mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
closes #2074
when new notifications are pushed to uids clear their old notifications.
This commit is contained in:
@@ -51,6 +51,10 @@ module.exports = function(db, module) {
|
||||
}, callback);
|
||||
};
|
||||
|
||||
module.sortedSetsRemoveRangeByScore = function(keys, min, max, callback) {
|
||||
throw new Error('not implemented');
|
||||
};
|
||||
|
||||
function flattenSortedSet(set, callback) {
|
||||
callback(null, !set.length ? [] : set.reduce(function(a, b) {
|
||||
return (a.length ? a : [a.value]).concat([b.value]);
|
||||
|
||||
@@ -79,6 +79,12 @@ module.exports = function(db, module) {
|
||||
db.collection('objects').remove({_key: {$in: keys}, value: value}, callback);
|
||||
};
|
||||
|
||||
module.sortedSetsRemoveRangeByScore = function(keys, min, max, callback) {
|
||||
callback = callback || helpers.noop;
|
||||
db.collection('objects').remove({_key: {$in: keys}, score: {$lte: max, $gte: min}}, function(err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
function getSortedSetRange(key, start, stop, sort, withScores, callback) {
|
||||
db.collection('objects').find({_key:key}, {fields: {_id: 0, value: 1, score: 1}})
|
||||
|
||||
@@ -55,6 +55,16 @@ module.exports = function(redisClient, module) {
|
||||
multi('zrem', keys, value, callback);
|
||||
};
|
||||
|
||||
module.sortedSetsRemoveRangeByScore = function(keys, min, max, callback) {
|
||||
var multi = redisClient.multi();
|
||||
for(var i=0; i<keys.length; ++i) {
|
||||
multi.zremrangebyscore(keys[i], min, max);
|
||||
}
|
||||
multi.exec(function(err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
module.getSortedSetRange = function(key, start, stop, callback) {
|
||||
redisClient.zrange(key, start, stop, callback);
|
||||
};
|
||||
|
||||
@@ -141,6 +141,10 @@ var async = require('async'),
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var oneWeekAgo = Date.now() - 604800000;
|
||||
db.sortedSetsRemoveRangeByScore(unreadKeys, 0, oneWeekAgo);
|
||||
db.sortedSetsRemoveRangeByScore(readKeys, 0, oneWeekAgo);
|
||||
|
||||
plugins.fireHook('action:notification.pushed', {notification: notification, uids: uids});
|
||||
|
||||
for(var i=0; i<uids.length; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user