feat: send undo when rescinding/deleting a report

This commit is contained in:
Opliko
2024-04-14 01:52:07 +02:00
parent 2a2b855fe2
commit c1dfa8d2fe
2 changed files with 49 additions and 6 deletions

View File

@@ -223,10 +223,37 @@ activitypubApi.flag = enabledCheck(async (caller, flag) => {
if (flag.type === 'post' && activitypub.helpers.isUri(flag.targetUid)) {
reportedIds.push(flag.targetUid);
}
const reason = flag.reports.filter(report => report.reporter.uid === caller.uid).at(-1);
const reason = flag.reason ||
(flag.reports && flag.reports.filter(report => report.reporter.uid === caller.uid).at(-1).value);
await activitypub.send('uid', caller.uid, reportedIds, {
id: `${nconf.get('url')}/${flag.type}/${encodeURIComponent(flag.targetId)}#activity/flag/${caller.uid}`,
type: 'Flag',
object: reportedIds,
content: reason ? reason.value : undefined,
content: reason,
});
await db.sortedSetAdd(`flag:${flag.flagId}:remote`, Date.now(), caller.uid);
});
activitypubApi.undo.flag = enabledCheck(async (caller, flag) => {
if (!activitypub.helpers.isUri(flag.targetId)) {
return;
}
const reportedIds = [flag.targetId];
if (flag.type === 'post' && activitypub.helpers.isUri(flag.targetUid)) {
reportedIds.push(flag.targetUid);
}
const reason = flag.reason ||
(flag.reports && flag.reports.filter(report => report.reporter.uid === caller.uid).at(-1).value);
await activitypub.send('uid', caller.uid, reportedIds, {
id: `${nconf.get('url')}/${flag.type}/${encodeURIComponent(flag.targetId)}#activity/undo:flag/${caller.uid}`,
type: 'Undo',
object: {
id: `${nconf.get('url')}/${flag.type}/${encodeURIComponent(flag.targetId)}#activity/flag/${caller.uid}`,
actor: `${nconf.get('url')}/uid/${caller.uid}`,
type: 'Flag',
object: reportedIds,
content: reason,
},
});
await db.sortedSetRemove(`flag:${flag.flagId}:remote`, caller.uid);
});