flotilla/src/app/deletes.ts
2026-06-08 17:07:39 -07:00

28 lines
777 B
TypeScript

import type {TrustedEvent} from "@welshman/util"
import {DELETE, getTag, makeEvent} from "@welshman/util"
import {publishThunk, tagEvent} from "@welshman/app"
import {PROTECTED} from "@app/groups"
export type DeleteParams = {
protect: boolean
event: TrustedEvent
tags?: string[][]
}
export const makeDelete = ({protect, event, tags = []}: DeleteParams) => {
const thisTags = [["k", String(event.kind)], ...tagEvent(event), ...tags]
const groupTag = getTag("h", event.tags)
if (groupTag) {
thisTags.push(groupTag)
}
if (protect) {
thisTags.push(PROTECTED)
}
return makeEvent(DELETE, {tags: thisTags})
}
export const publishDelete = ({relays, ...params}: DeleteParams & {relays: string[]}) =>
publishThunk({event: makeDelete(params), relays})