From db3632557e7f3d49277d443cab04fbe2a6c37c12 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 21 Mar 2014 17:48:32 -0400 Subject: [PATCH] moved notification push out of markAsRead --- src/categories.js | 4 ++-- src/controllers/topics.js | 14 +++----------- src/socket.io/topics.js | 11 ++++++++--- src/topics/fork.js | 1 + src/topics/unread.js | 16 +++++++++++----- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/categories.js b/src/categories.js index e04b8c56cc..576f29af58 100644 --- a/src/categories.js +++ b/src/categories.js @@ -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) { diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 879bd65cd3..213b8f63c0 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -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); }); } diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index 0185ac60bc..d77ef1fd32 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -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