From 86622b7ce5e3397acb0d6e765900345fbd65b57a Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Wed, 16 Oct 2024 15:57:18 -0700 Subject: [PATCH] Add undo to channel messages --- src/app/commands.ts | 8 +++- src/app/components/ChannelMessage.svelte | 33 ++++------------ src/app/components/ChannelThread.svelte | 13 +++++-- src/app/components/ChatMessage.svelte | 28 -------------- src/app/components/ThunkStatus.svelte | 38 +++++++++++++++++++ src/routes/+layout.svelte | 2 - .../spaces/[nrelay]/[[room]]/+page.svelte | 12 ++++-- 7 files changed, 69 insertions(+), 65 deletions(-) create mode 100644 src/app/components/ThunkStatus.svelte diff --git a/src/app/commands.ts b/src/app/commands.ts index 12217433..33d0660c 100644 --- a/src/app/commands.ts +++ b/src/app/commands.ts @@ -196,11 +196,13 @@ export const checkRelayAccess = async (url: string, claim = "") => { await connection.auth.attemptIfRequested() await connection.auth.waitIfPending() - const result = await publishThunk({ + const thunk = publishThunk({ event: createEvent(AUTH_JOIN, {tags: [["claim", claim]]}), relays: [url], }) + const result = await thunk.result + if (result[url].status !== PublishStatus.Success) { const message = result[url].message?.replace(/^.*: /, "") || "join request rejected" @@ -259,10 +261,12 @@ export const sendWrapped = async ({ await Promise.all( uniq(pubkeys).map(async recipient => { - return publishThunk({ + const thunk = publishThunk({ event: await nip59.wrap(recipient, stamp(template)), relays: ctx.app.router.PublishMessage(recipient).getUrls(), }) + + await thunk.result }), ) } diff --git a/src/app/components/ChannelMessage.svelte b/src/app/components/ChannelMessage.svelte index eb570758..be886425 100644 --- a/src/app/components/ChannelMessage.svelte +++ b/src/app/components/ChannelMessage.svelte @@ -3,21 +3,20 @@ import {hash, ellipsize, uniqBy, groupBy, now} from "@welshman/lib" import type {TrustedEvent} from "@welshman/util" import {deriveEvents, throttled} from "@welshman/store" - import {PublishStatus} from "@welshman/net" import { - publishStatusData, deriveProfile, deriveProfileDisplay, formatTimestampAsTime, pubkey, } from "@welshman/app" - import type {PublishStatusData} from "@welshman/app" + import type {Thunk} from "@welshman/app" import {REACTION, ZAP_RESPONSE, displayRelayUrl} from "@welshman/util" import {repository} from "@welshman/app" import Icon from "@lib/components/Icon.svelte" import Avatar from "@lib/components/Avatar.svelte" import Button from "@lib/components/Button.svelte" import Content from "@app/components/Content.svelte" + import ThunkStatus from "@app/components/ThunkStatus.svelte" import ChannelThread from "@app/components/ChannelThread.svelte" import ChannelMessageEmojiButton from "@app/components/ChannelMessageEmojiButton.svelte" import ChannelMessageMenuButton from "@app/components/ChannelMessageMenuButton.svelte" @@ -28,6 +27,7 @@ export let url export let room export let event: TrustedEvent + export let thunk: Thunk export let showPubkey = false export let hideParent = false @@ -40,13 +40,6 @@ const rootHints = [rootTag?.[2]].filter(Boolean) as string[] const rootEvent = rootId ? deriveEvent(rootId, rootHints) : readable(null) const [colorName, colorValue] = colors[parseInt(hash(event.pubkey)) % colors.length] - const ps = throttled( - 300, - derived(publishStatusData, $m => Object.values($m[event.id] || {})), - ) - - const findStatus = ($ps: PublishStatusData[], statuses: PublishStatus[]) => - $ps.find(({status}) => statuses.includes(status)) const openThread = () => { const root = $rootEvent || event @@ -72,10 +65,6 @@ $: rootPubkey = $rootEvent?.pubkey || rootTag?.[4] $: rootProfile = deriveProfile(rootPubkey || "") $: rootProfileDisplay = deriveProfileDisplay(rootPubkey || "") - $: isPublished = findStatus($ps, [PublishStatus.Success]) - $: isPending = findStatus($ps, [PublishStatus.Pending]) && event.created_at > now() - 30 - $: failure = - !isPending && !isPublished && findStatus($ps, [PublishStatus.Failure, PublishStatus.Timeout]) + {/if} + +{:else if isFailure && failure} + + + Failed to send! + +{/if} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 71103bc6..b966dc7b 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -24,7 +24,6 @@ initStorage, repository, pubkey, - publishStatusData, plaintext, freshness, storageAdapters, @@ -106,7 +105,6 @@ events: storageAdapters.fromRepository(repository, {throttle: 300, migrate: migrateEvents}), relays: {keyPath: "url", store: throttled(1000, relays)}, handles: {keyPath: "nip05", store: throttled(1000, handles)}, - publishStatus: storageAdapters.fromObjectStore(publishStatusData), freshness: storageAdapters.fromObjectStore(freshness, { throttle: 1000, migrate: migrateFreshness, diff --git a/src/routes/spaces/[nrelay]/[[room]]/+page.svelte b/src/routes/spaces/[nrelay]/[[room]]/+page.svelte index 56a5b634..f0c77c0c 100644 --- a/src/routes/spaces/[nrelay]/[[room]]/+page.svelte +++ b/src/routes/spaces/[nrelay]/[[room]]/+page.svelte @@ -9,10 +9,12 @@