mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 10:17:15 +02:00
Merge remote-tracking branch 'origin/master' into user-icons
Conflicts: public/src/app.js public/src/client/account/edit.js
This commit is contained in:
@@ -22,20 +22,30 @@ SocketGroups.join = function(socket, data, callback) {
|
||||
return callback(new Error('[[error:invalid-uid]]'));
|
||||
}
|
||||
|
||||
if (meta.config.allowPrivateGroups !== '0') {
|
||||
groups.exists(data.groupName, function(err, exists) {
|
||||
if (err || !exists) {
|
||||
return callback(err || new Error('[[error:no-group]]'));
|
||||
}
|
||||
|
||||
if (parseInt(meta.config.allowPrivateGroups, 10) !== 1) {
|
||||
return groups.join(data.groupName, socket.uid, callback);
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
isAdmin: async.apply(user.isAdministrator, socket.uid),
|
||||
isPrivate: async.apply(groups.isPrivate, data.groupName)
|
||||
}, function(err, checks) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (checks.isPrivate && !checks.isAdmin) {
|
||||
groups.requestMembership(data.groupName, socket.uid, callback);
|
||||
} else {
|
||||
groups.join(data.groupName, socket.uid, callback);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
groups.join(data.groupName, socket.uid, callback);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
SocketGroups.leave = function(socket, data, callback) {
|
||||
|
||||
113
src/socket.io/helpers.js
Normal file
113
src/socket.io/helpers.js
Normal file
@@ -0,0 +1,113 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var winston = require('winston');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var websockets = require('./index');
|
||||
var user = require('../user');
|
||||
var posts = require('../posts');
|
||||
var topics = require('../topics');
|
||||
var privileges = require('../privileges');
|
||||
var notifications = require('../notifications');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
var SocketHelpers = {};
|
||||
|
||||
SocketHelpers.notifyOnlineUsers = function(uid, result) {
|
||||
var cid = result.posts[0].topic.cid;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
user.getUidsFromSet('users:online', 0, -1, next);
|
||||
},
|
||||
function(uids, next) {
|
||||
privileges.categories.filterUids('read', cid, uids, next);
|
||||
},
|
||||
function(uids, next) {
|
||||
plugins.fireHook('filter:sockets.sendNewPostToUids', {uidsTo: uids, uidFrom: uid, type: 'newPost'}, next);
|
||||
}
|
||||
], function(err, data) {
|
||||
if (err) {
|
||||
return winston.error(err.stack);
|
||||
}
|
||||
|
||||
var uids = data.uidsTo;
|
||||
|
||||
for(var i=0; i<uids.length; ++i) {
|
||||
if (parseInt(uids[i], 10) !== uid) {
|
||||
websockets.in('uid_' + uids[i]).emit('event:new_post', result);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, notification) {
|
||||
if (!pid || !fromuid || !notification) {
|
||||
return;
|
||||
}
|
||||
posts.getPostFields(pid, ['tid', 'uid', 'content'], function(err, postData) {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!postData.uid || fromuid === parseInt(postData.uid, 10)) {
|
||||
return;
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
username: async.apply(user.getUserField, fromuid, 'username'),
|
||||
topicTitle: async.apply(topics.getTopicField, postData.tid, 'title'),
|
||||
postObj: async.apply(posts.parsePost, postData)
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
notifications.create({
|
||||
bodyShort: '[[' + notification + ', ' + results.username + ', ' + results.topicTitle + ']]',
|
||||
bodyLong: results.postObj.content,
|
||||
pid: pid,
|
||||
nid: 'post:' + pid + ':uid:' + fromuid,
|
||||
from: fromuid
|
||||
}, function(err, notification) {
|
||||
if (!err && notification) {
|
||||
notifications.push(notification, [postData.uid]);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
SocketHelpers.sendNotificationToTopicOwner = function(tid, fromuid, notification) {
|
||||
if (!tid || !fromuid || !notification) {
|
||||
return;
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
username: async.apply(user.getUserField, fromuid, 'username'),
|
||||
topicData: async.apply(topics.getTopicFields, tid, ['uid', 'slug']),
|
||||
}, function(err, results) {
|
||||
if (err || fromuid === parseInt(results.topicData.uid, 10)) {
|
||||
return;
|
||||
}
|
||||
|
||||
notifications.create({
|
||||
bodyShort: '[[' + notification + ', ' + results.username + ']]',
|
||||
path: nconf.get('relative_path') + '/topic/' + results.topicData.slug,
|
||||
nid: 'tid:' + tid + ':uid:' + fromuid,
|
||||
from: fromuid
|
||||
}, function(err, notification) {
|
||||
if (!err && notification) {
|
||||
notifications.push(notification, [results.topicData.uid]);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
SocketHelpers.emitToTopicAndCategory = function(event, data) {
|
||||
websockets.in('topic_' + data.tid).emit(event, data);
|
||||
websockets.in('category_' + data.cid).emit(event, data);
|
||||
};
|
||||
|
||||
module.exports = SocketHelpers;
|
||||
@@ -71,9 +71,12 @@ SocketModules.chats.canMessage = function(socket, toUid, callback) {
|
||||
|
||||
SocketModules.chats.markRead = function(socket, touid, callback) {
|
||||
Messaging.markRead(socket.uid, touid, function(err) {
|
||||
if (!err) {
|
||||
Messaging.pushUnreadCount(socket.uid);
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Messaging.pushUnreadCount(socket.uid);
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -2,18 +2,14 @@
|
||||
|
||||
var async = require('async'),
|
||||
|
||||
winston = require('winston'),
|
||||
|
||||
|
||||
posts = require('../posts'),
|
||||
plugins = require('../plugins'),
|
||||
privileges = require('../privileges'),
|
||||
meta = require('../meta'),
|
||||
topics = require('../topics'),
|
||||
notifications = require('../notifications'),
|
||||
user = require('../user'),
|
||||
websockets = require('./index'),
|
||||
socketTopics = require('./topics'),
|
||||
socketHelpers = require('./helpers'),
|
||||
utils = require('../../public/src/utils'),
|
||||
|
||||
SocketPosts = {};
|
||||
@@ -26,7 +22,7 @@ require('./posts/tools')(SocketPosts);
|
||||
require('./posts/flag')(SocketPosts);
|
||||
|
||||
SocketPosts.reply = function(socket, data, callback) {
|
||||
if(!data || !data.tid || !data.content) {
|
||||
if (!data || !data.tid || !data.content) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
@@ -53,7 +49,7 @@ SocketPosts.reply = function(socket, data, callback) {
|
||||
|
||||
user.updateOnlineUsers(socket.uid);
|
||||
|
||||
SocketPosts.notifyOnlineUsers(socket.uid, result);
|
||||
socketHelpers.notifyOnlineUsers(socket.uid, result);
|
||||
|
||||
if (data.lock) {
|
||||
socketTopics.doTopicAction('lock', 'event:topic_locked', socket, {tids: [postData.topic.tid], cid: postData.topic.cid});
|
||||
@@ -61,70 +57,6 @@ SocketPosts.reply = function(socket, data, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
SocketPosts.notifyOnlineUsers = function(uid, result) {
|
||||
var cid = result.posts[0].topic.cid;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
user.getUidsFromSet('users:online', 0, -1, next);
|
||||
},
|
||||
function(uids, next) {
|
||||
privileges.categories.filterUids('read', cid, uids, next);
|
||||
},
|
||||
function(uids, next) {
|
||||
plugins.fireHook('filter:sockets.sendNewPostToUids', {uidsTo: uids, uidFrom: uid, type: 'newPost'}, next);
|
||||
}
|
||||
], function(err, data) {
|
||||
if (err) {
|
||||
return winston.error(err.stack);
|
||||
}
|
||||
|
||||
var uids = data.uidsTo;
|
||||
|
||||
for(var i=0; i<uids.length; ++i) {
|
||||
if (parseInt(uids[i], 10) !== uid) {
|
||||
websockets.in('uid_' + uids[i]).emit('event:new_post', result);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
SocketPosts.sendNotificationToPostOwner = function(pid, fromuid, notification) {
|
||||
if(!pid || !fromuid || !notification) {
|
||||
return;
|
||||
}
|
||||
posts.getPostFields(pid, ['tid', 'uid', 'content'], function(err, postData) {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!postData.uid || fromuid === parseInt(postData.uid, 10)) {
|
||||
return;
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
username: async.apply(user.getUserField, fromuid, 'username'),
|
||||
topicTitle: async.apply(topics.getTopicField, postData.tid, 'title'),
|
||||
postObj: async.apply(posts.parsePost, postData)
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
notifications.create({
|
||||
bodyShort: '[[' + notification + ', ' + results.username + ', ' + results.topicTitle + ']]',
|
||||
bodyLong: results.postObj.content,
|
||||
pid: pid,
|
||||
nid: 'post:' + pid + ':uid:' + fromuid,
|
||||
from: fromuid
|
||||
}, function(err, notification) {
|
||||
if (!err && notification) {
|
||||
notifications.push(notification, [postData.uid]);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
SocketPosts.getRawPost = function(socket, pid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
|
||||
@@ -9,6 +9,7 @@ var favourites = require('../../favourites');
|
||||
var plugins = require('../../plugins');
|
||||
var websockets = require('../index');
|
||||
var privileges = require('../../privileges');
|
||||
var socketHelpers = require('../helpers');
|
||||
|
||||
module.exports = function(SocketPosts) {
|
||||
SocketPosts.getVoters = function(socket, data, callback) {
|
||||
@@ -148,7 +149,7 @@ module.exports = function(SocketPosts) {
|
||||
}
|
||||
|
||||
if (result && notification) {
|
||||
SocketPosts.sendNotificationToPostOwner(data.pid, socket.uid, notification);
|
||||
socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, notification);
|
||||
}
|
||||
callback();
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
var async = require('async');
|
||||
var privileges = require('../../privileges');
|
||||
var topics = require('../../topics');
|
||||
|
||||
var socketHelpers = require('../helpers');
|
||||
|
||||
module.exports = function(SocketPosts) {
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = function(SocketPosts) {
|
||||
topics.movePostToTopic(data.pid, data.tid, next);
|
||||
},
|
||||
function (next) {
|
||||
SocketPosts.sendNotificationToPostOwner(data.pid, socket.uid, 'notifications:moved_your_post');
|
||||
socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, 'notifications:moved_your_post');
|
||||
next();
|
||||
}
|
||||
], callback);
|
||||
|
||||
@@ -101,12 +101,6 @@ SocketTopics.bookmark = function(socket, data, callback) {
|
||||
topics.setUserBookmark(data.tid, socket.uid, data.index, callback);
|
||||
};
|
||||
|
||||
|
||||
SocketTopics.emitToTopicAndCategory = function(event, data) {
|
||||
websockets.in('topic_' + data.tid).emit(event, data);
|
||||
websockets.in('category_' + data.cid).emit(event, data);
|
||||
};
|
||||
|
||||
SocketTopics.createTopicFromPosts = function(socket, data, callback) {
|
||||
if (!socket.uid) {
|
||||
return callback(new Error('[[error:not-logged-in]]'));
|
||||
@@ -119,33 +113,6 @@ SocketTopics.createTopicFromPosts = function(socket, data, callback) {
|
||||
topics.createTopicFromPosts(socket.uid, data.title, data.pids, callback);
|
||||
};
|
||||
|
||||
SocketTopics.sendNotificationToTopicOwner = function(tid, fromuid, notification) {
|
||||
if (!tid || !fromuid) {
|
||||
return;
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
username: async.apply(user.getUserField, fromuid, 'username'),
|
||||
topicData: async.apply(topics.getTopicFields, tid, ['uid', 'slug']),
|
||||
}, function(err, results) {
|
||||
if (err || fromuid === parseInt(results.topicData.uid, 10)) {
|
||||
return;
|
||||
}
|
||||
|
||||
notifications.create({
|
||||
bodyShort: '[[' + notification + ', ' + results.username + ']]',
|
||||
path: nconf.get('relative_path') + '/topic/' + results.topicData.slug,
|
||||
nid: 'tid:' + tid + ':uid:' + fromuid,
|
||||
from: fromuid
|
||||
}, function(err, notification) {
|
||||
if (!err && notification) {
|
||||
notifications.push(notification, [results.topicData.uid]);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
SocketTopics.toggleFollow = function(socket, tid, callback) {
|
||||
followCommand(topics.toggleFollow, socket, tid, callback);
|
||||
};
|
||||
|
||||
@@ -15,12 +15,12 @@ module.exports = function(SocketTopics) {
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
settings: function(next) {
|
||||
user.getSettings(socket.uid, next);
|
||||
},
|
||||
privileges: function(next) {
|
||||
privileges.topics.get(data.tid, socket.uid, next);
|
||||
},
|
||||
settings: function(next) {
|
||||
user.getSettings(socket.uid, next);
|
||||
},
|
||||
topic: function(next) {
|
||||
topics.getTopicFields(data.tid, ['postcount', 'deleted'], next);
|
||||
}
|
||||
@@ -68,22 +68,21 @@ module.exports = function(SocketTopics) {
|
||||
},
|
||||
posts: function(next) {
|
||||
topics.getTopicPosts(data.tid, set, start, stop, socket.uid, reverse, next);
|
||||
},
|
||||
privileges: function(next) {
|
||||
next(null, results.privileges);
|
||||
},
|
||||
'reputation:disabled': function(next) {
|
||||
next(null, parseInt(meta.config['reputation:disabled'], 10) === 1);
|
||||
},
|
||||
'downvote:disabled': function(next) {
|
||||
next(null, parseInt(meta.config['downvote:disabled'], 10) === 1);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (results.mainPost) {
|
||||
results.posts = [results.mainPost].concat(results.posts);
|
||||
}, function(err, topicData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (topicData.mainPost) {
|
||||
topicData.posts = [topicData.mainPost].concat(topicData.posts);
|
||||
}
|
||||
|
||||
callback(err, results);
|
||||
topicData.privileges = results.privileges;
|
||||
topicData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
|
||||
topicData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
|
||||
|
||||
topics.modifyByPrivilege(topicData.posts, results.privileges);
|
||||
callback(null, topicData);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ var async = require('async');
|
||||
var topics = require('../../topics');
|
||||
var categories = require('../../categories');
|
||||
var privileges = require('../../privileges');
|
||||
var socketHelpers = require('../helpers');
|
||||
|
||||
module.exports = function(SocketTopics) {
|
||||
|
||||
@@ -37,9 +38,9 @@ module.exports = function(SocketTopics) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
SocketTopics.emitToTopicAndCategory('event:topic_moved', topicData);
|
||||
socketHelpers.emitToTopicAndCategory('event:topic_moved', topicData);
|
||||
|
||||
SocketTopics.sendNotificationToTopicOwner(tid, socket.uid, 'notifications:moved_your_topic');
|
||||
socketHelpers.sendNotificationToTopicOwner(tid, socket.uid, 'notifications:moved_your_topic');
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
var async = require('async');
|
||||
var topics = require('../../topics');
|
||||
var events = require('../../events');
|
||||
var socketHelpers = require('../helpers');
|
||||
|
||||
module.exports = function(SocketTopics) {
|
||||
|
||||
@@ -55,7 +56,7 @@ module.exports = function(SocketTopics) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
SocketTopics.emitToTopicAndCategory(event, data);
|
||||
socketHelpers.emitToTopicAndCategory(event, data);
|
||||
|
||||
if (action === 'delete' || action === 'restore' || action === 'purge') {
|
||||
events.log({
|
||||
|
||||
@@ -49,7 +49,7 @@ module.exports = function(SocketUser) {
|
||||
function (_oldUserData, next) {
|
||||
oldUserData = _oldUserData;
|
||||
if (!oldUserData || !oldUserData.username) {
|
||||
return next(new Error('[[error-invalid-data]]'));
|
||||
return next(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
if (parseInt(meta.config['username:disableEdit'], 10) === 1) {
|
||||
|
||||
Reference in New Issue
Block a user