diff options
| author | Adam Soltys <[email protected]> | 2026-03-05 22:10:50 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-03-05 22:32:43 -0800 |
| commit | 653224387d8c09e461aabe632dbad6d59caf8f05 (patch) | |
| tree | 4bc940709f10550a86fe172579b21c0ab4a2c240 /src/routes | |
| parent | 796119569ae96ff0afd5cc4d5472175e271e9c8d (diff) | |
| download | coinos-ui-653224387d8c09e461aabe632dbad6d59caf8f05.tar.gz coinos-ui-653224387d8c09e461aabe632dbad6d59caf8f05.zip | |
Add MLS messaging with marmot-ts, NIP-17 fallback
Integrate MLS (Messaging Layer Security) via marmot-ts for encrypted
group messaging. Falls back to NIP-17 when the recipient doesn't have
an MLS key package. Includes optimistic UI for sent messages, local
caching of decrypted rumours, dynamic group subscriptions, and
self-echo filtering. Fix SSR crash in nostr settings page.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/(app)/messages/+page.svelte | 2 | ||||
| -rw-r--r-- | src/routes/(app)/messages/[pubkey]/+page.svelte | 25 | ||||
| -rw-r--r-- | src/routes/(app)/settings/nostr/+page.svelte | 11 |
3 files changed, 31 insertions, 7 deletions
diff --git a/src/routes/(app)/messages/+page.svelte b/src/routes/(app)/messages/+page.svelte index 6c97c27c..2c3b1eb1 100644 --- a/src/routes/(app)/messages/+page.svelte +++ b/src/routes/(app)/messages/+page.svelte @@ -8,7 +8,7 @@ getMessageRumours, subscribeToMessages, cacheRumour, getCachedChatList, setCachedChatList, getCachedUserInfo, setCachedUserInfo, - } from "$lib/nip17"; + } from "$lib/messaging"; import { pTagKeys } from "$lib/nostr"; import { t } from "$lib/translations"; diff --git a/src/routes/(app)/messages/[pubkey]/+page.svelte b/src/routes/(app)/messages/[pubkey]/+page.svelte index c10798b0..8a478c98 100644 --- a/src/routes/(app)/messages/[pubkey]/+page.svelte +++ b/src/routes/(app)/messages/[pubkey]/+page.svelte @@ -6,7 +6,7 @@ import { isValid } from "nostr-tools/nip05"; import { getNostrUserInfo } from "$lib/nip01"; - import * as libnip17 from "$lib/nip17"; + import * as libnip17 from "$lib/messaging"; import { pTagKeys } from "$lib/nostr"; import { t } from "$lib/translations"; import { theme } from "$lib/store"; @@ -149,9 +149,30 @@ ta.style.height = "auto"; ta.focus(); } + + // Optimistic UI: show message immediately + const optimistic = { + id: crypto.randomUUID(), + kind: 14, + created_at: Math.floor(Date.now() / 1000), + pubkey: user.pubkey, + content: message, + tags: [["p", pubkey]], + }; + allRumours = [...allRumours, optimistic]; + const dayKey = Math.floor(optimistic.created_at / 86400); + const existing = messageRumours.get(dayKey); + if (existing) { + messageRumours = new Map(messageRumours).set(dayKey, [...existing, optimistic]); + } else { + messageRumours = new Map(messageRumours).set(dayKey, [optimistic]); + } + dates = Array.from(messageRumours.keys()).sort((a: number, b: number) => a - b); + await tick(); + scrollChat(); + try { await libnip17.send(message, user, selectedChat); - updateEvents(); } catch (e: any) { console.error("Failed to send message:", e); sendError = $t("dm.sendFailed"); diff --git a/src/routes/(app)/settings/nostr/+page.svelte b/src/routes/(app)/settings/nostr/+page.svelte index 3a27bc88..24fda6fb 100644 --- a/src/routes/(app)/settings/nostr/+page.svelte +++ b/src/routes/(app)/settings/nostr/+page.svelte @@ -51,13 +51,16 @@ ($save as any).click(); }; + import { onMount } from "svelte"; import { PUBLIC_DM_RELAYS } from "$env/static/public"; const DM_RELAYS_LIST = PUBLIC_DM_RELAYS.split(","); const pool = new SimplePool(); - (() => getPreferredRelays(data.user.pubkey).then((relays) => { - const relayEntry = document.getElementById("dmRelays") as HTMLTextAreaElement | null; - if (relayEntry) relayEntry.value = relays.join("\n"); - }))(); + onMount(() => { + getPreferredRelays(data.user.pubkey).then((relays) => { + const relayEntry = document.getElementById("dmRelays") as HTMLTextAreaElement | null; + if (relayEntry) relayEntry.value = relays.join("\n"); + }); + }); </script> <input type="hidden" name="challenge" value={challenge} /> |
