mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
send new post/topic to users who can read it
This commit is contained in:
@@ -27,34 +27,38 @@ SocketPosts.reply = function(socket, data, callback) {
|
|||||||
data.req = websockets.reqFromSocket(socket);
|
data.req = websockets.reqFromSocket(socket);
|
||||||
|
|
||||||
topics.reply(data, function(err, postData) {
|
topics.reply(data, function(err, postData) {
|
||||||
if(err) {
|
if (err) {
|
||||||
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,
|
|
||||||
'reputation:disabled': parseInt(meta.config['reputation:disabled'], 10) === 1,
|
|
||||||
'downvote:disabled': parseInt(meta.config['downvote:disabled'], 10) === 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
websockets.emitTopicPostStats();
|
privileges.categories.filterUids('read', postData.topic.cid, uids, function(err, uids) {
|
||||||
topics.pushUnreadCount();
|
if (err) {
|
||||||
}
|
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();
|
||||||
|
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]]'));
|
||||||
}
|
}
|
||||||
@@ -33,27 +32,30 @@ SocketTopics.post = function(socket, data, callback) {
|
|||||||
tags: data.tags,
|
tags: data.tags,
|
||||||
req: websockets.reqFromSocket(socket)
|
req: websockets.reqFromSocket(socket)
|
||||||
}, function(err, result) {
|
}, function(err, result) {
|
||||||
if(err) {
|
if (err) {
|
||||||
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);
|
|
||||||
websockets.server.sockets.in('home').emit('event:new_post', {
|
|
||||||
posts: result.postData
|
|
||||||
});
|
|
||||||
websockets.server.sockets.in('user/' + socket.uid).emit('event:new_post', {
|
|
||||||
posts: result.postData
|
|
||||||
});
|
|
||||||
|
|
||||||
websockets.emitTopicPostStats();
|
privileges.categories.filterUids('read', result.topicData.cid, uids, function(err, uids) {
|
||||||
topics.pushUnreadCount();
|
if (err) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(var i=0; i<uids.length; ++i) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
callback(null, result.topicData);
|
websockets.emitTopicPostStats();
|
||||||
}
|
topics.pushUnreadCount();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user