From 63af9b77017b2c370153e4c512039f8a659654a1 Mon Sep 17 00:00:00 2001 From: Ticruz Date: Tue, 10 Dec 2024 16:39:34 +0100 Subject: [PATCH 1/2] - fix Chat send is slow #499 - add cancelable button to message - show message status --- src/app/views/ChannelsDetail.svelte | 10 ++- src/engine/commands.ts | 6 +- src/partials/Channel.svelte | 107 +++++----------------------- src/partials/Message.svelte | 87 ++++++++++++++++++++++ 4 files changed, 112 insertions(+), 98 deletions(-) create mode 100644 src/partials/Message.svelte diff --git a/src/app/views/ChannelsDetail.svelte b/src/app/views/ChannelsDetail.svelte index a40892631..1e9565b6b 100644 --- a/src/app/views/ChannelsDetail.svelte +++ b/src/app/views/ChannelsDetail.svelte @@ -10,7 +10,7 @@ import PersonCircles from "src/app/shared/PersonCircles.svelte" import PersonAbout from "src/app/shared/PersonAbout.svelte" import {router} from "src/app/util/router" - import {sendMessage, markChannelRead, getChannelIdFromEvent, listenForMessages} from "src/engine" + import {markChannelRead, getChannelIdFromEvent, listenForMessages} from "src/engine" import Popover from "src/partials/Popover.svelte" export let pubkeys @@ -30,10 +30,6 @@ const showPerson = pubkey => router.at("people").of(pubkey).open() - const send = async content => { - await sendMessage(channelId, content) - } - onMount(() => { isAccepted = $messages.some(m => m.pubkey === $session.pubkey) markChannelRead(channelId) @@ -50,9 +46,11 @@ }) document.title = `Direct Messages` + + $: console.log("messages", $messages) - +
diff --git a/src/engine/commands.ts b/src/engine/commands.ts index 3a710b6f0..6b31b745a 100644 --- a/src/engine/commands.ts +++ b/src/engine/commands.ts @@ -408,7 +408,7 @@ export const markAsSeen = async (kind: number, eventsByKey: Record { +export const sendMessage = async (channelId: string, content: string, delay: number) => { const recipients = channelId.split(",") const template = { content, @@ -421,10 +421,12 @@ export const sendMessage = async (channelId: string, content: string) => { const helper = Nip59.fromSigner(signer.get()) const rumor = await helper.wrap(recipient, template) - await publish({ + repository.publish(rumor) + publish({ event: rumor.wrap, relays: ctx.app.router.PubkeyInbox(recipient).getUrls(), forcePlatform: false, + delay, }) } } diff --git a/src/partials/Channel.svelte b/src/partials/Channel.svelte index da90e2c4f..9c4f9a0a7 100644 --- a/src/partials/Channel.svelte +++ b/src/partials/Channel.svelte @@ -1,36 +1,27 @@ + +
+
+ {#if message.showProfile && message.pubkey !== $session.pubkey} + + {/if} +
+ {#await getContent(message)} + + {:then content} + + {/await} +
+ + {#if thunk} + {#await thunk.result} + + Sending... + {#if message.created_at > $timestamp1 - $userSettings.send_delay / 1000} + + {/if} + {:then} + {formatTimestamp(message.created_at)} + {/await} + {:else} + {formatTimestamp(message.created_at)} + {/if} + {#if message.kind === 4} + + +

+ This message was sent using nostr's legacy DMs, which have a number of shortcomings. + Read more here. +

+
+ {:else} + + +
+

+ This message was sent using nostr's new group chat specification, which solves several + problems with legacy DMs. Read more here. +

+ {#if message.pubkey === $session.pubkey} +

+ Note that these messages are not yet universally supported. Make sure the person + you're chatting with is using a compatible nostr client. +

+ {/if} +
+
+ {/if} +
+
+
From 0ee54cc1342c138262639d3698881e76d08e6f54 Mon Sep 17 00:00:00 2001 From: Ticruz Date: Tue, 10 Dec 2024 17:59:42 +0100 Subject: [PATCH 2/2] use circle-notch as loading icon --- src/partials/Channel.svelte | 2 +- src/partials/Message.svelte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/partials/Channel.svelte b/src/partials/Channel.svelte index 9c4f9a0a7..35ee1b5f1 100644 --- a/src/partials/Channel.svelte +++ b/src/partials/Channel.svelte @@ -192,7 +192,7 @@ class="flex cursor-pointer flex-col justify-center gap-2 p-3 py-6 text-neutral-100 transition-all hover:bg-accent hover:text-white"> {#if sending} - + {:else} {/if} diff --git a/src/partials/Message.svelte b/src/partials/Message.svelte index 621d18df6..25c68331c 100644 --- a/src/partials/Message.svelte +++ b/src/partials/Message.svelte @@ -39,7 +39,7 @@ class:text-neutral-100={message.pubkey !== $session.pubkey}> {#if thunk} {#await thunk.result} - + Sending... {#if message.created_at > $timestamp1 - $userSettings.send_delay / 1000}