send new post/topic to users who can read it

v1.18.x
barisusakli 11 years ago
parent 655f5087d9
commit 82e721e854

@ -31,30 +31,34 @@ SocketPosts.reply = function(socket, data, callback) {
return callback(err); return callback(err);
} }
if (postData) { var result = {
var privileges = { posts: [postData],
privileges: {
'topics:reply': true 'topics:reply': true
},
'reputation:disabled': parseInt(meta.config['reputation:disabled'], 10) === 1,
'downvote:disabled': parseInt(meta.config['downvote:disabled'], 10) === 1,
}; };
callback(); callback();
socket.emit('event:new_post', { socket.emit('event:new_post', result);
posts: [postData],
privileges: privileges,
'reputation:disabled': parseInt(meta.config['reputation:disabled'], 10) === 1,
'downvote:disabled': parseInt(meta.config['downvote:disabled'], 10) === 1,
});
socket.broadcast.emit('event:new_post', { var uids = websockets.getConnectedClients();
posts: [postData],
privileges: privileges, privileges.categories.filterUids('read', postData.topic.cid, uids, function(err, uids) {
'reputation:disabled': parseInt(meta.config['reputation:disabled'], 10) === 1, if (err) {
'downvote:disabled': parseInt(meta.config['downvote:disabled'], 10) === 1, return;
}
for(var i=0; i<uids.length; ++i) {
if (uids[i] !== socket.uid) {
websockets.in('uid_' + uids[i]).emit('event:new_post', result);
}
}
}); });
websockets.emitTopicPostStats(); websockets.emitTopicPostStats();
topics.pushUnreadCount(); topics.pushUnreadCount();
}
}); });
}; };

@ -19,7 +19,6 @@ var nconf = require('nconf'),
SocketTopics = {}; SocketTopics = {};
SocketTopics.post = function(socket, data, callback) { SocketTopics.post = function(socket, data, callback) {
if(!data) { if(!data) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
@ -37,23 +36,26 @@ SocketTopics.post = function(socket, data, callback) {
return callback(err); return callback(err);
} }
if (result) { callback(null, result.topicData);
socket.emit('event:new_post', {posts: result.postData});
socket.emit('event:new_topic', result.topicData);
websockets.server.sockets.in('category_' + data.category_id).emit('event:new_topic', result.topicData); var uids = websockets.getConnectedClients();
websockets.server.sockets.in('recent_posts').emit('event:new_topic', result.topicData);
websockets.server.sockets.in('home').emit('event:new_topic', result.topicData); privileges.categories.filterUids('read', result.topicData.cid, uids, function(err, uids) {
websockets.server.sockets.in('home').emit('event:new_post', { if (err) {
posts: result.postData return;
}); }
websockets.server.sockets.in('user/' + socket.uid).emit('event:new_post', { for(var i=0; i<uids.length; ++i) {
posts: result.postData if (uids[i] !== socket.uid) {
websockets.in('uid_' + uids[i]).emit('event:new_post', result.postData);
websockets.in('uid_' + uids[i]).emit('event:new_topic', result.topicData);
}
}
}); });
websockets.emitTopicPostStats(); websockets.emitTopicPostStats();
topics.pushUnreadCount(); topics.pushUnreadCount();
callback(null, result.topicData);
}
}); });
}; };

Loading…
Cancel
Save