Skip to content

Node.js based forum software built for the modern web

feat: pass options to digest

Baris Usakli23da300958df
diff --git a/src/topics/index.js b/src/topics/index.js
index fb57fcd5d9..aae8647ecc 100644
--- a/src/topics/index.js
+++ b/src/topics/index.js
@@ -52,22 +52,29 @@ Topics.getTopicsFromSet = function (set, uid, start, stop, callback) {
], callback);
};
-Topics.getTopics = function (tids, uid, callback) {
+Topics.getTopics = function (tids, options, callback) {
+ let uid = options;
+ if (typeof options === 'object') {
+ uid = options.uid;
+ }
async.waterfall([
function (next) {
privileges.topics.filterTids('read', tids, uid, next);
},
function (tids, next) {
- Topics.getTopicsByTids(tids, uid, next);
+ Topics.getTopicsByTids(tids, options, next);
},
], callback);
};
-Topics.getTopicsByTids = function (tids, uid, callback) {
+Topics.getTopicsByTids = function (tids, options, callback) {
if (!Array.isArray(tids) || !tids.length) {
return callback(null, []);
}
-
+ let uid = options;
+ if (typeof options === 'object') {
+ uid = options.uid;
+ }
var uids;
var cids;
var topics;
@@ -107,7 +114,7 @@ Topics.getTopicsByTids = function (tids, uid, callback) {
Topics.getUserBookmarks(tids, uid, next);
},
teasers: function (next) {
- Topics.getTeasers(topics, uid, next);
+ Topics.getTeasers(topics, options, next);
},
tags: function (next) {
Topics.getTopicsTagsObjects(tids, next);
diff --git a/src/topics/recent.js b/src/topics/recent.js
index dd5f7a148d..fee915bd73 100644
--- a/src/topics/recent.js
+++ b/src/topics/recent.js
@@ -28,16 +28,17 @@ module.exports = function (Topics) {
};
/* not an orphan method, used in widget-essentials */
- Topics.getLatestTopics = function (uid, start, stop, term, callback) {
+ Topics.getLatestTopics = function (options, callback) {
+ // uid, start, stop, term
async.waterfall([
function (next) {
- Topics.getLatestTidsFromSet('topics:recent', start, stop, term, next);
+ Topics.getLatestTidsFromSet('topics:recent', options.start, options.stop, options.term, next);
},
function (tids, next) {
- Topics.getTopics(tids, uid, next);
+ Topics.getTopics(tids, options, next);
},
function (topics, next) {
- next(null, { topics: topics, nextStart: stop + 1 });
+ next(null, { topics: topics, nextStart: options.stop + 1 });
},
], callback);
};
diff --git a/src/topics/teaser.js b/src/topics/teaser.js
index c4af9cf7ca..b66507e95c 100644
--- a/src/topics/teaser.js
+++ b/src/topics/teaser.js
@@ -14,16 +14,21 @@ var utils = require('../utils');
module.exports = function (Topics) {
var stripTeaserTags = utils.stripTags.concat(['img']);
- Topics.getTeasers = function (topics, uid, callback) {
+ Topics.getTeasers = function (topics, options, callback) {
if (!Array.isArray(topics) || !topics.length) {
return callback(null, []);
}
+ let uid = options;
+ let teaserPost = meta.config.teaserPost;
+ if (typeof options === 'object') {
+ uid = options.uid;
+ teaserPost = options.teaserPost || meta.config.teaserPost;
+ }
var counts = [];
var teaserPids = [];
var postData;
var tidToPost = {};
- const teaserPost = this.teaserPost ? this.teaserPost : meta.config.teaserPost;
topics.forEach(function (topic) {
counts.push(topic && topic.postcount);
diff --git a/src/user/digest.js b/src/user/digest.js
index 2ece74489a..881805940c 100644
--- a/src/user/digest.js
+++ b/src/user/digest.js
@@ -163,41 +163,34 @@ Digest.send = function (data, callback) {
});
function getTermTopics(term, uid, start, stop, callback) {
+ const options = {
+ uid: uid,
+ start: start,
+ stop: stop,
+ term: term,
+ sort: 'posts',
+ teaserPost: 'last-post',
+ };
+
async.waterfall([
function (next) {
- topics.getSortedTopics({
- uid: uid,
- start: start,
- stop: stop,
- term: term,
- sort: 'posts',
- }, next);
+ topics.getSortedTopics(options, next);
},
function (data, next) {
if (!data.topics.length) {
- topics.getLatestTopics(uid, start, stop, term, next);
+ topics.getLatestTopics(options, next);
} else {
next(null, data);
}
},
(data, next) => {
- // Re-generate teasers with different teaserPost option
- topics.getTeasers.bind({ teaserPost: 'last-post' })(data.topics, uid, function (err, teasers) {
- if (err) {
- return next(err);
+ data.topics.forEach(function (topicObj) {
+ if (topicObj && topicObj.teaser && topicObj.teaser.content && topicObj.teaser.content.length > 255) {
+ topicObj.teaser.content = topicObj.teaser.content.slice(0, 255) + '...';
}
-
- data.topics.map(function (topicObj, i) {
- if (teasers[i].content.length > 255) {
- teasers[i].content = teasers[i].content.slice(0, 255) + '...';
- }
-
- topicObj.teaser = teasers[i];
- return topicObj;
- });
-
- next(null, data.topics);
});
+
+ next(null, data.topics);
},
], callback);
}
diff --git a/test/topics.js b/test/topics.js
index 0c467acdb6..b34119feb4 100644
--- a/test/topics.js
+++ b/test/topics.js
@@ -693,7 +693,12 @@ describe('Topic\'s', function () {
topics.ignore(newTid, uid, done);
},
function (done) {
- topics.getLatestTopics(uid, 0, -1, 'year', done);
+ topics.getLatestTopics({
+ uid: uid,
+ start: 0,
+ stop: -1,
+ term: 'year',
+ }, done);
},
function (results, done) {
var topics = results.topics;