2014-03-21 17:04:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2016-02-24 21:35:35 +02:00
|
|
|
var async = require('async');
|
|
|
|
|
var db = require('../database');
|
2016-07-07 17:17:17 -04:00
|
|
|
var plugins = require('../plugins');
|
2014-09-19 15:54:13 -04:00
|
|
|
|
2014-03-21 17:04:15 -04:00
|
|
|
module.exports = function(Topics) {
|
2014-09-03 15:16:41 -04:00
|
|
|
var terms = {
|
|
|
|
|
day: 86400000,
|
|
|
|
|
week: 604800000,
|
|
|
|
|
month: 2592000000,
|
|
|
|
|
year: 31104000000
|
|
|
|
|
};
|
2014-03-21 17:04:15 -04:00
|
|
|
|
2015-03-31 23:40:58 -04:00
|
|
|
Topics.getLatestTopics = function(uid, start, stop, term, callback) {
|
2014-11-16 16:15:49 -05:00
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
2015-03-31 23:40:58 -04:00
|
|
|
Topics.getLatestTidsFromSet('topics:recent', start, stop, term, next);
|
2014-11-16 16:15:49 -05:00
|
|
|
},
|
|
|
|
|
function(tids, next) {
|
|
|
|
|
Topics.getTopics(tids, uid, next);
|
|
|
|
|
},
|
|
|
|
|
function(topics, next) {
|
2015-03-31 23:40:58 -04:00
|
|
|
next(null, {topics: topics, nextStart: stop + 1});
|
2014-03-21 17:04:15 -04:00
|
|
|
}
|
2014-11-16 16:15:49 -05:00
|
|
|
], callback);
|
2014-03-21 17:04:15 -04:00
|
|
|
};
|
|
|
|
|
|
2015-03-31 23:40:58 -04:00
|
|
|
Topics.getLatestTidsFromSet = function(set, start, stop, term, callback) {
|
2014-03-21 17:04:15 -04:00
|
|
|
var since = terms.day;
|
2014-09-03 15:16:41 -04:00
|
|
|
if (terms[term]) {
|
2014-03-21 17:04:15 -04:00
|
|
|
since = terms[term];
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-31 23:40:58 -04:00
|
|
|
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
|
2014-03-21 17:04:15 -04:00
|
|
|
|
2015-01-07 13:35:49 -05:00
|
|
|
db.getSortedSetRevRangeByScore(set, start, count, '+inf', Date.now() - since, callback);
|
2014-03-21 17:04:15 -04:00
|
|
|
};
|
|
|
|
|
|
2014-09-19 15:54:13 -04:00
|
|
|
Topics.updateTimestamp = function(tid, timestamp, callback) {
|
|
|
|
|
async.parallel([
|
|
|
|
|
function(next) {
|
2016-02-24 21:35:35 +02:00
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.getTopicField(tid, 'deleted', next);
|
|
|
|
|
},
|
|
|
|
|
function (deleted, next) {
|
|
|
|
|
if (parseInt(deleted, 10) === 1) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
Topics.updateRecent(tid, timestamp, next);
|
|
|
|
|
}
|
|
|
|
|
], next);
|
2014-09-19 15:54:13 -04:00
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
Topics.setTopicField(tid, 'lastposttime', timestamp, next);
|
|
|
|
|
}
|
2016-02-24 21:35:35 +02:00
|
|
|
], function(err) {
|
2015-09-01 12:38:26 -04:00
|
|
|
callback(err);
|
|
|
|
|
});
|
2014-09-05 17:39:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.updateRecent = function(tid, timestamp, callback) {
|
|
|
|
|
callback = callback || function() {};
|
2016-07-07 17:17:17 -04:00
|
|
|
if (plugins.hasListeners('filter:topics.updateRecent')) {
|
|
|
|
|
plugins.fireHook('filter:topics.updateRecent', {tid: tid, timestamp: timestamp}, callback);
|
|
|
|
|
} else {
|
|
|
|
|
db.sortedSetAdd('topics:recent', timestamp, tid, callback);
|
|
|
|
|
}
|
2014-09-05 17:39:24 -04:00
|
|
|
};
|
2014-03-21 17:04:15 -04:00
|
|
|
};
|