Node.js based forum software built for the modern web
Merge remote-tracking branch 'origin/develop' into activitypub
Julian Lam0b2faf21f956
diff --cc install/package.jsonindex d6ab418c94,1e50efcee4..75b011bbb9--- a/install/package.json+++ b/install/package.json@@@ -98,8 -98,8 +98,8 @@@"nodebb-plugin-dbsearch": "6.2.3","nodebb-plugin-emoji": "5.1.13","nodebb-plugin-emoji-android": "4.0.0",- "nodebb-plugin-markdown": "12.2.6",+ "nodebb-plugin-markdown": "13.0.0-pre.3",- "nodebb-plugin-mentions": "4.4.2",+ "nodebb-plugin-mentions": "4.4.3","nodebb-plugin-ntfy": "1.7.4","nodebb-plugin-spam-be-gone": "2.2.1","nodebb-rewards-essentials": "1.0.0",diff --cc src/events.jsindex 2a2c3ce20d,41e1f0d29b..b750876341--- a/src/events.js+++ b/src/events.js@@@ -96,20 -99,68 +99,70 @@@ events.log = async function (data)db.setObject(`event:${eid}`, data),]);plugins.hooks.fire('action:events.log', { data: data });++ return { eid };};- events.getEvents = async function (filter, start, stop, from, to) {- // from/to optional- if (from === undefined) {- from = '-inf';+ // filter, start, stop, from(optional), to(optional), uids(optional)+ events.getEvents = async function (options) {+ // backwards compatibility+ if (arguments.length > 1) {+ // eslint-disable-next-line prefer-rest-params+ const args = Array.prototype.slice.call(arguments);+ options = {+ filter: args[0],+ start: args[1],+ stop: args[2],+ from: args[3],+ to: args[4],+ };}- if (to === undefined) {- to = '+inf';+ // from/to optional+ const from = options.hasOwnProperty('from') ? options.from : '-inf';+ const to = options.hasOwnProperty('to') ? options.to : '+inf';+ const { filter, start, stop, uids } = options;+ let eids = [];++ if (Array.isArray(uids)) {+ if (filter === '') {+ eids = await db.getSortedSetRevRangeByScore(+ uids.map(uid => `events:time:uid:${uid}`),+ start,+ stop === -1 ? -1 : stop - start + 1,+ to,+ from+ );+ } else {+ eids = await Promise.all(+ uids.map(+ uid => db.getSortedSetRevIntersect({+ sets: [`events:time:uid:${uid}`, `events:time:${filter}`],+ start: 0,+ stop: -1,+ weights: [1, 0],+ withScores: true,+ })+ )+ );++ eids = _.flatten(eids)+ .filter(+ i => (from === '-inf' || i.score >= from) && (to === '+inf' || i.score <= to)+ )+ .sort((a, b) => b.score - a.score)+ .slice(start, stop + 1)+ .map(i => i.value);+ }+ } else {+ eids = await db.getSortedSetRevRangeByScore(+ `events:time${filter ? `:${filter}` : ''}`,+ start,+ stop === -1 ? -1 : stop - start + 1,+ to,+ from+ );}- const eids = await db.getSortedSetRevRangeByScore(`events:time${filter ? `:${filter}` : ''}`, start, stop === -1 ? -1 : stop - start + 1, to, from);return await events.getEventsByEventIds(eids);};