mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46: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);
|
], 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([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
privileges.topics.filterTids('read', tids, uid, next);
|
privileges.topics.filterTids('read', tids, uid, next);
|
||||||
},
|
},
|
||||||
function (tids, next) {
|
function (tids, next) {
|
||||||
Topics.getTopicsByTids(tids, uid, next);
|
Topics.getTopicsByTids(tids, options, next);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.getTopicsByTids = function (tids, uid, callback) {
|
Topics.getTopicsByTids = function (tids, options, callback) {
|
||||||
if (!Array.isArray(tids) || !tids.length) {
|
if (!Array.isArray(tids) || !tids.length) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
let uid = options;
|
||||||
|
if (typeof options === 'object') {
|
||||||
|
uid = options.uid;
|
||||||
|
}
|
||||||
var uids;
|
var uids;
|
||||||
var cids;
|
var cids;
|
||||||
var topics;
|
var topics;
|
||||||
@@ -107,7 +114,7 @@ Topics.getTopicsByTids = function (tids, uid, callback) {
|
|||||||
Topics.getUserBookmarks(tids, uid, next);
|
Topics.getUserBookmarks(tids, uid, next);
|
||||||
},
|
},
|
||||||
teasers: function (next) {
|
teasers: function (next) {
|
||||||
Topics.getTeasers(topics, uid, next);
|
Topics.getTeasers(topics, options, next);
|
||||||
},
|
},
|
||||||
tags: function (next) {
|
tags: function (next) {
|
||||||
Topics.getTopicsTagsObjects(tids, next);
|
Topics.getTopicsTagsObjects(tids, next);
|
||||||
|
|||||||
@@ -28,16 +28,17 @@ module.exports = function (Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* not an orphan method, used in widget-essentials */
|
/* 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([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
Topics.getLatestTidsFromSet('topics:recent', start, stop, term, next);
|
Topics.getLatestTidsFromSet('topics:recent', options.start, options.stop, options.term, next);
|
||||||
},
|
},
|
||||||
function (tids, next) {
|
function (tids, next) {
|
||||||
Topics.getTopics(tids, uid, next);
|
Topics.getTopics(tids, options, next);
|
||||||
},
|
},
|
||||||
function (topics, next) {
|
function (topics, next) {
|
||||||
next(null, { topics: topics, nextStart: stop + 1 });
|
next(null, { topics: topics, nextStart: options.stop + 1 });
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,16 +14,21 @@ var utils = require('../utils');
|
|||||||
module.exports = function (Topics) {
|
module.exports = function (Topics) {
|
||||||
var stripTeaserTags = utils.stripTags.concat(['img']);
|
var stripTeaserTags = utils.stripTags.concat(['img']);
|
||||||
|
|
||||||
Topics.getTeasers = function (topics, uid, callback) {
|
Topics.getTeasers = function (topics, options, callback) {
|
||||||
if (!Array.isArray(topics) || !topics.length) {
|
if (!Array.isArray(topics) || !topics.length) {
|
||||||
return callback(null, []);
|
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 counts = [];
|
||||||
var teaserPids = [];
|
var teaserPids = [];
|
||||||
var postData;
|
var postData;
|
||||||
var tidToPost = {};
|
var tidToPost = {};
|
||||||
const teaserPost = this.teaserPost ? this.teaserPost : meta.config.teaserPost;
|
|
||||||
|
|
||||||
topics.forEach(function (topic) {
|
topics.forEach(function (topic) {
|
||||||
counts.push(topic && topic.postcount);
|
counts.push(topic && topic.postcount);
|
||||||
|
|||||||
@@ -163,41 +163,34 @@ Digest.send = function (data, callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function getTermTopics(term, uid, start, stop, callback) {
|
function getTermTopics(term, uid, start, stop, callback) {
|
||||||
async.waterfall([
|
const options = {
|
||||||
function (next) {
|
|
||||||
topics.getSortedTopics({
|
|
||||||
uid: uid,
|
uid: uid,
|
||||||
start: start,
|
start: start,
|
||||||
stop: stop,
|
stop: stop,
|
||||||
term: term,
|
term: term,
|
||||||
sort: 'posts',
|
sort: 'posts',
|
||||||
}, next);
|
teaserPost: 'last-post',
|
||||||
|
};
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
topics.getSortedTopics(options, next);
|
||||||
},
|
},
|
||||||
function (data, next) {
|
function (data, next) {
|
||||||
if (!data.topics.length) {
|
if (!data.topics.length) {
|
||||||
topics.getLatestTopics(uid, start, stop, term, next);
|
topics.getLatestTopics(options, next);
|
||||||
} else {
|
} else {
|
||||||
next(null, data);
|
next(null, data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(data, next) => {
|
(data, next) => {
|
||||||
// Re-generate teasers with different teaserPost option
|
data.topics.forEach(function (topicObj) {
|
||||||
topics.getTeasers.bind({ teaserPost: 'last-post' })(data.topics, uid, function (err, teasers) {
|
if (topicObj && topicObj.teaser && topicObj.teaser.content && topicObj.teaser.content.length > 255) {
|
||||||
if (err) {
|
topicObj.teaser.content = topicObj.teaser.content.slice(0, 255) + '...';
|
||||||
return next(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -693,7 +693,12 @@ describe('Topic\'s', function () {
|
|||||||
topics.ignore(newTid, uid, done);
|
topics.ignore(newTid, uid, done);
|
||||||
},
|
},
|
||||||
function (done) {
|
function (done) {
|
||||||
topics.getLatestTopics(uid, 0, -1, 'year', done);
|
topics.getLatestTopics({
|
||||||
|
uid: uid,
|
||||||
|
start: 0,
|
||||||
|
stop: -1,
|
||||||
|
term: 'year',
|
||||||
|
}, done);
|
||||||
},
|
},
|
||||||
function (results, done) {
|
function (results, done) {
|
||||||
var topics = results.topics;
|
var topics = results.topics;
|
||||||
|
|||||||
Reference in New Issue
Block a user