Create nip29 group when creating a room

This commit is contained in:
Jon Staab
2024-12-10 15:16:54 -08:00
parent 73c6b9656c
commit d8c3378e5c
4 changed files with 62 additions and 13 deletions
+24 -1
View File
@@ -10,6 +10,8 @@ import {
AUTH_JOIN,
GROUP_JOIN,
GROUP_LEAVE,
GROUP_CREATE,
GROUP_EDIT_META,
GROUPS,
COMMENT,
isSignedEvent,
@@ -53,7 +55,7 @@ import {
clearStorage,
dropSession,
} from "@welshman/app"
import type {Relay} from "@welshman/app"
import type {Relay, Thunk} from "@welshman/app"
import {
tagRoom,
userMembership,
@@ -122,6 +124,15 @@ export const subscribePersistent = (request: SubscribeRequestWithHandlers) => {
}
}
export const getThunkError = async (thunk: Thunk) => {
const result = await thunk.result
const [{status, message}] = Object.values(result) as any
if (status !== PublishStatus.Success) {
return message
}
}
// Log in
export const loginWithNip46 = async ({
@@ -224,6 +235,18 @@ export const broadcastUserData = async (relays: string[]) => {
export const nip29 = {
isSupported: (relay?: Relay) => relay?.profile?.supported_nips?.map(String)?.includes("29"),
createRoom: (url: string, room: string) => {
const event = createEvent(GROUP_CREATE, {tags: [tagRoom(room, url)]})
return publishThunk({event, relays: [url]})
},
editMeta: (url: string, room: string, meta: Record<string, string>) => {
const event = createEvent(GROUP_EDIT_META, {
tags: [tagRoom(room, url), ...Object.entries(meta)],
})
return publishThunk({event, relays: [url]})
},
joinRoom: (url: string, room: string) => {
const event = createEvent(GROUP_JOIN, {tags: [tagRoom(room, url)]})