mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 17:16:14 +01:00
Merge pull request #2621 from TheBronx/master
new filter hooks on favourite actions #2620
This commit is contained in:
@@ -174,25 +174,43 @@ function favouriteCommand(socket, command, eventName, notification, data, callba
|
||||
return callback(new Error('[[error:post-deleted]]'));
|
||||
}
|
||||
|
||||
favourites[command](data.pid, socket.uid, function(err, result) {
|
||||
/*
|
||||
hooks:
|
||||
filter.post.upvote
|
||||
filter.post.downvote
|
||||
filter.post.unvote
|
||||
filter.post.favourite
|
||||
filter.post.unfavourite
|
||||
*/
|
||||
plugins.fireHook('filter:post.' + command, {data: data, uid: socket.uid}, function(err, filteredData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
socket.emit('posts.' + command, result);
|
||||
|
||||
if (result && eventName) {
|
||||
websockets.in(data.room_id).emit('event:' + eventName, result);
|
||||
}
|
||||
|
||||
if (notification) {
|
||||
SocketPosts.sendNotificationToPostOwner(data.pid, socket.uid, notification);
|
||||
}
|
||||
callback();
|
||||
executeFavouriteCommand(socket, command, eventName, notification, filteredData.data, callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function executeFavouriteCommand(socket, command, eventName, notification, data, callback) {
|
||||
favourites[command](data.pid, socket.uid, function(err, result) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
socket.emit('posts.' + command, result);
|
||||
|
||||
if (result && eventName) {
|
||||
websockets.in(data.room_id).emit('event:' + eventName, result);
|
||||
}
|
||||
|
||||
if (notification) {
|
||||
SocketPosts.sendNotificationToPostOwner(data.pid, socket.uid, notification);
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
SocketPosts.sendNotificationToPostOwner = function(pid, fromuid, notification) {
|
||||
if(!pid || !fromuid || !notification) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user