Skip to content

Node.js based forum software built for the modern web

closes #2633

barisusakli4b3aa26abd5e
diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js
index 52d2c2cb01..c7c59e642b 100644
--- a/src/socket.io/topics.js
+++ b/src/socket.io/topics.js
@@ -124,7 +124,7 @@ SocketTopics.markTopicNotificationsRead = function(socket, tid, callback) {
};
SocketTopics.markAllRead = function(socket, data, callback) {
- topics.getUnreadTids(socket.uid, 0, -1, function(err, tids) {
+ topics.getLatestTidsFromSet('topics:recent', 0, -1, 'day', function(err, tids) {
if (err) {
return callback(err);
}
@@ -182,31 +182,23 @@ SocketTopics.markAsUnreadForAll = function(socket, tids, callback) {
},
function(cid, next) {
user.isModerator(socket.uid, cid, next);
- }
- ], function(err, isMod) {
- if (err) {
- return next(err);
- }
-
- if (!isAdmin && !isMod) {
- return next(new Error('[[error:no-privileges]]'));
- }
-
- topics.markAsUnreadForAll(tid, function(err) {
- if(err) {
- return next(err);
+ },
+ function(isMod, next) {
+ if (!isAdmin && !isMod) {
+ return next(new Error('[[error:no-privileges]]'));
}
-
- topics.updateRecent(tid, Date.now(), function(err) {
- if(err) {
- return next(err);
- }
- topics.pushUnreadCount(socket.uid);
- next();
- });
- });
- });
- }, callback);
+ topics.markAsUnreadForAll(tid, next);
+ },
+ function(next) {
+ topics.updateRecent(tid, Date.now(), next);
+ }
+ ], next);
+ }, function(err) {
+ if (err) {
+ return callback(err);
+ }
+ topics.pushUnreadCount(socket.uid);
+ });
});
};
diff --git a/src/topics/unread.js b/src/topics/unread.js
index d4adf2a994..4683395f6f 100644
--- a/src/topics/unread.js
+++ b/src/topics/unread.js
@@ -27,30 +27,26 @@ module.exports = function(Topics) {
topics: []
};
- Topics.getUnreadTids(uid, start, stop, function(err, tids) {
- if (err) {
- return callback(err);
- }
-
- if (!tids.length) {
- return callback(null, unreadTopics);
- }
-
- Topics.getTopicsByTids(tids, uid, function(err, topicData) {
- if (err) {
- return callback(err);
+ async.waterfall([
+ function(next) {
+ Topics.getUnreadTids(uid, start, stop, next);
+ },
+ function(tids, next) {
+ if (!tids.length) {
+ return next(null, []);
}
-
+ Topics.getTopicsByTids(tids, uid, next);
+ },
+ function(topicData, next) {
if (!Array.isArray(topicData) || !topicData.length) {
- return callback(null, unreadTopics);
+ return next(null, unreadTopics);
}
unreadTopics.topics = topicData;
unreadTopics.nextStart = stop + 1;
-
- callback(null, unreadTopics);
- });
- });
+ next(null, unreadTopics);
+ }
+ ], callback);
};
Topics.getUnreadTids = function(uid, start, stop, callback) {