mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 08:55:47 +01:00
@@ -268,6 +268,23 @@ var utils = require('../public/src/utils');
|
||||
});
|
||||
};
|
||||
|
||||
Notifications.rescind = function(nid, callback) {
|
||||
callback = callback || function() {};
|
||||
|
||||
async.parallel([
|
||||
async.apply(db.sortedSetRemove, 'notifications', nid),
|
||||
async.apply(db.delete, 'notifications:' + nid)
|
||||
], function(err) {
|
||||
if (err) {
|
||||
winston.error('Encountered error rescinding notification (' + nid + '): ' + err.message);
|
||||
} else {
|
||||
winston.verbose('[notifications/rescind] Rescinded notification "' + nid + '"');
|
||||
}
|
||||
|
||||
callback(err, nid);
|
||||
});
|
||||
};
|
||||
|
||||
Notifications.markRead = function(nid, uid, callback) {
|
||||
callback = callback || function() {};
|
||||
if (!parseInt(uid, 10) || !nid) {
|
||||
|
||||
@@ -77,7 +77,7 @@ function filterTidCidIgnorers(uids, tid, cid, callback) {
|
||||
], callback);
|
||||
}
|
||||
|
||||
SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, notification) {
|
||||
SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, command, notification) {
|
||||
if (!pid || !fromuid || !notification) {
|
||||
return;
|
||||
}
|
||||
@@ -107,7 +107,7 @@ SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, notification)
|
||||
bodyLong: results.postObj.content,
|
||||
pid: pid,
|
||||
path: '/post/' + pid,
|
||||
nid: 'post:' + pid + ':uid:' + fromuid,
|
||||
nid: command + ':post:' + pid + ':uid:' + fromuid,
|
||||
from: fromuid,
|
||||
mergeId: notification + '|' + pid,
|
||||
topicTitle: results.topicTitle
|
||||
@@ -124,7 +124,7 @@ SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, notification)
|
||||
};
|
||||
|
||||
|
||||
SocketHelpers.sendNotificationToTopicOwner = function(tid, fromuid, notification) {
|
||||
SocketHelpers.sendNotificationToTopicOwner = function(tid, fromuid, command, notification) {
|
||||
if (!tid || !fromuid || !notification) {
|
||||
return;
|
||||
}
|
||||
@@ -150,7 +150,7 @@ SocketHelpers.sendNotificationToTopicOwner = function(tid, fromuid, notification
|
||||
notifications.create({
|
||||
bodyShort: '[[' + notification + ', ' + results.username + ', ' + titleEscaped + ']]',
|
||||
path: '/topic/' + results.topicData.slug,
|
||||
nid: 'tid:' + tid + ':uid:' + fromuid,
|
||||
nid: command + ':tid:' + tid + ':uid:' + fromuid,
|
||||
from: fromuid
|
||||
}, next);
|
||||
}
|
||||
@@ -164,6 +164,11 @@ SocketHelpers.sendNotificationToTopicOwner = function(tid, fromuid, notification
|
||||
});
|
||||
};
|
||||
|
||||
SocketHelpers.rescindUpvoteNotification = function(pid, fromuid) {
|
||||
var nid = 'upvote:post:' + pid + ':uid:' + fromuid;
|
||||
notifications.rescind(nid);
|
||||
};
|
||||
|
||||
SocketHelpers.emitToTopicAndCategory = function(event, data) {
|
||||
websockets.in('topic_' + data.tid).emit(event, data);
|
||||
websockets.in('category_' + data.cid).emit(event, data);
|
||||
|
||||
@@ -152,7 +152,9 @@ module.exports = function(SocketPosts) {
|
||||
}
|
||||
|
||||
if (result && notification) {
|
||||
socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, notification);
|
||||
socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, command, notification);
|
||||
} else if (result && command === 'unvote') {
|
||||
socketHelpers.rescindUpvoteNotification(data.pid, socket.uid);
|
||||
}
|
||||
callback();
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = function(SocketPosts) {
|
||||
topics.movePostToTopic(data.pid, data.tid, next);
|
||||
},
|
||||
function (next) {
|
||||
socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, 'notifications:moved_your_post');
|
||||
socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, 'move', 'notifications:moved_your_post');
|
||||
next();
|
||||
}
|
||||
], callback);
|
||||
|
||||
@@ -40,7 +40,7 @@ module.exports = function(SocketTopics) {
|
||||
|
||||
socketHelpers.emitToTopicAndCategory('event:topic_moved', topicData);
|
||||
|
||||
socketHelpers.sendNotificationToTopicOwner(tid, socket.uid, 'notifications:moved_your_topic');
|
||||
socketHelpers.sendNotificationToTopicOwner(tid, socket.uid, 'move', 'notifications:moved_your_topic');
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user