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]]'));
}
if (!tids.length) {
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();
});
topics.markAsRead(tids, socket.uid, callback);
};
SocketTopics.markTopicNotificationsRead = function(socket, tid, callback) {
@ -43,13 +25,7 @@ module.exports = function(SocketTopics) {
};
SocketTopics.markAllRead = function(socket, data, callback) {
db.getSortedSetRevRangeByScore('topics:recent', 0, -1, '+inf', Date.now() - topics.unreadCutoff, function(err, tids) {
if (err) {
return callback(err);
}
SocketTopics.markAsRead(socket, tids, callback);
});
topics.markAllRead(socket.uid, callback);
};
SocketTopics.markCategoryTopicsRead = function(socket, cid, callback) {

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

@ -92,6 +92,18 @@
</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="col-sm-2 col-xs-12 settings-header">Signature Settings</div>
<div class="col-sm-10 col-xs-12">

Loading…
Cancel
Save