mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-11 11:27:03 +00:00
Move nip29 check
This commit is contained in:
@@ -54,7 +54,7 @@ import {
|
|||||||
clearStorage,
|
clearStorage,
|
||||||
dropSession,
|
dropSession,
|
||||||
} from "@welshman/app"
|
} from "@welshman/app"
|
||||||
import type {Relay, Thunk} from "@welshman/app"
|
import type {Thunk} from "@welshman/app"
|
||||||
import {
|
import {
|
||||||
tagRoom,
|
tagRoom,
|
||||||
userMembership,
|
userMembership,
|
||||||
@@ -209,7 +209,6 @@ export const broadcastUserData = async (relays: string[]) => {
|
|||||||
// NIP 29 stuff
|
// NIP 29 stuff
|
||||||
|
|
||||||
export const nip29 = {
|
export const nip29 = {
|
||||||
isSupported: (relay?: Relay) => relay?.profile?.supported_nips?.map(String)?.includes("29"),
|
|
||||||
createRoom: (url: string, room: string) => {
|
createRoom: (url: string, room: string) => {
|
||||||
const event = createEvent(GROUP_CREATE, {tags: [tagRoom(room, url)]})
|
const event = createEvent(GROUP_CREATE, {tags: [tagRoom(room, url)]})
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
||||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||||
|
import {hasNip29} from "@app/state"
|
||||||
import {addRoomMembership, nip29, getThunkError} from "@app/commands"
|
import {addRoomMembership, nip29, getThunkError} from "@app/commands"
|
||||||
import {makeSpacePath} from "@app/routes"
|
import {makeSpacePath} from "@app/routes"
|
||||||
import {pushToast} from "@app/toast"
|
import {pushToast} from "@app/toast"
|
||||||
@@ -21,7 +22,7 @@
|
|||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
const tryCreate = async () => {
|
const tryCreate = async () => {
|
||||||
if (nip29.isSupported($relay)) {
|
if (hasNip29($relay)) {
|
||||||
const createMessage = await getThunkError(nip29.createRoom(url, room))
|
const createMessage = await getThunkError(nip29.createRoom(url, room))
|
||||||
|
|
||||||
if (createMessage && !createMessage.match(/^duplicate:|already a member/)) {
|
if (createMessage && !createMessage.match(/^duplicate:|already a member/)) {
|
||||||
|
|||||||
@@ -32,9 +32,9 @@
|
|||||||
|
|
||||||
// Delay updating isPending so users can see that the message is sent
|
// 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(() => {
|
setTimeout(() => {
|
||||||
isPending = false
|
isPending = false
|
||||||
}, 2000)
|
}, 2000)
|
||||||
|
|||||||
@@ -459,10 +459,13 @@ export const messages = derived(
|
|||||||
$events => $events.map(adaptLegacyMessage),
|
$events => $events.map(adaptLegacyMessage),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Group Meta
|
// Nip29
|
||||||
|
|
||||||
export const groupMeta = deriveEvents(repository, {filters: [{kinds: [GROUP_META]}]})
|
export const groupMeta = deriveEvents(repository, {filters: [{kinds: [GROUP_META]}]})
|
||||||
|
|
||||||
|
export const hasNip29 = (relay?: Relay) =>
|
||||||
|
relay?.profile?.supported_nips?.map(String)?.includes("29")
|
||||||
|
|
||||||
// Channels
|
// Channels
|
||||||
|
|
||||||
export type ChannelMeta = {
|
export type ChannelMeta = {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
import {setChecked} from "@app/notifications"
|
import {setChecked} from "@app/notifications"
|
||||||
import {nip29, addRoomMembership, removeRoomMembership, getThunkError} from "@app/commands"
|
import {nip29, addRoomMembership, removeRoomMembership, getThunkError} from "@app/commands"
|
||||||
import {listenForChannelMessages} from "@app/requests"
|
import {listenForChannelMessages} from "@app/requests"
|
||||||
import {PROTECTED} from "@app/state"
|
import {PROTECTED, hasNip29} from "@app/state"
|
||||||
import {popKey} from "@app/implicit"
|
import {popKey} from "@app/implicit"
|
||||||
import {pushToast} from "@app/toast"
|
import {pushToast} from "@app/toast"
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
const assertEvent = (e: any) => e as TrustedEvent
|
const assertEvent = (e: any) => e as TrustedEvent
|
||||||
|
|
||||||
const joinRoom = async () => {
|
const joinRoom = async () => {
|
||||||
if (nip29.isSupported($relay)) {
|
if (hasNip29($relay)) {
|
||||||
const message = await getThunkError(nip29.joinRoom(url, room))
|
const message = await getThunkError(nip29.joinRoom(url, room))
|
||||||
|
|
||||||
if (message && !message.includes("already")) {
|
if (message && !message.includes("already")) {
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const leaveRoom = () => {
|
const leaveRoom = () => {
|
||||||
if (nip29.isSupported($relay)) {
|
if (hasNip29($relay)) {
|
||||||
nip29.leaveRoom(url, room)
|
nip29.leaveRoom(url, room)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user