v1.18.x
Barış Soner Uşaklı
parent 8a581ed1dd
commit d20628a8d4

@ -10,10 +10,6 @@ app.currentRoom = null;
app.widgets = {}; app.widgets = {};
app.cacheBuster = null; app.cacheBuster = null;
// TODO: deprecate in 0.7.0, use app.user
app.username = null;
app.uid = null;
(function () { (function () {
var showWelcomeMessage = false; var showWelcomeMessage = false;
var reconnecting = false; var reconnecting = false;
@ -29,14 +25,7 @@ app.uid = null;
socket = io.connect(config.websocketAddress, ioParams); socket = io.connect(config.websocketAddress, ioParams);
reconnecting = false; reconnecting = false;
socket.on('event:connect', function (data) { socket.on('event:connect', function () {
// TODO : deprecate in 0.7.0, use app.user
app.username = data.username;
app.userslug = data.userslug;
app.picture = data.picture;
app.uid = data.uid;
app.isAdmin = data.isAdmin;
app.showLoginMessage(); app.showLoginMessage();
app.replaceSelfLinks(); app.replaceSelfLinks();
$(window).trigger('action:connected'); $(window).trigger('action:connected');
@ -182,9 +171,9 @@ app.uid = null;
socket.emit('meta.rooms.enter', { socket.emit('meta.rooms.enter', {
enter: room, enter: room,
username: app.username, username: app.user.username,
userslug: app.userslug, userslug: app.user.userslug,
picture: app.picture picture: app.user.picture
}); });
app.currentRoom = room; app.currentRoom = room;
@ -232,8 +221,8 @@ app.uid = null;
selector = selector || $('a'); selector = selector || $('a');
selector.each(function() { selector.each(function() {
var href = $(this).attr('href'); var href = $(this).attr('href');
if (href && app.userslug && href.indexOf('user/_self_') !== -1) { if (href && app.user.userslug && href.indexOf('user/_self_') !== -1) {
$(this).attr('href', href.replace(/user\/_self_/g, 'user/' + app.userslug)); $(this).attr('href', href.replace(/user\/_self_/g, 'user/' + app.user.userslug));
} }
}); });
}; };
@ -261,7 +250,7 @@ app.uid = null;
function showAlert() { function showAlert() {
app.alert({ app.alert({
type: 'success', type: 'success',
title: '[[global:welcome_back]] ' + app.username + '!', title: '[[global:welcome_back]] ' + app.user.username + '!',
message: '[[global:you_have_successfully_logged_in]]', message: '[[global:you_have_successfully_logged_in]]',
timeout: 5000 timeout: 5000
}); });
@ -278,11 +267,11 @@ app.uid = null;
}; };
app.openChat = function (username, touid) { app.openChat = function (username, touid) {
if (username === app.username) { if (username === app.user.username) {
return app.alertError('[[error:cant-chat-with-yourself]]'); return app.alertError('[[error:cant-chat-with-yourself]]');
} }
if (!app.uid) { if (!app.user.uid) {
return app.alertError('[[error:not-logged-in]]'); return app.alertError('[[error:not-logged-in]]');
} }

@ -152,7 +152,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader'], function(head
return; return;
} }
if ($('#confirm-username').val() !== app.username) { if ($('#confirm-username').val() !== app.user.username) {
app.alertError('[[error:invalid-username]]'); app.alertError('[[error:invalid-username]]');
return false; return false;
} else { } else {
@ -266,7 +266,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader'], function(head
password_confirm.on('blur', onPasswordConfirmChanged); password_confirm.on('blur', onPasswordConfirmChanged);
$('#changePasswordBtn').on('click', function() { $('#changePasswordBtn').on('click', function() {
if ((passwordvalid && passwordsmatch) || app.isAdmin) { if ((passwordvalid && passwordsmatch) || app.user.isAdmin) {
socket.emit('user.changePassword', { socket.emit('user.changePassword', {
'currentPassword': currentPassword.val(), 'currentPassword': currentPassword.val(),
'newPassword': password.val(), 'newPassword': password.val(),

@ -44,7 +44,7 @@ define('forum/account/settings', ['forum/account/header'], function(header) {
} }
app.exposeConfigToTemplates(); app.exposeConfigToTemplates();
if (parseInt(app.uid, 10) === parseInt(ajaxify.variables.get('theirid'), 10)) { if (parseInt(app.user.uid, 10) === parseInt(ajaxify.variables.get('theirid'), 10)) {
ajaxify.refresh(); ajaxify.refresh();
} }
}); });

@ -193,7 +193,7 @@ define('forum/chats', ['string', 'sounds', 'forum/infinitescroll'], function(S,
Chats.notifyTyping = function(toUid, typing) { Chats.notifyTyping = function(toUid, typing) {
socket.emit('modules.chats.user' + (typing ? 'Start' : 'Stop') + 'Typing', { socket.emit('modules.chats.user' + (typing ? 'Start' : 'Stop') + 'Typing', {
touid: toUid, touid: toUid,
fromUid: app.uid fromUid: app.user.uid
}); });
}; };

@ -31,7 +31,7 @@ define('forum/footer', ['notifications', 'chat'], function(Notifications, Chat)
if (data && data.posts && data.posts.length) { if (data && data.posts && data.posts.length) {
var post = data.posts[0]; var post = data.posts[0];
if (parseInt(post.uid, 10) !== parseInt(app.uid, 10) && !unreadTopics[post.topic.tid]) { if (parseInt(post.uid, 10) !== parseInt(app.user.uid, 10) && !unreadTopics[post.topic.tid]) {
increaseUnreadCount(); increaseUnreadCount();
markTopicsUnread(post.topic.tid); markTopicsUnread(post.topic.tid);
unreadTopics[post.topic.tid] = true; unreadTopics[post.topic.tid] = true;

@ -59,7 +59,7 @@ define('forum/topic', [
$(window).trigger('action:topic.loaded'); $(window).trigger('action:topic.loaded');
if (app.uid) { if (app.user.uid) {
socket.emit('topics.enter', tid, function(err, data) { socket.emit('topics.enter', tid, function(err, data) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);

@ -74,7 +74,7 @@ define('forum/topic/browsing', function() {
} }
var activeEl = $('.thread_active_users'); var activeEl = $('.thread_active_users');
var userEl = createUserIcon(user.uid, user.picture, user.userslug, user.username); var userEl = createUserIcon(user.uid, user.picture, user.userslug, user.username);
var isSelf = parseInt(user.uid, 10) === parseInt(app.uid, 10); var isSelf = parseInt(user.uid, 10) === parseInt(app.user.uid, 10);
if (isSelf) { if (isSelf) {
activeEl.prepend(userEl); activeEl.prepend(userEl);
} else { } else {

@ -156,7 +156,7 @@ define('forum/topic/events', [
var isDeleted = postEl.hasClass('deleted'); var isDeleted = postEl.hasClass('deleted');
postTools.toggle(data.pid, isDeleted); postTools.toggle(data.pid, isDeleted);
if (!app.isAdmin && parseInt(data.uid, 10) !== parseInt(app.uid, 10)) { if (!app.user.isAdmin && parseInt(data.uid, 10) !== parseInt(app.user.uid, 10)) {
if (isDeleted) { if (isDeleted) {
postEl.find('.post-content').translateHtml('[[topic:post_is_deleted]]'); postEl.find('.post-content').translateHtml('[[topic:post_is_deleted]]');
} else { } else {

@ -34,7 +34,7 @@ define('forum/topic/posts', [
var posts = data.posts; var posts = data.posts;
if (pagination.currentPage === pagination.pageCount) { if (pagination.currentPage === pagination.pageCount) {
createNewPosts(data); createNewPosts(data);
} else if(data.posts && data.posts.length && parseInt(data.posts[0].uid, 10) === parseInt(app.uid, 10)) { } else if(data.posts && data.posts.length && parseInt(data.posts[0].uid, 10) === parseInt(app.user.uid, 10)) {
pagination.loadPage(pagination.pageCount); pagination.loadPage(pagination.pageCount);
} }
} }
@ -134,7 +134,7 @@ define('forum/topic/posts', [
} }
function onNewPostsLoaded(html, pids) { function onNewPostsLoaded(html, pids) {
if (app.uid) { if (app.user.uid) {
socket.emit('posts.getPrivileges', pids, function(err, privileges) { socket.emit('posts.getPrivileges', pids, function(err, privileges) {
if(err) { if(err) {
return app.alertError(err.message); return app.alertError(err.message);
@ -163,8 +163,8 @@ define('forum/topic/posts', [
postEl.find('.move').remove(); postEl.find('.move').remove();
} }
postEl.find('.reply, .quote').toggleClass('hidden', !$('.post_reply').length); postEl.find('.reply, .quote').toggleClass('hidden', !$('.post_reply').length);
var isSelfPost = parseInt(postEl.attr('data-uid'), 10) === parseInt(app.uid, 10); var isSelfPost = parseInt(postEl.attr('data-uid'), 10) === parseInt(app.user.uid, 10);
postEl.find('.chat, .flag').toggleClass('hidden', isSelfPost || !app.uid); postEl.find('.chat, .flag').toggleClass('hidden', isSelfPost || !app.user.uid);
} }
Posts.loadMorePosts = function(direction) { Posts.loadMorePosts = function(direction) {
@ -202,7 +202,7 @@ define('forum/topic/posts', [
done(); done();
}); });
} else { } else {
if (app.uid) { if (app.user.uid) {
socket.emit('topics.markAsRead', [tid]); socket.emit('topics.markAsRead', [tid]);
} }
navigator.update(); navigator.update();

@ -99,7 +99,7 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move'], func
ThreadTools.setLockedState = function(data) { ThreadTools.setLockedState = function(data) {
var threadEl = $('#post-container'); var threadEl = $('#post-container');
if (parseInt(data.tid, 10) === parseInt(threadEl.attr('data-tid'), 10)) { if (parseInt(data.tid, 10) === parseInt(threadEl.attr('data-tid'), 10)) {
var isLocked = data.isLocked && !app.isAdmin; var isLocked = data.isLocked && !app.user.isAdmin;
$('.lock_thread').translateHtml('<i class="fa fa-fw fa-' + (data.isLocked ? 'un': '') + 'lock"></i> [[topic:thread_tools.' + (data.isLocked ? 'un': '') + 'lock]]'); $('.lock_thread').translateHtml('<i class="fa fa-fw fa-' + (data.isLocked ? 'un': '') + 'lock"></i> [[topic:thread_tools.' + (data.isLocked ? 'un': '') + 'lock]]');

@ -74,7 +74,7 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,
} }
var username = data.message.fromUser.username; var username = data.message.fromUser.username;
var isSelf = parseInt(data.message.fromUser.uid, 10) === parseInt(app.uid, 10); var isSelf = parseInt(data.message.fromUser.uid, 10) === parseInt(app.user.uid, 10);
data.message.self = data.self; data.message.self = data.self;
if (isSelf) { if (isSelf) {
username = data.message.toUser.username; username = data.message.toUser.username;

@ -68,13 +68,13 @@ define('composer', [
}); });
// Construct a save_id // Construct a save_id
if (0 !== parseInt(app.uid, 10)) { if (0 !== parseInt(app.user.uid, 10)) {
if (post.hasOwnProperty('cid')) { if (post.hasOwnProperty('cid')) {
post.save_id = ['composer', app.uid, 'cid', post.cid].join(':'); post.save_id = ['composer', app.user.uid, 'cid', post.cid].join(':');
} else if (post.hasOwnProperty('tid')) { } else if (post.hasOwnProperty('tid')) {
post.save_id = ['composer', app.uid, 'tid', post.tid].join(':'); post.save_id = ['composer', app.user.uid, 'tid', post.tid].join(':');
} else if (post.hasOwnProperty('pid')) { } else if (post.hasOwnProperty('pid')) {
post.save_id = ['composer', app.uid, 'pid', post.pid].join(':'); post.save_id = ['composer', app.user.uid, 'pid', post.pid].join(':');
} }
} }
@ -183,7 +183,7 @@ define('composer', [
function emit() { function emit() {
socket.emit('modules.composer.notifyTyping', { socket.emit('modules.composer.notifyTyping', {
tid: postData.tid, tid: postData.tid,
uid: app.uid uid: app.user.uid
}); });
} }
@ -203,7 +203,7 @@ define('composer', [
} }
socket.emit('modules.composer.stopNotifyTyping', { socket.emit('modules.composer.stopNotifyTyping', {
tid: postData.tid, tid: postData.tid,
uid: app.uid uid: app.user.uid
}); });
} }
@ -219,7 +219,7 @@ define('composer', [
isTopic = composer.posts[post_uuid] ? !!composer.posts[post_uuid].cid : false, isTopic = composer.posts[post_uuid] ? !!composer.posts[post_uuid].cid : false,
isMain = composer.posts[post_uuid] ? !!composer.posts[post_uuid].isMain : false, isMain = composer.posts[post_uuid] ? !!composer.posts[post_uuid].isMain : false,
isEditing = composer.posts[post_uuid] ? !!composer.posts[post_uuid].pid : false, isEditing = composer.posts[post_uuid] ? !!composer.posts[post_uuid].pid : false,
isGuestPost = composer.posts[post_uuid] ? composer.posts[post_uuid].uid === '0' : null; isGuestPost = composer.posts[post_uuid] ? parseInt(composer.posts[post_uuid].uid, 10) === 0 : null;
composer.bsEnvironment = utils.findBootstrapEnvironment(); composer.bsEnvironment = utils.findBootstrapEnvironment();

@ -66,32 +66,19 @@ function onConnect(socket) {
socket.join('uid_' + socket.uid); socket.join('uid_' + socket.uid);
socket.join('online_users'); socket.join('online_users');
async.parallel({ user.getUserFields(socket.uid, ['status'], function(err, userData) {
user: function(next) { if (err || !userData) {
user.getUserFields(socket.uid, ['username', 'userslug', 'picture', 'status', 'email:confirmed'], next);
},
isAdmin: function(next) {
user.isAdministrator(socket.uid, next);
}
}, function(err, userData) {
if (err || !userData.user) {
return; return;
} }
userData.user.uid = socket.uid;
userData.user.isAdmin = userData.isAdmin; socket.emit('event:connect');
userData.user['email:confirmed'] = parseInt(userData.user['email:confirmed'], 10) === 1; if (userData.status !== 'offline') {
socket.emit('event:connect', userData.user); socket.broadcast.emit('event:user_status_change', {uid: socket.uid, status: userData.status || 'online'});
if (userData.user.status !== 'offline') {
socket.broadcast.emit('event:user_status_change', {uid: socket.uid, status: userData.user.status || 'online'});
} }
}); });
} else { } else {
socket.join('online_guests'); socket.join('online_guests');
socket.emit('event:connect', { socket.emit('event:connect');
username: '[[global:guest]]',
isAdmin: false,
uid: 0
});
} }
} }

Loading…
Cancel
Save