moved notification push out of markAsRead

v1.18.x
barisusakli 11 years ago
parent 7a1037dc11
commit db3632557e

@ -198,8 +198,8 @@ var db = require('./database'),
});
};
Categories.markAsRead = function(cid, uid) {
db.setAdd('cid:' + cid + ':read_by_uid', uid);
Categories.markAsRead = function(cid, uid, callback) {
db.setAdd('cid:' + cid + ':read_by_uid', uid, callback);
};
Categories.markAsUnreadForAll = function(cid, callback) {

@ -54,9 +54,7 @@ topicsController.get = function(req, res, next) {
});
},
function (topicData, next) {
var lastMod = topicData.timestamp,
timestamp,
description = '';
var description = '';
if(topicData.posts.length) {
description = S(topicData.posts[0].content).stripTags().s;
@ -68,13 +66,6 @@ topicsController.get = function(req, res, next) {
description = validator.escape(description);
for (var x = 0, numPosts = topicData.posts.length; x < numPosts; x++) {
timestamp = parseInt(topicData.posts[x].timestamp, 10);
if (timestamp > lastMod) {
lastMod = timestamp;
}
}
var ogImageUrl = meta.config['brand:logo'];
if(ogImageUrl && ogImageUrl.indexOf('http') === -1) {
ogImageUrl = nconf.get('url') + ogImageUrl;
@ -119,7 +110,7 @@ topicsController.get = function(req, res, next) {
},
{
property: 'article:modified_time',
content: utils.toISOString(lastMod)
content: utils.toISOString(topicData.lastposttime)
},
{
property: 'article:section',
@ -162,6 +153,7 @@ topicsController.get = function(req, res, next) {
if (uid) {
topics.markAsRead(tid, uid, function(err) {
topics.pushUnreadCount(uid);
topics.markTopicNotificationsRead(tid, uid);
});
}

@ -92,22 +92,27 @@ SocketTopics.markAsRead = function(socket, data) {
topics.markAsRead(data.tid, data.uid, function(err) {
topics.pushUnreadCount(data.uid);
topics.markTopicNotificationsRead(data.tid, data.uid);
});
};
SocketTopics.markAllRead = function(socket, data, callback) {
SocketTopics.markAllRead = function(socket, tids, callback) {
if (!Array.isArray(data)) {
if (!Array.isArray(tids)) {
return callback(new Error('invalid-data'));
}
topics.markAllRead(socket.uid, data, function(err) {
topics.markAllRead(socket.uid, tids, function(err) {
if(err) {
return callback(err);
}
index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', null, 0);
for (var i=0; i<tids.length; ++i) {
topics.markTopicNotificationsRead(tids[i], socket.uid);
}
callback();
});
};

@ -47,6 +47,7 @@ module.exports = function(Topics) {
return callback(err);
}
Topics.updateTimestamp(tid, Date.now());
Topics.getTopicData(tid, callback);
});

@ -162,15 +162,21 @@ module.exports = function(Topics) {
Topics.markAsRead = function(tid, uid, callback) {
db.setAdd('tid:' + tid + ':read_by_uid', uid, function(err) {
if(callback) {
callback(err);
if (err) {
return callback(err);
}
});
Topics.getTopicField(tid, 'cid', function(err, cid) {
categories.markAsRead(cid, uid);
Topics.getTopicField(tid, 'cid', function(err, cid) {
if (err) {
return callback(err);
}
categories.markAsRead(cid, uid, callback);
});
});
};
Topics.markTopicNotificationsRead = function(tid, uid) {
user.notifications.getUnreadByUniqueId(uid, 'topic:' + tid, function(err, nids) {
notifications.mark_read_multiple(nids, uid, function() {
user.notifications.pushCount(uid);

Loading…
Cancel
Save