Move nip29 check

This commit is contained in:
Jon Staab
2024-12-12 14:49:30 -08:00
parent 9d6531c0d5
commit 9f3bfd5ac0
5 changed files with 12 additions and 9 deletions

View File

@@ -54,7 +54,7 @@ import {
clearStorage,
dropSession,
} from "@welshman/app"
import type {Relay, Thunk} from "@welshman/app"
import type {Thunk} from "@welshman/app"
import {
tagRoom,
userMembership,
@@ -209,7 +209,6 @@ export const broadcastUserData = async (relays: string[]) => {
// NIP 29 stuff
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)]})

View File

@@ -9,6 +9,7 @@
import Icon from "@lib/components/Icon.svelte"
import ModalHeader from "@lib/components/ModalHeader.svelte"
import ModalFooter from "@lib/components/ModalFooter.svelte"
import {hasNip29} from "@app/state"
import {addRoomMembership, nip29, getThunkError} from "@app/commands"
import {makeSpacePath} from "@app/routes"
import {pushToast} from "@app/toast"
@@ -21,7 +22,7 @@
const back = () => history.back()
const tryCreate = async () => {
if (nip29.isSupported($relay)) {
if (hasNip29($relay)) {
const createMessage = await getThunkError(nip29.createRoom(url, room))
if (createMessage && !createMessage.match(/^duplicate:|already a member/)) {

View File

@@ -32,9 +32,9 @@
// Delay updating isPending so users can see that the message is sent
$: {
isPending = isPending || ps.some(s => s.status == Pending)
isPending = isPending || ps.some(s => s.status === Pending)
if (!ps.some(s => s.status == Pending)) {
if (!ps.some(s => s.status === Pending)) {
setTimeout(() => {
isPending = false
}, 2000)

View File

@@ -459,10 +459,13 @@ export const messages = derived(
$events => $events.map(adaptLegacyMessage),
)
// Group Meta
// Nip29
export const groupMeta = deriveEvents(repository, {filters: [{kinds: [GROUP_META]}]})
export const hasNip29 = (relay?: Relay) =>
relay?.profile?.supported_nips?.map(String)?.includes("29")
// Channels
export type ChannelMeta = {

View File

@@ -35,7 +35,7 @@
import {setChecked} from "@app/notifications"
import {nip29, addRoomMembership, removeRoomMembership, getThunkError} from "@app/commands"
import {listenForChannelMessages} from "@app/requests"
import {PROTECTED} from "@app/state"
import {PROTECTED, hasNip29} from "@app/state"
import {popKey} from "@app/implicit"
import {pushToast} from "@app/toast"
@@ -55,7 +55,7 @@
const assertEvent = (e: any) => e as TrustedEvent
const joinRoom = async () => {
if (nip29.isSupported($relay)) {
if (hasNip29($relay)) {
const message = await getThunkError(nip29.joinRoom(url, room))
if (message && !message.includes("already")) {
@@ -67,7 +67,7 @@
}
const leaveRoom = () => {
if (nip29.isSupported($relay)) {
if (hasNip29($relay)) {
nip29.leaveRoom(url, room)
}