chadtmiller.com/group-host
atmosphere group host
0
0
A post is labelled and taken down from its own Review
crates/group-host/src/moderation.rs+1−0
| @@ -446,6 +446,7 @@ fn event_view(e: &Event, actors: &HashMap<String, Value>) -> Value { | ||
"createdAt": iso(e.created_at), | ||
"createdBy": e.actor, | ||
"creator": e.actor.as_ref().map(|did| &actors[did]), | ||
"cid": e.cid, | ||
"event": present(event), | ||
})) | ||
} | ||
crates/group-host/tests/moderation.rs+3−0
| @@ -553,6 +553,9 @@ async fn resolves_and_escalates_with_a_note() { | ||
// Narrowed to one version of the record: what was said of it. | ||
let (_, version) = history(&format!("&cid={CID}")).await; | ||
assert_eq!(kinds(&version), ["labelEvent", "reportEvent"]); | ||
// Each names the version it is about, for a moderator to act on it. | ||
assert_eq!(version["events"][0]["cid"], CID); | ||
assert!(all["events"][2].get("cid").is_none()); | ||
// A page at a time, oldest first. | ||
let mut seen = Vec::new(); | ||
let mut cursor = String::new(); | ||
docs/design/moderation.md+2−1
| @@ -104,7 +104,8 @@ record it is, by its DID and handle, so a moderator reads who it is about | ||
rather than a DID. | ||
| ||
Its history is a list of events, each with an `id`, `createdAt`, who did | ||
it as `createdBy` and, by their DID and handle, as `creator`, and one of | ||
it as `createdBy` and, by their DID and handle, as `creator`, the | ||
version of a record it is about as `cid` when it names one, and one of | ||
four kinds as `event`: | ||
| ||
- `reportEvent`: someone reported it, with a `reasonType`, an optional | ||
docs/guides/moderating.md+3−2
| @@ -101,7 +101,9 @@ shows. | ||
Press the × to take a label back. Once the group has used a label, the | ||
dialog offers it to add with one press, under the field. | ||
| ||
Posts are labelled from a terminal only, as the last part shows. | ||
A post is labelled the same way, from its own Review, when the report | ||
named the version of the post it was about. If it didn't, its Review says | ||
so, and you label it from a terminal, as the last part shows. | ||
| ||
## How do I take an account down? | ||
| ||
| @@ -190,7 +192,6 @@ Each act here has a command in [the `opensocial` command](../reference/cli.md): | ||
- Label an account: `opensocial mod label gardens.groups.test <did> spam`. | ||
A takedown is the same with `!takedown`. | ||
- Label a post: `opensocial mod label gardens.groups.test <at:// uri> <label> --cid <cid>`. | ||
Only the terminal labels posts. | ||
- Take a label back: the same command with `--undo`. | ||
- Remove a member: `opensocial member eject gardens.groups.test maximilianaquinces.test`. | ||
| ||
harness/look/seeds/reports.mjs+3−1
| @@ -61,7 +61,9 @@ export default async ({ world, who, opensocial }) => { | ||
'carol', | ||
{ | ||
$type: 'fyi.opensocial.defs#recordSubject', | ||
uri: `${space}/${who.frank.did}/com.example.forum.post/3mzoijrblxc2j` | ||
uri: `${space}/${who.frank.did}/com.example.forum.post/3mzoijrblxc2j`, | ||
// The version reported, as an app names it. | ||
cid: 'bafyreie5737gdxlw5i64vzichcalba3z2v5n6icifvx5xytvske7mr3hpm' | ||
}, | ||
'reasonMisleading', | ||
'Says the north ridge trail is open. It has been closed since the rockfall in September.' | ||
lexicons/fyi/opensocial/defs.json+5−0
| @@ -916,6 +916,11 @@ | ||
"ref": "#actorView", | ||
"description": "Who did it, as a view names them, when createdBy is given." | ||
}, | ||
"cid": { | ||
"type": "string", | ||
"format": "cid", | ||
"description": "The version of a record subject it is about, when it names one." | ||
}, | ||
"event": { | ||
"type": "union", | ||
"refs": [ | ||
web/src/lib/organisms/ReviewDialog.svelte+60−22
| @@ -6,10 +6,11 @@ | ||
import SubjectHistory from '#lib/molecules/SubjectHistory.svelte'; | ||
import ReportDialog from '#lib/organisms/ReportDialog.svelte'; | ||
import { inDialog, inOpenDialog } from '#lib/forms.ts'; | ||
import { type Subject, TAKEDOWN, labelsOf, reported, what } from '#lib/moderation.ts'; | ||
import { type Subject, TAKEDOWN, labelsOf, latestCid, reported, what } from '#lib/moderation.ts'; | ||
/** | ||
* Everything a moderator does about one subject, in a dialog opened by a | ||
* button whose `popovertarget` is `id`: for an account, the labels it | ||
* button whose `popovertarget` is `id`: for an account, or a record | ||
* whose version the queue knows, the labels it | ||
* wears, each removable, those the group uses (`choices`) to add and | ||
* another; taking it down; then resolving or escalating it, or, for one | ||
* the queue has never had, reporting it; and what happened to it. Each | ||
| @@ -42,6 +43,15 @@ | ||
// Why something in the dialog was refused, said in it. | ||
let failed = $state<string | null>(null); | ||
const account = $derived(s.key.startsWith('did:')); | ||
// What a label is put on: the account, or the record at the version | ||
// last reported or labelled; none for a record of no known version. | ||
const target = $derived<Record<string, string> | null>( | ||
account | ||
? { did: s.key } | ||
: latestCid(s.events) | ||
? { uri: s.key, cid: latestCid(s.events)! } | ||
: null | ||
); | ||
const wearing = $derived(labelsOf(s.events)); | ||
const takenDown = $derived(wearing.some((v) => TAKEDOWN.includes(v))); | ||
const toAdd = $derived(choices.filter((v) => !wearing.includes(v))); | ||
| @@ -49,6 +59,14 @@ | ||
const removable = (val: string) => (TAKEDOWN.includes(val) ? can.takedown : can.label); | ||
</script> | ||
| ||
{#snippet which()} | ||
{#each Object.entries(target ?? {}) as [name, value] (name)}<input | ||
type="hidden" | ||
{name} | ||
{value} | ||
/>{/each} | ||
{/snippet} | ||
| ||
<Dialog | ||
{id} | ||
title="Review" | ||
| @@ -61,7 +79,7 @@ | ||
<p><Person actor={s.actor} /> <span class="mute">· {what(s.key)} · {reported(s)}</span></p> | ||
{#if failed}<p class="danger">{failed}</p>{/if} | ||
| ||
{#if account && (can.label || can.takedown)} | ||
{#if target && (can.label || can.takedown)} | ||
<div class="review-part"> | ||
<h3>Labels</h3> | ||
{#if wearing.length} | ||
| @@ -75,7 +93,7 @@ | ||
action="?/unlabel" | ||
use:enhance={inOpenDialog((w) => (failed = w))} | ||
> | ||
<input type="hidden" name="did" value={s.key} /> | ||
{@render which()} | ||
<input type="hidden" name="val" value={val} /> | ||
<button class="quiet small" type="submit" aria-label={`Remove the label ${val}`} | ||
>×</button | ||
| @@ -96,7 +114,7 @@ | ||
action="?/label" | ||
use:enhance={inOpenDialog((w) => (failed = w))} | ||
> | ||
<input type="hidden" name="did" value={s.key} /> | ||
{@render which()} | ||
{#each toAdd as val (val)}<button | ||
class="quiet small mono" | ||
type="submit" | ||
| @@ -110,7 +128,7 @@ | ||
action="?/label" | ||
use:enhance={inOpenDialog((w) => (failed = w))} | ||
> | ||
<input type="hidden" name="did" value={s.key} /> | ||
{@render which()} | ||
<label class="field" | ||
>Add a label | ||
<input name="val" required maxlength="128" placeholder="off-topic" /></label | ||
| @@ -123,28 +141,48 @@ | ||
{#if can.takedown && !takenDown} | ||
<div class="review-part"> | ||
<div class="row-form"> | ||
<p class="mute"> | ||
Asks apps that follow the group's labels to hide everything this account posted. They | ||
stay in the group. | ||
</p> | ||
{#if account}<p class="mute"> | ||
Asks apps that follow the group's labels to hide everything this account posted. They | ||
stay in the group. | ||
</p>{:else}<p class="mute"> | ||
Asks apps that follow the group's labels to hide this. The rest of what they posted | ||
stays. | ||
</p>{/if} | ||
<button class="quiet small" type="button" popovertarget={`${id}-takedown`} | ||
>Take down</button | ||
> | ||
</div> | ||
<ConfirmDialog | ||
id={`${id}-takedown`} | ||
title="Take this account down?" | ||
action="?/label" | ||
confirm="Take down" | ||
danger={false} | ||
fields={{ did: s.key, val: '!takedown' }} | ||
>Apps that follow the group's labels hide what <Person actor={s.actor} /> posted. Removing the | ||
label undoes it.</ConfirmDialog | ||
> | ||
{#if account} | ||
<ConfirmDialog | ||
id={`${id}-takedown`} | ||
title="Take this account down?" | ||
action="?/label" | ||
confirm="Take down" | ||
danger={false} | ||
fields={{ ...target, val: '!takedown' }} | ||
>Apps that follow the group's labels hide what <Person actor={s.actor} /> posted. Removing | ||
the label undoes it.</ConfirmDialog | ||
> | ||
{:else} | ||
<ConfirmDialog | ||
id={`${id}-takedown`} | ||
title="Take this down?" | ||
action="?/label" | ||
confirm="Take down" | ||
danger={false} | ||
fields={{ ...target, val: '!takedown' }} | ||
>Apps that follow the group's labels hide this {what(s.key).toLowerCase()} by <Person | ||
actor={s.actor} | ||
/>. Removing the label undoes it.</ConfirmDialog | ||
> | ||
{/if} | ||
</div> | ||
{/if} | ||
{:else if !account} | ||
<p class="mute">Posts are labelled from a terminal, with opensocial mod label.</p> | ||
{:else if !target} | ||
<p class="mute"> | ||
The queue doesn't know which version of this to label. Label it from a terminal, with | ||
opensocial mod label and its CID. | ||
</p> | ||
{/if} | ||
| ||
{#if s.status && can.resolve} | ||
web/src/lib/moderation.ts+4−1
| @@ -15,7 +15,7 @@ export type Said = { | ||
val?: string; | ||
deleted?: boolean; | ||
}; | ||
export type Event = { id: string; createdAt: string; creator?: Actor; event: Said }; | ||
export type Event = { id: string; createdAt: string; creator?: Actor; cid?: string; event: Said }; | ||
/** A subject: `status` none for one the queue has never had. */ | ||
export type Subject = { | ||
key: string; | ||
| @@ -53,6 +53,9 @@ export function labelsUsed(subjects: Subject[]): string[] { | ||
return [...new Set(used)].filter((v): v is string => !!v && !TAKEDOWN.includes(v)).sort(); | ||
} | ||
| ||
/** The version of a record subject its latest event names, if any. */ | ||
export const latestCid = (events: Event[]) => events.findLast((e) => e.cid)?.cid; | ||
| ||
/** A subject's reports, oldest first. */ | ||
export const reports = (s: Subject) => s.events.filter((e) => kindOf(e) === 'reportEvent'); | ||
| ||
web/src/routes/g/[handle]/moderation/+page.server.ts+9−5
| @@ -110,11 +110,15 @@ export const load: PageServerLoad = async (event) => { | ||
}; | ||
}; | ||
| ||
/** The account a form names, as a label's subject. */ | ||
const account = (form: FormData) => ({ | ||
$type: 'com.atproto.admin.defs#repoRef', | ||
did: String(form.get('did')) | ||
}); | ||
/** What a form names, as a label's subject: an account, or a record at one version. */ | ||
const account = (form: FormData) => | ||
form.has('uri') | ||
? { | ||
$type: 'com.atproto.repo.strongRef', | ||
uri: String(form.get('uri')), | ||
cid: String(form.get('cid')) | ||
} | ||
: { $type: 'com.atproto.admin.defs#repoRef', did: String(form.get('did')) }; | ||
| ||
export const actions: Actions = { | ||
resolve: async (event) => { | ||