From 2b1226ce75dd33f6b46488e376a899c3a261af12 Mon Sep 17 00:00:00 2001 From: Kieran Date: Fri, 22 Sep 2023 10:26:17 +0100 Subject: [PATCH] Fix dms link --- packages/app/src/Pages/ProfilePage.tsx | 2 +- packages/app/src/chat/nip4.ts | 28 ++++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/app/src/Pages/ProfilePage.tsx b/packages/app/src/Pages/ProfilePage.tsx index 3dfc7e548..15a050e88 100644 --- a/packages/app/src/Pages/ProfilePage.tsx +++ b/packages/app/src/Pages/ProfilePage.tsx @@ -473,7 +473,7 @@ export default function ProfilePage() { navigate( `/messages/${encodeTLVEntries("chat4" as NostrPrefix, { type: TLVEntryType.Author, - length: 64, + length: 32, value: id, })}`, ) diff --git a/packages/app/src/chat/nip4.ts b/packages/app/src/chat/nip4.ts index f011d5757..b3dae2cf9 100644 --- a/packages/app/src/chat/nip4.ts +++ b/packages/app/src/chat/nip4.ts @@ -8,6 +8,7 @@ import { TLVEntryType, encodeTLVEntries, TaggedNostrEvent, + decodeTLV, } from "@snort/system"; import { Chat, ChatSystem, ChatType, inChatWith, lastReadInChat } from "chat"; import { debug } from "debug"; @@ -59,26 +60,27 @@ export class Nip4ChatSystem extends ExternalStore> implements ChatSy {} as Record>, ); - return [...Object.entries(chats)].map(([k, v]) => Nip4ChatSystem.createChatObj(k, v)); + return [...Object.entries(chats)].map(([k, v]) => Nip4ChatSystem.createChatObj(encodeTLVEntries("chat4" as NostrPrefix, { + type: TLVEntryType.Author, + value: k, + length: 32, + }), v)); } static createChatObj(id: string, messages: Array) { const last = lastReadInChat(id); + const participants = decodeTLV(id) + .filter(v => v.type === TLVEntryType.Author) + .map(v => ({ + type: "pubkey", + id: v.value as string, + })); return { type: ChatType.DirectMessage, - id: encodeTLVEntries("chat4" as NostrPrefix, { - type: TLVEntryType.Author, - value: id, - length: 0, - }), + id, unread: messages.reduce((acc, v) => (v.created_at > last ? acc++ : acc), 0), lastMessage: messages.reduce((acc, v) => (v.created_at > acc ? v.created_at : acc), 0), - participants: [ - { - type: "pubkey", - id: id, - }, - ], + participants, messages: messages.map(m => ({ id: m.id, created_at: m.created_at, @@ -91,7 +93,7 @@ export class Nip4ChatSystem extends ExternalStore> implements ChatSy }, })), createMessage: async (msg, pub) => { - return [await pub.sendDm(msg, id)]; + return await Promise.all(participants.map(v => pub.sendDm(msg, v.id))); }, sendMessage: (ev, system: SystemInterface) => { ev.forEach(a => system.BroadcastEvent(a));