From d00bc64ffd4a37fecc06fe4d62e670f1f8513023 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Thu, 17 Oct 2024 11:27:17 -0700 Subject: [PATCH] Add chat undo --- src/app/commands.ts | 22 ++-- src/app/components/ChatMessage.svelte | 138 +++++++++++++------------- src/app/components/ThunkStatus.svelte | 20 ++-- src/lib/transition.ts | 1 - src/routes/home/[chat]/+page.svelte | 13 ++- 5 files changed, 102 insertions(+), 92 deletions(-) diff --git a/src/app/commands.ts b/src/app/commands.ts index 33d0660..f521bf6 100644 --- a/src/app/commands.ts +++ b/src/app/commands.ts @@ -27,6 +27,7 @@ import { signer, repository, publishThunk, + mergeThunks, loadProfile, loadInboxRelaySelections, profilesByPubkey, @@ -253,21 +254,24 @@ export const attemptRelayAccess = async (url: string, claim = "") => export const sendWrapped = async ({ template, pubkeys, + delay, }: { template: EventTemplate pubkeys: string[] + delay?: number }) => { const nip59 = Nip59.fromSigner(signer.get()!) - await Promise.all( - uniq(pubkeys).map(async recipient => { - const thunk = publishThunk({ - event: await nip59.wrap(recipient, stamp(template)), - relays: ctx.app.router.PublishMessage(recipient).getUrls(), - }) - - await thunk.result - }), + return mergeThunks( + await Promise.all( + uniq(pubkeys).map(async recipient => + publishThunk({ + event: await nip59.wrap(recipient, stamp(template)), + relays: ctx.app.router.PublishMessage(recipient).getUrls(), + delay, + }) + ), + ) ) } diff --git a/src/app/components/ChatMessage.svelte b/src/app/components/ChatMessage.svelte index b2b1bd5..77ac1a6 100644 --- a/src/app/components/ChatMessage.svelte +++ b/src/app/components/ChatMessage.svelte @@ -10,15 +10,16 @@ formatTimestampAsTime, pubkey, } from "@welshman/app" + import type {MergedThunk} from "@welshman/app" import {REACTION, ZAP_RESPONSE, displayRelayUrl} from "@welshman/util" import {repository} from "@welshman/app" - import {slideAndFade} from "@lib/transition" import Icon from "@lib/components/Icon.svelte" import Tippy from "@lib/components/Tippy.svelte" import Delay from "@lib/components/Delay.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 ProfileDetail from "@app/components/ProfileDetail.svelte" import ChatMessageMenu from "@app/components/ChatMessageMenu.svelte" import {colors, displayReaction} from "@app/state" @@ -26,6 +27,7 @@ import {makeDelete, makeReaction, sendWrapped} from "@app/commands" export let event: TrustedEvent + export let thunk: MergedThunk export let pubkeys: string[] export let showPubkey = false @@ -56,77 +58,77 @@ let popoverIsVisible = false - -
- - - -
-
-
+
+ + + +
+
+
+ {#if showPubkey} + + {/if} +
{#if showPubkey} - - {/if} -
- {#if showPubkey} -
- - {formatTimestampAsTime(event.created_at)} -
- {/if} -
- +
+ + {formatTimestampAsTime(event.created_at)}
+ {/if} +
+ + {#if thunk} + + {/if}
- {#if $reactions.length > 0 || $zaps.length > 0} -
- {#each groupBy( e => e.content, uniqBy(e => e.pubkey + e.content, $reactions), ).entries() as [content, events]} - {@const isOwn = events.some(e => e.pubkey === $pubkey)} - {@const onClick = () => onReactionClick(content, events)} - - {/each} -
- {/if}
+ {#if $reactions.length > 0 || $zaps.length > 0} +
+ {#each groupBy( e => e.content, uniqBy(e => e.pubkey + e.content, $reactions), ).entries() as [content, events]} + {@const isOwn = events.some(e => e.pubkey === $pubkey)} + {@const onClick = () => onReactionClick(content, events)} + + {/each} +
+ {/if}
- +
diff --git a/src/app/components/ThunkStatus.svelte b/src/app/components/ThunkStatus.svelte index a01f471..772fbf0 100644 --- a/src/app/components/ThunkStatus.svelte +++ b/src/app/components/ThunkStatus.svelte @@ -1,37 +1,37 @@ -{#if canUndo || isPending} - +{#if canCancel || isPending} + Sending... - {#if canUndo} - + {#if canCancel} + {/if} {:else if isFailure && failure} {@const [url, {message}] = failure} Failed to send! diff --git a/src/lib/transition.ts b/src/lib/transition.ts index da14500..afe0c76 100644 --- a/src/lib/transition.ts +++ b/src/lib/transition.ts @@ -13,7 +13,6 @@ export function slideAndFade( node: any, {delay = 0, duration = 400, easing = cubicOut, axis = "y"} = {}, ) { - console.log('slideAndFade') const style = getComputedStyle(node) const primary_property = axis === "y" ? "height" : "width" const primary_property_value = parseFloat(style[primary_property]) diff --git a/src/routes/home/[chat]/+page.svelte b/src/routes/home/[chat]/+page.svelte index d7734d6..ccf7bb8 100644 --- a/src/routes/home/[chat]/+page.svelte +++ b/src/routes/home/[chat]/+page.svelte @@ -10,8 +10,8 @@