One entry per open reported thing, an event id or a blob hash, with the report's type and words as the reason. Owner and moderator, like the rest of the reports actions.
- commit
- f4acbb6df774004b9a47c7e6b28a0a4936d49696
- parent
- bba0a8cb4590e1ccdbe46e439da276e1a76ef225
- author
- Dami <dami.etoile@gmail.com>
| M | src/ | 14 | +++++++++++++- |
| M | src/ | 2 | +- |
@@ -50,7 +50,7 @@ const METHODS = [
5050 "allowkind", "disallowkind", "unrulekind", "listallowedkinds", "listblockedkinds",5151 "changerelayname", "changerelaydescription", "changerelayicon",5252 "createinvite", "listinvites", "revokeinvite", "listmembers",53- "listreports", "resolvereport",53+ "listreports", "resolvereport", "listeventsneedingmoderation",5454 "listblobs", "deleteblob",5555 "storagestats", "setretention", "listretention", "purgekind",5656 "deleterelay", "exportconfig", "importconfig", "resetrules",@@ -195,6 +195,18 @@ export async function manage(relay: Relay, req: Request): Promise<Response> {
195195 case "allowevent":196196 s.setEvent(str(0), null);197197 return reply({ result: true });198+ case "listeventsneedingmoderation": {199+ // NIP-86's view of the reports queue: one entry per reported thing,200+ // event id or blob hash, with the report's type and words as the reason.201+ const seen = new Set<string>();202+ const out: { id: string; reason: string }[] = [];203+ for (const r of relay.sql.exec<{ target_event: string; type: string; content: string }>(`SELECT target_event, type, content FROM reports WHERE status='open' AND target_event<>'' ORDER BY at DESC LIMIT 500`)) {204+ if (seen.has(r.target_event)) continue;205+ seen.add(r.target_event);206+ out.push({ id: r.target_event, reason: [r.type, r.content.slice(0, 200)].filter(Boolean).join(": ") });207+ }208+ return reply({ result: out });209+ }198210 case "listreports": {199211 const status = str(0) || "open";200212 return reply({ result: relay.sql.exec(`SELECT * FROM reports WHERE status=? ORDER BY at DESC LIMIT 200`, status).toArray() });@@ -43,7 +43,7 @@ export const METHOD_ACTIONS: Record<string, Action> = {
4343 banpubkey: "ban", banevent: "ban", allowevent: "ban",4444 deleteevent: "deleteEvent",4545 createinvite: "invites", revokeinvite: "invites",46- resolvereport: "reports",46+ resolvereport: "reports", listeventsneedingmoderation: "reports",4747 setpolicy: "rules", allowkind: "rules", disallowkind: "rules", unrulekind: "rules", setretention: "rules", purgekind: "rules", resetrules: "rules",4848 changerelayname: "identity", changerelaydescription: "identity", changerelayicon: "identity",4949 storagestats: "storage", deleteblob: "storage",