From 85584e7766b830dceb8eaa907adf1c6a5bda9cc5 Mon Sep 17 00:00:00 2001 From: Ticruz Date: Wed, 13 Nov 2024 14:28:48 +0100 Subject: [PATCH 1/5] remove legacy message --- src/app/views/ChannelsDetail.svelte | 81 +++++++++++++++++------------ src/engine/commands.ts | 19 ------- src/partials/Channel.svelte | 58 +++------------------ 3 files changed, 54 insertions(+), 104 deletions(-) diff --git a/src/app/views/ChannelsDetail.svelte b/src/app/views/ChannelsDetail.svelte index a1fafad71..6710eec49 100644 --- a/src/app/views/ChannelsDetail.svelte +++ b/src/app/views/ChannelsDetail.svelte @@ -1,23 +1,24 @@ + + -
-
- - -
-
-
- {#each pubkeys as pubkey, i (pubkey)} - {#if i > 0}•{/if} - showPerson(pubkey)}> - {displayProfileByPubkey(pubkey)} - - {/each} +
+
+
+ + +
+
+
+ {#each pubkeys as pubkey, i (pubkey)} + {#if i > 0}•{/if} + showPerson(pubkey)}> + {displayProfileByPubkey(pubkey)} + + {/each} +
+ {#if pubkeys.length === 1} + + {/if}
- {#if pubkeys.length === 1} - - {/if}
+ {#if $pubkeysWithoutInbox.length > 0} +
+
+ {$pubkeysWithoutInbox.length} inbox is not configured +
+
+ + + {$pubkeysWithoutInbox.length} + +
+
+ {/if}
diff --git a/src/engine/commands.ts b/src/engine/commands.ts index 5dbbd3ceb..3c12e0c96 100644 --- a/src/engine/commands.ts +++ b/src/engine/commands.ts @@ -409,25 +409,6 @@ export const markAsSeen = async (kind: number, eventsByKey: Record { - const $pubkey = pubkey.get() - const recipients = without([$pubkey], channelId.split(",")) - - if (recipients.length > 1) { - throw new Error("Attempted to send legacy message to more than 1 recipient") - } - - const recipient = recipients[0] || $pubkey - - return createAndPublish({ - kind: 4, - tags: [tagPubkey(recipient), ...getClientTags()], - content: await signer.get().nip04.encrypt(recipient, content), - relays: ctx.app.router.PubkeyInbox(recipient).getUrls(), - forcePlatform: false, - }) -} - export const sendMessage = async (channelId: string, content: string) => { const recipients = channelId.split(",") const template = { diff --git a/src/partials/Channel.svelte b/src/partials/Channel.svelte index 59ebe2038..1011e877a 100644 --- a/src/partials/Channel.svelte +++ b/src/partials/Channel.svelte @@ -3,7 +3,7 @@ import {onMount} from "svelte" import {pluralize} from "hurdak" import {derived} from "svelte/store" - import {sleep, remove} from "@welshman/lib" + import {sleep} from "@welshman/lib" import type {TrustedEvent} from "@welshman/util" import {Nip46Signer} from "@welshman/signer" import { @@ -18,7 +18,6 @@ import Spinner from "src/partials/Spinner.svelte" import Anchor from "src/partials/Anchor.svelte" import Popover from "src/partials/Popover.svelte" - import Toggle from "src/partials/Toggle.svelte" import FlexColumn from "src/partials/FlexColumn.svelte" import Modal from "src/partials/Modal.svelte" import Subheading from "src/partials/Subheading.svelte" @@ -30,14 +29,13 @@ import Compose from "src/app/shared/Compose.svelte" export let pubkeys - export let sendMessage + export let sendMessage: (content: string) => Promise export let initialMessage = "" export let messages: TrustedEvent[] let editor: Editor const loading = sleep(5_000) - const toggleScale = 0.7 const startScroller = () => { scroller?.stop() @@ -65,14 +63,10 @@ let showNewMessages = false let groupedMessages = [] - const isGroupMessage = pubkeys.length > 2 - const recipients = remove($session?.pubkey, pubkeys) const pubkeysWithoutInbox = derived(inboxRelaySelectionsByPubkey, $inboxRelayPoliciesByPubkey => pubkeys.filter(pubkey => !$inboxRelayPoliciesByPubkey.has(pubkey)), ) - let useNip17 = isGroupMessage || ($hasNip44 && $pubkeysWithoutInbox.length === 0) - onMount(() => { editor = new Editor( getEditorOptions({ @@ -119,7 +113,7 @@ } const sendOrConfirm = () => { - if (isGroupMessage && $pubkeysWithoutInbox.length > 0) { + if ($pubkeysWithoutInbox.length > 0) { openConfirm() } else { send() @@ -132,7 +126,7 @@ if (content) { sending = true - await sendMessage(content, useNip17) + await sendMessage(content) sending = false stickToBottom() @@ -141,7 +135,6 @@ } $: userHasInbox = !$pubkeysWithoutInbox.includes($session?.pubkey) - $: hasSingleRecipientWithInbox = !isGroupMessage && !$pubkeysWithoutInbox.includes(recipients[0]) // Group messages so we're only showing the person once per chunk $: { @@ -247,7 +240,7 @@
End of message history
{/await}
- {#if $hasNip44 || !isGroupMessage} + {#if $hasNip44}
- {#if $hasNip44 && hasSingleRecipientWithInbox} -
- {#if userHasInbox} - - {:else} - -
- -
- - - You must have at least one inbox relay to send messages using nip-17. Click here to set - up your inbox relays. - -
- {/if} - - Send messages using - - NIP 17 -
-

- When enabled, Coracle will use nostr's new group chat specification, which solves - several problems with legacy DMs. Read more here. -

-

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

-
-
-
-
- {/if}
{:else} @@ -332,8 +287,7 @@

{displayList($pubkeysWithoutInbox.map(displayProfileByPubkey))} {pluralize($pubkeysWithoutInbox.length, "does not have", "do not have")} - inbox relays, which means they likely either don't want to receive DMs, or are using a client - that does not support nostr group chats. + inbox relays, which means they likely don't want to receive DMs.

{:else if !userHasInbox}

From e4486a1c934adb887a1282ba801b070c558fd576 Mon Sep 17 00:00:00 2001 From: Ticruz Date: Fri, 15 Nov 2024 12:45:49 +0100 Subject: [PATCH 2/5] using Popover for missing inbox warning --- src/app/views/ChannelsDetail.svelte | 25 +++++++++++++++---------- src/engine/commands.ts | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/app/views/ChannelsDetail.svelte b/src/app/views/ChannelsDetail.svelte index 6710eec49..dc59b5743 100644 --- a/src/app/views/ChannelsDetail.svelte +++ b/src/app/views/ChannelsDetail.svelte @@ -19,6 +19,7 @@ import PersonAbout from "src/app/shared/PersonAbout.svelte" import {router} from "src/app/util/router" import {sendMessage, markChannelRead, getChannelIdFromEvent, listenForMessages} from "src/engine" + import Popover from "src/partials/Popover.svelte" export let pubkeys export let channelId @@ -83,16 +84,20 @@

{#if $pubkeysWithoutInbox.length > 0} -
-
- {$pubkeysWithoutInbox.length} inbox is not configured -
-
- - - {$pubkeysWithoutInbox.length} - -
+
+ +
+ + + {$pubkeysWithoutInbox.length} + +
+
+ {$pubkeysWithoutInbox.length} inbox is not configured +
+
{/if}
diff --git a/src/engine/commands.ts b/src/engine/commands.ts index 3c12e0c96..b818e58f9 100644 --- a/src/engine/commands.ts +++ b/src/engine/commands.ts @@ -57,7 +57,7 @@ import { } from "@welshman/util" import crypto from "crypto" import {Fetch, seconds, sleep, tryFunc} from "hurdak" -import {assoc, flatten, identity, omit, prop, reject, uniq, without} from "ramda" +import {assoc, flatten, identity, omit, prop, reject, uniq} from "ramda" import { addClientTags, anonymous, From e0ef256d9adb596d6125b62d44c7b554c2739a36 Mon Sep 17 00:00:00 2001 From: Ticruz Date: Fri, 15 Nov 2024 12:46:54 +0100 Subject: [PATCH 3/5] remove margin below Channel Compose --- src/partials/Channel.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/partials/Channel.svelte b/src/partials/Channel.svelte index 1011e877a..048b778f9 100644 --- a/src/partials/Channel.svelte +++ b/src/partials/Channel.svelte @@ -245,7 +245,7 @@ + class="h-20 w-full resize-none bg-transparent p-2 text-neutral-100 outline-0 placeholder:text-neutral-100" />