From d20628a8d4458e3dbde79c24fac82f7c15d452e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 11 Feb 2015 12:54:54 -0500 Subject: [PATCH] closes #2539 --- public/src/app.js | 29 ++++++++------------------ public/src/client/account/edit.js | 4 ++-- public/src/client/account/settings.js | 2 +- public/src/client/chats.js | 2 +- public/src/client/footer.js | 2 +- public/src/client/topic.js | 2 +- public/src/client/topic/browsing.js | 2 +- public/src/client/topic/events.js | 2 +- public/src/client/topic/posts.js | 10 ++++----- public/src/client/topic/threadTools.js | 2 +- public/src/modules/chat.js | 2 +- public/src/modules/composer.js | 14 ++++++------- src/socket.io/index.js | 27 +++++++----------------- 13 files changed, 38 insertions(+), 62 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 1e5b92cf4d..5010ead25d 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -10,10 +10,6 @@ app.currentRoom = null; app.widgets = {}; app.cacheBuster = null; -// TODO: deprecate in 0.7.0, use app.user -app.username = null; -app.uid = null; - (function () { var showWelcomeMessage = false; var reconnecting = false; @@ -29,14 +25,7 @@ app.uid = null; socket = io.connect(config.websocketAddress, ioParams); reconnecting = false; - socket.on('event:connect', function (data) { - // 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; - + socket.on('event:connect', function () { app.showLoginMessage(); app.replaceSelfLinks(); $(window).trigger('action:connected'); @@ -182,9 +171,9 @@ app.uid = null; socket.emit('meta.rooms.enter', { enter: room, - username: app.username, - userslug: app.userslug, - picture: app.picture + username: app.user.username, + userslug: app.user.userslug, + picture: app.user.picture }); app.currentRoom = room; @@ -232,8 +221,8 @@ app.uid = null; selector = selector || $('a'); selector.each(function() { var href = $(this).attr('href'); - if (href && app.userslug && href.indexOf('user/_self_') !== -1) { - $(this).attr('href', href.replace(/user\/_self_/g, 'user/' + app.userslug)); + if (href && app.user.userslug && href.indexOf('user/_self_') !== -1) { + $(this).attr('href', href.replace(/user\/_self_/g, 'user/' + app.user.userslug)); } }); }; @@ -261,7 +250,7 @@ app.uid = null; function showAlert() { app.alert({ type: 'success', - title: '[[global:welcome_back]] ' + app.username + '!', + title: '[[global:welcome_back]] ' + app.user.username + '!', message: '[[global:you_have_successfully_logged_in]]', timeout: 5000 }); @@ -278,11 +267,11 @@ app.uid = null; }; app.openChat = function (username, touid) { - if (username === app.username) { + if (username === app.user.username) { return app.alertError('[[error:cant-chat-with-yourself]]'); } - if (!app.uid) { + if (!app.user.uid) { return app.alertError('[[error:not-logged-in]]'); } diff --git a/public/src/client/account/edit.js b/public/src/client/account/edit.js index f85e00951c..dc8bfaeaf1 100644 --- a/public/src/client/account/edit.js +++ b/public/src/client/account/edit.js @@ -152,7 +152,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader'], function(head return; } - if ($('#confirm-username').val() !== app.username) { + if ($('#confirm-username').val() !== app.user.username) { app.alertError('[[error:invalid-username]]'); return false; } else { @@ -266,7 +266,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader'], function(head password_confirm.on('blur', onPasswordConfirmChanged); $('#changePasswordBtn').on('click', function() { - if ((passwordvalid && passwordsmatch) || app.isAdmin) { + if ((passwordvalid && passwordsmatch) || app.user.isAdmin) { socket.emit('user.changePassword', { 'currentPassword': currentPassword.val(), 'newPassword': password.val(), diff --git a/public/src/client/account/settings.js b/public/src/client/account/settings.js index 0b4bbbd00f..fef95fc495 100644 --- a/public/src/client/account/settings.js +++ b/public/src/client/account/settings.js @@ -44,7 +44,7 @@ define('forum/account/settings', ['forum/account/header'], function(header) { } 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(); } }); diff --git a/public/src/client/chats.js b/public/src/client/chats.js index 607b84d4f3..994ddeb47a 100644 --- a/public/src/client/chats.js +++ b/public/src/client/chats.js @@ -193,7 +193,7 @@ define('forum/chats', ['string', 'sounds', 'forum/infinitescroll'], function(S, Chats.notifyTyping = function(toUid, typing) { socket.emit('modules.chats.user' + (typing ? 'Start' : 'Stop') + 'Typing', { touid: toUid, - fromUid: app.uid + fromUid: app.user.uid }); }; diff --git a/public/src/client/footer.js b/public/src/client/footer.js index 775686aaa2..ff44f25e1e 100644 --- a/public/src/client/footer.js +++ b/public/src/client/footer.js @@ -31,7 +31,7 @@ define('forum/footer', ['notifications', 'chat'], function(Notifications, Chat) if (data && data.posts && data.posts.length) { 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(); markTopicsUnread(post.topic.tid); unreadTopics[post.topic.tid] = true; diff --git a/public/src/client/topic.js b/public/src/client/topic.js index 621521eaed..f5627a02d5 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -59,7 +59,7 @@ define('forum/topic', [ $(window).trigger('action:topic.loaded'); - if (app.uid) { + if (app.user.uid) { socket.emit('topics.enter', tid, function(err, data) { if (err) { return app.alertError(err.message); diff --git a/public/src/client/topic/browsing.js b/public/src/client/topic/browsing.js index 6541cdf68a..dd768391e1 100644 --- a/public/src/client/topic/browsing.js +++ b/public/src/client/topic/browsing.js @@ -74,7 +74,7 @@ define('forum/topic/browsing', function() { } var activeEl = $('.thread_active_users'); 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) { activeEl.prepend(userEl); } else { diff --git a/public/src/client/topic/events.js b/public/src/client/topic/events.js index f4c69a121e..c90dd149b5 100644 --- a/public/src/client/topic/events.js +++ b/public/src/client/topic/events.js @@ -156,7 +156,7 @@ define('forum/topic/events', [ var isDeleted = postEl.hasClass('deleted'); 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) { postEl.find('.post-content').translateHtml('[[topic:post_is_deleted]]'); } else { diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js index 05bc505ae2..57bf5a1e15 100644 --- a/public/src/client/topic/posts.js +++ b/public/src/client/topic/posts.js @@ -34,7 +34,7 @@ define('forum/topic/posts', [ var posts = data.posts; if (pagination.currentPage === pagination.pageCount) { 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); } } @@ -134,7 +134,7 @@ define('forum/topic/posts', [ } function onNewPostsLoaded(html, pids) { - if (app.uid) { + if (app.user.uid) { socket.emit('posts.getPrivileges', pids, function(err, privileges) { if(err) { return app.alertError(err.message); @@ -163,8 +163,8 @@ define('forum/topic/posts', [ postEl.find('.move').remove(); } postEl.find('.reply, .quote').toggleClass('hidden', !$('.post_reply').length); - var isSelfPost = parseInt(postEl.attr('data-uid'), 10) === parseInt(app.uid, 10); - postEl.find('.chat, .flag').toggleClass('hidden', isSelfPost || !app.uid); + var isSelfPost = parseInt(postEl.attr('data-uid'), 10) === parseInt(app.user.uid, 10); + postEl.find('.chat, .flag').toggleClass('hidden', isSelfPost || !app.user.uid); } Posts.loadMorePosts = function(direction) { @@ -202,7 +202,7 @@ define('forum/topic/posts', [ done(); }); } else { - if (app.uid) { + if (app.user.uid) { socket.emit('topics.markAsRead', [tid]); } navigator.update(); diff --git a/public/src/client/topic/threadTools.js b/public/src/client/topic/threadTools.js index b401a850ed..c3923e2720 100644 --- a/public/src/client/topic/threadTools.js +++ b/public/src/client/topic/threadTools.js @@ -99,7 +99,7 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move'], func ThreadTools.setLockedState = function(data) { var threadEl = $('#post-container'); 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(' [[topic:thread_tools.' + (data.isLocked ? 'un': '') + 'lock]]'); diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js index 02fcbba02e..06e8c75c7d 100644 --- a/public/src/modules/chat.js +++ b/public/src/modules/chat.js @@ -74,7 +74,7 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar, } 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; if (isSelf) { username = data.message.toUser.username; diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js index 2836967416..088cafe260 100644 --- a/public/src/modules/composer.js +++ b/public/src/modules/composer.js @@ -68,13 +68,13 @@ define('composer', [ }); // Construct a save_id - if (0 !== parseInt(app.uid, 10)) { + if (0 !== parseInt(app.user.uid, 10)) { 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')) { - 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')) { - 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() { socket.emit('modules.composer.notifyTyping', { tid: postData.tid, - uid: app.uid + uid: app.user.uid }); } @@ -203,7 +203,7 @@ define('composer', [ } socket.emit('modules.composer.stopNotifyTyping', { 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, isMain = composer.posts[post_uuid] ? !!composer.posts[post_uuid].isMain : 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(); diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 8144fbc835..98d1d6e2e8 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -66,32 +66,19 @@ function onConnect(socket) { socket.join('uid_' + socket.uid); socket.join('online_users'); - async.parallel({ - user: function(next) { - 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) { + user.getUserFields(socket.uid, ['status'], function(err, userData) { + if (err || !userData) { return; } - userData.user.uid = socket.uid; - userData.user.isAdmin = userData.isAdmin; - userData.user['email:confirmed'] = parseInt(userData.user['email:confirmed'], 10) === 1; - socket.emit('event:connect', userData.user); - if (userData.user.status !== 'offline') { - socket.broadcast.emit('event:user_status_change', {uid: socket.uid, status: userData.user.status || 'online'}); + + socket.emit('event:connect'); + if (userData.status !== 'offline') { + socket.broadcast.emit('event:user_status_change', {uid: socket.uid, status: userData.status || 'online'}); } }); } else { socket.join('online_guests'); - socket.emit('event:connect', { - username: '[[global:guest]]', - isAdmin: false, - uid: 0 - }); + socket.emit('event:connect'); } }