feat: filter followed tids by category

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 1b9e8928eb
commit f3afba6156

@ -177,9 +177,14 @@ module.exports = function (Topics) {
}
async function getFollowedTids(params) {
const tids = await db.getSortedSetsMembers(['uid:' + params.uid + ':followed_tids']);
const scores = await db.sortedSetScores('topics:recent', tids[0]);
const data = tids[0].map((tid, index) => ({ value: tid, score: scores[index] }));
let tids = (await db.getSortedSetsMembers(['uid:' + params.uid + ':followed_tids']))[0];
const filterCids = params.cid && params.cid.map(cid => parseInt(cid, 10));
if (filterCids) {
const topicData = await Topics.getTopicsFields(tids, ['tid', 'cid']);
tids = topicData.filter(t => filterCids.includes(t.cid)).map(t => t.tid);
}
const scores = await db.sortedSetScores('topics:recent', tids);
const data = tids.map((tid, index) => ({ value: tid, score: scores[index] }));
return data.filter(item => item.score > params.cutoff);
}

Loading…
Cancel
Save