diff --git a/packages/app/src/Pages/ProfilePage.tsx b/packages/app/src/Pages/ProfilePage.tsx index 3dfc7e54..15a050e8 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 f011d575..b3dae2cf 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));