mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: pass options to digest
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user