diff --git a/src/commons.ts b/src/commons.ts index 14125c5..b8ae0fa 100644 --- a/src/commons.ts +++ b/src/commons.ts @@ -79,11 +79,6 @@ export function getReceivers(tags: string[][]) { return p; } -export function getChatId(pubkey: string, tags: string[][]) { - const id = [pubkey, tags.map((tag) => tag[0] === "p" && tag[1])].join("-"); - return id; -} - export function groupEventByDate(events: NostrEvent[]) { const groups = Object.groupBy(events, (event) => { return dayjs.unix(event.created_at).startOf("day").format("MMM DD, YYYY"); diff --git a/src/components/user/avatar.tsx b/src/components/user/avatar.tsx index 6cf9d62..8b7ad5b 100644 --- a/src/components/user/avatar.tsx +++ b/src/components/user/avatar.tsx @@ -26,7 +26,7 @@ export function UserAvatar({ className }: { className?: string }) { <> {user.profile?.picture ? ( { - if (!prevEvents) return prevEvents; + if (!prevEvents) return [event]; return [event, ...prevEvents]; }, ); diff --git a/src/routes/$account.chats.lazy.tsx b/src/routes/$account.chats.lazy.tsx index 3e4bb86..8baf4ae 100644 --- a/src/routes/$account.chats.lazy.tsx +++ b/src/routes/$account.chats.lazy.tsx @@ -19,8 +19,9 @@ import { Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/api/menu"; import { readText } from "@tauri-apps/plugin-clipboard-manager"; import { message } from "@tauri-apps/plugin-dialog"; import { open } from "@tauri-apps/plugin-shell"; -import type { NostrEvent } from "nostr-tools"; -import { useCallback, useEffect, useState, useTransition } from "react"; +import { type NostrEvent, nip19 } from "nostr-tools"; +import { useCallback, useEffect, useRef, useState, useTransition } from "react"; +import { Virtualizer } from "virtua"; type EventPayload = { event: string; @@ -273,6 +274,7 @@ function Compose() { }); const navigate = Route.useNavigate(); + const scrollRef = useRef(null); const pasteFromClipboard = async () => { const val = await readText(); @@ -283,13 +285,33 @@ function Compose() { startTransition(async () => { if (!newMessage.length) return; if (!target.length) return; + if (!target.startsWith("npub1")) { + await message("You must enter the public key as npub", { + title: "Send Message", + kind: "error", + }); + return; + } + + const decoded = nip19.decode(target); + let id: string; + + if (decoded.type !== "npub") { + await message("You must enter the public key as npub", { + title: "Send Message", + kind: "error", + }); + return; + } else { + id = decoded.data; + } // Connect to user's inbox relays const connect = await commands.connectInboxRelays(target, false); // Send message if (connect.status === "ok") { - const res = await commands.sendMessage(target, newMessage); + const res = await commands.sendMessage(id, newMessage); if (res.status === "ok") { setTarget(""); @@ -298,7 +320,7 @@ function Compose() { navigate({ to: "/$account/chats/$id", - params: { account, id: target }, + params: { account, id }, }); } else { await message(res.error, { title: "Send Message", kind: "error" }); @@ -343,7 +365,7 @@ function Compose() { placeholder="npub1..." value={target} onChange={(e) => setTarget(e.target.value)} - disabled={isPending || isLoading} + disabled={isPending} className="w-full pr-14 h-9 bg-transparent focus:outline-none placeholder:text-neutral-400 dark:placeholder:text-neutral-600" /> - )) - )} + + + {isLoading ? ( +
+ +
+ ) : !contacts?.length ? ( +
+

Contact is empty.

+
+ ) : ( + contacts?.map((contact) => ( + + )) + )} +