v1.18.x
barisusakli 9 years ago
parent 7ad90b4ef6
commit c10b2fdb60

@ -14,25 +14,7 @@ module.exports = function(SocketTopics) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
if (!tids.length) { topics.markAsRead(tids, socket.uid, callback);
return callback();
}
tids = tids.filter(function(tid) {
return tid && utils.isNumber(tid);
});
topics.markAsRead(tids, socket.uid, function(err) {
if (err) {
return callback(err);
}
topics.pushUnreadCount(socket.uid);
for (var i=0; i<tids.length; ++i) {
topics.markTopicNotificationsRead(tids[i], socket.uid);
}
callback();
});
}; };
SocketTopics.markTopicNotificationsRead = function(socket, tid, callback) { SocketTopics.markTopicNotificationsRead = function(socket, tid, callback) {
@ -43,13 +25,7 @@ module.exports = function(SocketTopics) {
}; };
SocketTopics.markAllRead = function(socket, data, callback) { SocketTopics.markAllRead = function(socket, data, callback) {
db.getSortedSetRevRangeByScore('topics:recent', 0, -1, '+inf', Date.now() - topics.unreadCutoff, function(err, tids) { topics.markAllRead(socket.uid, callback);
if (err) {
return callback(err);
}
SocketTopics.markAsRead(socket, tids, callback);
});
}; };
SocketTopics.markCategoryTopicsRead = function(socket, cid, callback) { SocketTopics.markCategoryTopicsRead = function(socket, cid, callback) {

@ -9,13 +9,11 @@ var user = require('../user');
var notifications = require('../notifications'); var notifications = require('../notifications');
var categories = require('../categories'); var categories = require('../categories');
var privileges = require('../privileges'); var privileges = require('../privileges');
var meta = require('../meta');
var utils = require('../../public/src/utils');
module.exports = function(Topics) { module.exports = function(Topics) {
var unreadCutoff = 86400000 * 2;
Topics.unreadCutoff = unreadCutoff;
Topics.getTotalUnread = function(uid, callback) { Topics.getTotalUnread = function(uid, callback) {
Topics.getUnreadTids(0, uid, 0, 20, function(err, tids) { Topics.getUnreadTids(0, uid, 0, 20, function(err, tids) {
callback(err, tids ? tids.length : 0); callback(err, tids ? tids.length : 0);
@ -52,13 +50,17 @@ module.exports = function(Topics) {
], callback); ], callback);
}; };
Topics.unreadCutoff = function() {
return Date.now() - (parseInt(meta.config.unreadCutoff, 10) || 2) * 86400000;
};
Topics.getUnreadTids = function(cid, uid, start, stop, callback) { Topics.getUnreadTids = function(cid, uid, start, stop, callback) {
uid = parseInt(uid, 10); uid = parseInt(uid, 10);
if (uid === 0) { if (uid === 0) {
return callback(null, []); return callback(null, []);
} }
var cutoff = Date.now() - unreadCutoff; var cutoff = Topics.unreadCutoff();
async.parallel({ async.parallel({
ignoredCids: function(next) { ignoredCids: function(next) {
@ -166,9 +168,13 @@ module.exports = function(Topics) {
if (!Array.isArray(tids) || !tids.length) { if (!Array.isArray(tids) || !tids.length) {
return callback(); return callback();
} }
tids = tids.filter(Boolean);
tids = tids.filter(function(tid) {
return tid && utils.isNumber(tid);
});
if (!tids.length) { if (!tids.length) {
return callback(); return callback(null, false);
} }
async.waterfall([ async.waterfall([
@ -184,7 +190,7 @@ module.exports = function(Topics) {
}); });
if (!tids.length) { if (!tids.length) {
return callback(); return callback(null, false);
} }
var now = Date.now(); var now = Date.now();
@ -208,11 +214,30 @@ module.exports = function(Topics) {
categories.markAsRead(cids, uid, next); categories.markAsRead(cids, uid, next);
}, },
function (next) { function (next) {
Topics.pushUnreadCount(uid);
for (var i=0; i<tids.length; ++i) {
Topics.markTopicNotificationsRead(tids[i], uid);
}
next(null, true); next(null, true);
} }
], callback); ], callback);
}; };
Topics.markAllRead = function(uid, callback) {
async.waterfall([
function (next) {
db.getSortedSetRevRangeByScore('topics:recent', 0, -1, '+inf', Topics.unreadCutoff(), next);
},
function (tids, next) {
Topics.markAsRead(uid, tids, next);
},
function (markedRead, next) {
db.delete('uid:' + uid + ':tids_unread', next);
}
], callback);
};
Topics.markTopicNotificationsRead = function(tid, uid) { Topics.markTopicNotificationsRead = function(tid, uid) {
if (!tid) { if (!tid) {
return; return;
@ -259,7 +284,7 @@ module.exports = function(Topics) {
return callback(err); return callback(err);
} }
var cutoff = Date.now() - unreadCutoff; var cutoff = Topics.unreadCutoff();
var result = tids.map(function(tid, index) { var result = tids.map(function(tid, index) {
return !results.tids_unread[index] && return !results.tids_unread[index] &&
(results.recentScores[index] < cutoff || (results.recentScores[index] < cutoff ||

@ -92,6 +92,18 @@
</div> </div>
<div class="row">
<div class="col-sm-2 col-xs-12 settings-header">Unread Settings</div>
<div class="col-sm-10 col-xs-12">
<form>
<div class="form-group">
<label for="unreadCutoff">Unread cutoff days</label>
<input id="unreadCutoff" type="text" class="form-control" value="2" data-field="unreadCutoff">
</div>
</form>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-sm-2 col-xs-12 settings-header">Signature Settings</div> <div class="col-sm-2 col-xs-12 settings-header">Signature Settings</div>
<div class="col-sm-10 col-xs-12"> <div class="col-sm-10 col-xs-12">

Loading…
Cancel
Save