mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 01:10:31 +01:00
refactor: removed rather redundant flag reporters zset
This commit is contained in:
19
src/flags.js
19
src/flags.js
@@ -363,27 +363,30 @@ Flags.create = async function (type, id, uid, reason, timestamp) {
|
||||
};
|
||||
|
||||
Flags.getReports = async function (flagId) {
|
||||
const [reports, reporterUids] = await Promise.all([
|
||||
db.getSortedSetRevRangeWithScores(`flag:${flagId}:reports`, 0, -1),
|
||||
db.getSortedSetRevRange(`flag:${flagId}:reporters`, 0, -1),
|
||||
]);
|
||||
const payload = await db.getSortedSetRevRangeWithScores(`flag:${flagId}:reports`, 0, -1);
|
||||
const [reports, uids] = payload.reduce(function (memo, cur) {
|
||||
const value = cur.value.split(';');
|
||||
memo[1].push(value.shift());
|
||||
cur.value = value.join(';');
|
||||
memo[0].push(cur);
|
||||
|
||||
return memo;
|
||||
}, [[], []]);
|
||||
|
||||
await Promise.all(reports.map(async (report, idx) => {
|
||||
report.timestamp = report.score;
|
||||
report.timestampISO = new Date(report.score).toISOString();
|
||||
delete report.score;
|
||||
report.reporter = await user.getUserFields(reporterUids[idx], ['username', 'userslug', 'picture', 'reputation']);
|
||||
report.reporter = await user.getUserFields(uids[idx], ['username', 'userslug', 'picture', 'reputation']);
|
||||
}));
|
||||
|
||||
return reports;
|
||||
};
|
||||
|
||||
Flags.addReport = async function (flagId, type, id, uid, reason, timestamp) {
|
||||
// adds to reporters/report zsets
|
||||
await db.sortedSetAddBulk([
|
||||
[`flags:byReporter:${uid}`, timestamp, flagId],
|
||||
[`flag:${flagId}:reports`, timestamp, reason],
|
||||
[`flag:${flagId}:reporters`, timestamp, uid],
|
||||
[`flag:${flagId}:reports`, timestamp, [uid, reason].join(';')],
|
||||
|
||||
['flags:hash', flagId, [type, id, uid].join(':')],
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user