feat: nip-28
This commit is contained in:
@ -20,6 +20,8 @@ import { Nip29ChatSystem } from "./nip29";
|
||||
import useModeration from "Hooks/useModeration";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { Nip24ChatSystem } from "./nip24";
|
||||
import { LoginSession } from "Login";
|
||||
import { Nip28ChatSystem } from "./nip28";
|
||||
|
||||
export enum ChatType {
|
||||
DirectMessage = 1,
|
||||
@ -60,7 +62,7 @@ export interface ChatSystem {
|
||||
/**
|
||||
* Create a request for this system to get updates
|
||||
*/
|
||||
subscription(id: string): RequestBuilder | undefined;
|
||||
subscription(session: LoginSession): RequestBuilder | undefined;
|
||||
onEvent(evs: readonly TaggedNostrEvent[]): Promise<void> | void;
|
||||
|
||||
listChats(pk: string): Array<Chat>;
|
||||
@ -69,6 +71,7 @@ export interface ChatSystem {
|
||||
export const Nip4Chats = new Nip4ChatSystem(Chats);
|
||||
export const Nip29Chats = new Nip29ChatSystem(Chats);
|
||||
export const Nip24Chats = new Nip24ChatSystem(GiftsCache);
|
||||
export const Nip28Chats = new Nip28ChatSystem(Chats);
|
||||
|
||||
/**
|
||||
* Extract the P tag of the event
|
||||
@ -143,17 +146,23 @@ export function createChatLink(type: ChatType, ...params: Array<string>) {
|
||||
),
|
||||
)}`;
|
||||
}
|
||||
case ChatType.PublicGroupChat: {
|
||||
return `/messages/${Nip28ChatSystem.chatId(params[0])}`;
|
||||
}
|
||||
}
|
||||
throw new Error("Unknown chat type");
|
||||
}
|
||||
|
||||
export function createEmptyChatObject(id: string) {
|
||||
if (id.startsWith("chat4")) {
|
||||
if (id.startsWith("chat41")) {
|
||||
return Nip4ChatSystem.createChatObj(id, []);
|
||||
}
|
||||
if (id.startsWith("chat24")) {
|
||||
if (id.startsWith("chat241")) {
|
||||
return Nip24ChatSystem.createChatObj(id, []);
|
||||
}
|
||||
if (id.startsWith("chat281")) {
|
||||
return Nip28ChatSystem.createChatObj(id, []);
|
||||
}
|
||||
throw new Error("Cant create new empty chat, unknown id");
|
||||
}
|
||||
|
||||
@ -180,10 +189,18 @@ export function useNip24Chat() {
|
||||
);
|
||||
}
|
||||
|
||||
export function useNip28Chat() {
|
||||
return useSyncExternalStore(
|
||||
c => Nip28Chats.hook(c),
|
||||
() => Nip28Chats.snapshot(),
|
||||
);
|
||||
}
|
||||
|
||||
export function useChatSystem() {
|
||||
const nip4 = useNip4Chat();
|
||||
//const nip24 = useNip24Chat();
|
||||
const nip28 = useNip28Chat();
|
||||
const { muted, blocked } = useModeration();
|
||||
|
||||
return [...nip4].filter(a => !(muted.includes(a.id) || blocked.includes(a.id)));
|
||||
return [...nip4, ...nip28].filter(a => !(muted.includes(a.id) || blocked.includes(a.id)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user