Fix dms link

This commit is contained in:
Kieran 2023-09-22 10:26:17 +01:00
parent eef4270f84
commit 2b1226ce75
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
2 changed files with 16 additions and 14 deletions

View File

@ -473,7 +473,7 @@ export default function ProfilePage() {
navigate( navigate(
`/messages/${encodeTLVEntries("chat4" as NostrPrefix, { `/messages/${encodeTLVEntries("chat4" as NostrPrefix, {
type: TLVEntryType.Author, type: TLVEntryType.Author,
length: 64, length: 32,
value: id, value: id,
})}`, })}`,
) )

View File

@ -8,6 +8,7 @@ import {
TLVEntryType, TLVEntryType,
encodeTLVEntries, encodeTLVEntries,
TaggedNostrEvent, TaggedNostrEvent,
decodeTLV,
} from "@snort/system"; } from "@snort/system";
import { Chat, ChatSystem, ChatType, inChatWith, lastReadInChat } from "chat"; import { Chat, ChatSystem, ChatType, inChatWith, lastReadInChat } from "chat";
import { debug } from "debug"; import { debug } from "debug";
@ -59,26 +60,27 @@ export class Nip4ChatSystem extends ExternalStore<Array<Chat>> implements ChatSy
{} as Record<string, Array<NostrEvent>>, {} as Record<string, Array<NostrEvent>>,
); );
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<NostrEvent>) { static createChatObj(id: string, messages: Array<NostrEvent>) {
const last = lastReadInChat(id); const last = lastReadInChat(id);
const participants = decodeTLV(id)
.filter(v => v.type === TLVEntryType.Author)
.map(v => ({
type: "pubkey",
id: v.value as string,
}));
return { return {
type: ChatType.DirectMessage, type: ChatType.DirectMessage,
id: encodeTLVEntries("chat4" as NostrPrefix, { id,
type: TLVEntryType.Author,
value: id,
length: 0,
}),
unread: messages.reduce((acc, v) => (v.created_at > last ? acc++ : acc), 0), 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), lastMessage: messages.reduce((acc, v) => (v.created_at > acc ? v.created_at : acc), 0),
participants: [ participants,
{
type: "pubkey",
id: id,
},
],
messages: messages.map(m => ({ messages: messages.map(m => ({
id: m.id, id: m.id,
created_at: m.created_at, created_at: m.created_at,
@ -91,7 +93,7 @@ export class Nip4ChatSystem extends ExternalStore<Array<Chat>> implements ChatSy
}, },
})), })),
createMessage: async (msg, pub) => { 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) => { sendMessage: (ev, system: SystemInterface) => {
ev.forEach(a => system.BroadcastEvent(a)); ev.forEach(a => system.BroadcastEvent(a));