Work on thread detail page

This commit is contained in:
Jon Staab
2024-10-23 14:20:24 -07:00
parent 8d0c016621
commit 09028b69a4
15 changed files with 300 additions and 134 deletions
+40 -18
View File
@@ -46,6 +46,7 @@ import {
loadRelay,
} from "@welshman/app"
import {
REPLY,
tagRoom,
userMembership,
MEMBERSHIPS,
@@ -301,31 +302,52 @@ export const sendWrapped = async ({
)
}
export const makeReaction = ({
event,
content,
tags = [],
}: {
export type ReactionParams = {
event: TrustedEvent
content: string
tags?: string[][]
}) =>
createEvent(REACTION, {
content,
tags: [...tags, ...tagReactionTo(event)],
})
}
export const publishReaction = ({
relays,
event,
content,
tags = [],
}: {
relays: string[]
export const makeReaction = ({event, content, tags = []}: ReactionParams) =>
createEvent(REACTION, {content, tags: [...tags, ...tagReactionTo(event)]})
export const publishReaction = ({relays, ...params}: ReactionParams & {relays: string[]}) =>
publishThunk({event: makeReaction(params), relays})
export type ReplyParams = {
event: TrustedEvent
content: string
tags?: string[][]
}) => publishThunk({event: makeReaction({event, content, tags}), relays})
}
export const makeReply = ({event, content, tags = []}: ReplyParams) => {
const seenRoots = new Set<string>()
for (const [raw, ...tag] of event.tags.filter(t => t[0].match(/^K|E|A|I$/i))) {
const T = raw.toUpperCase()
const t = raw.toLowerCase()
if (seenRoots.has(T)) {
tags.push([t, ...tag])
} else {
tags.push([T, ...tag])
seenRoots.add(T)
}
}
if (seenRoots.size === 0) {
tags.push(["K", String(event.kind)])
tags.push(["E", event.id])
} else {
tags.push(["k", String(event.kind)])
tags.push(["e", event.id])
}
return createEvent(REPLY, {content, tags})
}
export const publishReply = ({relays, ...params}: ReplyParams & {relays: string[]}) =>
publishThunk({event: makeReply(params), relays})
export const makeDelete = ({event}: {event: TrustedEvent}) =>
createEvent(DELETE, {tags: [["k", String(event.kind)], ...tagEvent(event)]})