mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
closes #2539
This commit is contained in:
@@ -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]]');
|
||||
}
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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('<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 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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user