feat: allow pins to expire (if set) (#8908)

* fix: add back topic assert middleware for pin route

* feat: server-side handling of pin expiries

* refactor: togglePin to not require uid parameter [breaking]

* feat: automatic unpinning if pin has expiration set

* feat: client-side modal for setting pin expiration

* refactor: categories.getPinnedTids to accept multiple cids

... in preparation for pin expiry logic, direct access to *:pinned zsets is discouraged

* fix: remove references to since-removed jobs file for topics

* feat: expire pins when getPinnedTids is called

* refactor: make the togglePin change non-breaking

The 'action:topic.pin' hook now sends uid again, as before. However, if it is a system action (that is, a pin that expired), 'system' will be sent in instead of a valid uid
This commit is contained in:
Julian Lam
2020-11-20 11:31:14 -05:00
committed by GitHub
parent e5d94d9096
commit 046d0b1637
10 changed files with 125 additions and 24 deletions

View File

@@ -57,18 +57,20 @@ module.exports = function (Topics) {
async function getCidTids(params) {
const sets = [];
const pinnedSets = [];
params.cids.forEach(function (cid) {
if (params.sort === 'recent') {
sets.push('cid:' + cid + ':tids');
} else {
sets.push('cid:' + cid + ':tids' + (params.sort ? ':' + params.sort : ''));
}
pinnedSets.push('cid:' + cid + ':tids:pinned');
});
const [tids, pinnedTids] = await Promise.all([
db.getSortedSetRevRange(sets, 0, meta.config.recentMaxTopics - 1),
db.getSortedSetRevRange(pinnedSets, 0, -1),
categories.getPinnedTids({
cid: params.cids,
start: 0,
stop: -1,
}),
]);
return pinnedTids.concat(tids);
}