diff --git a/public/src/forum/unread.js b/public/src/forum/unread.js
index 9829ca7a25..ac9b275a68 100644
--- a/public/src/forum/unread.js
+++ b/public/src/forum/unread.js
@@ -12,8 +12,17 @@ define(['forum/recent'], function(recent) {
recent.watchForNewPosts();
$('#mark-allread-btn').on('click', function() {
+ function getUnreadTids() {
+ var tids = [];
+ $('#topics-container .category-item[data-tid]').each(function() {
+ tids.push($(this).attr('data-tid'));
+ });
+ return tids;
+ }
+
var btn = $(this);
- socket.emit('topics.markAllRead', function(err) {
+
+ socket.emit('topics.markAllRead', getUnreadTids(), function(err) {
if(err) {
return app.alertError('There was an error marking topics read!');
}
diff --git a/public/templates/unread.tpl b/public/templates/unread.tpl
index c1aa0f87d1..58cd9eab1e 100644
--- a/public/templates/unread.tpl
+++ b/public/templates/unread.tpl
@@ -19,7 +19,7 @@
- -
+
-
diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js
index ec19101cd2..80139d2f65 100644
--- a/src/socket.io/topics.js
+++ b/src/socket.io/topics.js
@@ -1,3 +1,6 @@
+
+'use strict';
+
var topics = require('../topics'),
categories = require('../categories'),
threadTools = require('../threadTools'),
@@ -68,7 +71,7 @@ SocketTopics.post = function(socket, data, callback) {
type: 'success',
timeout: 2000
});
- callback(null);
+ callback();
}
});
};
@@ -88,14 +91,19 @@ SocketTopics.markAsRead = function(socket, data) {
};
SocketTopics.markAllRead = function(socket, data, callback) {
- topics.markAllRead(socket.uid, function(err) {
+
+ if (!Array.isArray(data)) {
+ return callback(new Error('invalid-data'));
+ }
+
+ topics.markAllRead(socket.uid, data, function(err) {
if(err) {
return callback(err);
}
index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', null, []);
- callback(null);
+ callback();
});
};
diff --git a/src/topics.js b/src/topics.js
index 590e5deafd..7be77d3458 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -797,24 +797,6 @@ var async = require('async'),
});
};
- Topics.markAllRead = function(uid, callback) {
- Topics.getLatestTids(0, -1, 'month', function(err, tids) {
- if (err) {
- return callback(err);
- }
-
- if(!tids || !tids.length) {
- return callback();
- }
-
- function markRead(tid, next) {
- Topics.markAsRead(tid, uid, next);
- }
-
- async.each(tids, markRead, callback);
- });
- };
-
Topics.getTitleByPid = function(pid, callback) {
Topics.getTopicFieldByPid('title', pid, callback);
};
@@ -862,6 +844,16 @@ var async = require('async'),
});
};
+ Topics.markAllRead = function(uid, tids, callback) {
+ if(!tids || !tids.length) {
+ return callback();
+ }
+
+ async.each(tids, function (tid, next) {
+ Topics.markAsRead(tid, uid, next);
+ }, callback);
+ };
+
Topics.markAsRead = function(tid, uid, callback) {
db.setAdd('tid:' + tid + ':read_by_uid', uid, function(err) {