mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 10:57:04 +00:00
Unnest nip29 commands
This commit is contained in:
@@ -144,29 +144,30 @@ export const broadcastUserData = async (relays: string[]) => {
|
||||
|
||||
// NIP 29 stuff
|
||||
|
||||
export const nip29 = {
|
||||
createRoom: (url: string, room: string) => {
|
||||
const event = createEvent(GROUP_CREATE, {tags: [tagRoom(room, url)]})
|
||||
export const 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]})
|
||||
}
|
||||
|
||||
return publishThunk({event, relays: [url]})
|
||||
},
|
||||
joinRoom: (url: string, room: string) => {
|
||||
const event = createEvent(GROUP_JOIN, {tags: [tagRoom(room, url)]})
|
||||
export const editRoom = (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]})
|
||||
},
|
||||
leaveRoom: (url: string, room: string) => {
|
||||
const event = createEvent(GROUP_LEAVE, {tags: [tagRoom(room, url)]})
|
||||
return publishThunk({event, relays: [url]})
|
||||
}
|
||||
|
||||
return publishThunk({event, relays: [url]})
|
||||
},
|
||||
export const joinRoom = (url: string, room: string) => {
|
||||
const event = createEvent(GROUP_JOIN, {tags: [tagRoom(room, url)]})
|
||||
|
||||
return publishThunk({event, relays: [url]})
|
||||
}
|
||||
|
||||
export const leaveRoom = (url: string, room: string) => {
|
||||
const event = createEvent(GROUP_LEAVE, {tags: [tagRoom(room, url)]})
|
||||
|
||||
return publishThunk({event, relays: [url]})
|
||||
}
|
||||
|
||||
// List updates
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
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 {hasNip29, loadChannel} from "@app/state"
|
||||
import {addRoomMembership, createRoom, editRoom, joinRoom, getThunkError} from "@app/commands"
|
||||
import {makeSpacePath} from "@app/routes"
|
||||
import {pushToast} from "@app/toast"
|
||||
|
||||
@@ -23,24 +23,26 @@
|
||||
const back = () => history.back()
|
||||
|
||||
const tryCreate = async () => {
|
||||
const createMessage = await getThunkError(nip29.createRoom(url, room))
|
||||
const createMessage = await getThunkError(createRoom(url, room))
|
||||
|
||||
if (createMessage && !createMessage.match(/^duplicate:|already a member/)) {
|
||||
return pushToast({theme: "error", message: createMessage})
|
||||
}
|
||||
|
||||
const editMessage = await getThunkError(nip29.editMeta(url, room, {name}))
|
||||
const editMessage = await getThunkError(editRoom(url, room, {name}))
|
||||
|
||||
if (editMessage) {
|
||||
return pushToast({theme: "error", message: editMessage})
|
||||
}
|
||||
|
||||
const joinMessage = await getThunkError(nip29.joinRoom(url, room))
|
||||
const joinMessage = await getThunkError(joinRoom(url, room))
|
||||
|
||||
if (joinMessage && !joinMessage.includes("already")) {
|
||||
return pushToast({theme: "error", message: joinMessage})
|
||||
}
|
||||
|
||||
await loadChannel(url, room)
|
||||
|
||||
addRoomMembership(url, room, name)
|
||||
goto(makeSpacePath(url, room))
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
MESSAGE,
|
||||
INBOX_RELAYS,
|
||||
DIRECT_MESSAGE,
|
||||
GROUP_META,
|
||||
MUTES,
|
||||
FOLLOWS,
|
||||
PROFILE,
|
||||
@@ -173,7 +174,11 @@
|
||||
limit: 10_000,
|
||||
repository,
|
||||
rankEvent: (e: TrustedEvent) => {
|
||||
if ([PROFILE, FOLLOWS, MUTES, RELAYS, BLOSSOM_SERVERS, INBOX_RELAYS].includes(e.kind)) {
|
||||
if (
|
||||
[PROFILE, FOLLOWS, MUTES, RELAYS, BLOSSOM_SERVERS, INBOX_RELAYS, GROUP_META].includes(
|
||||
e.kind,
|
||||
)
|
||||
) {
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
import {onMount} from "svelte"
|
||||
import {page} from "$app/stores"
|
||||
import {ago, WEEK} from "@welshman/lib"
|
||||
import {GROUP_META, EVENT_TIME, GROUPS, THREAD, COMMENT, MESSAGE} from "@welshman/util"
|
||||
import {request} from "@welshman/net"
|
||||
import {GROUP_META, EVENT_TIME, THREAD, COMMENT, MESSAGE} from "@welshman/util"
|
||||
import Page from "@lib/components/Page.svelte"
|
||||
import SecondaryNav from "@lib/components/SecondaryNav.svelte"
|
||||
import MenuSpace from "@app/components/MenuSpace.svelte"
|
||||
@@ -73,9 +72,6 @@
|
||||
],
|
||||
})
|
||||
|
||||
// Completely refresh our groups list and listen for new ones
|
||||
request({relays, filters: [{kinds: [GROUPS]}], signal: controller.signal})
|
||||
|
||||
return () => {
|
||||
controller.abort()
|
||||
}
|
||||
|
||||
@@ -29,13 +29,14 @@
|
||||
} from "@app/state"
|
||||
import {setChecked, checked} from "@app/notifications"
|
||||
import {
|
||||
nip29,
|
||||
joinRoom,
|
||||
leaveRoom,
|
||||
addRoomMembership,
|
||||
removeRoomMembership,
|
||||
prependParent,
|
||||
getThunkError,
|
||||
} from "@app/commands"
|
||||
import {PROTECTED, hasNip29} from "@app/state"
|
||||
import {PROTECTED} from "@app/state"
|
||||
import {makeFeed} from "@app/requests"
|
||||
import {popKey} from "@app/implicit"
|
||||
import {pushToast} from "@app/toast"
|
||||
@@ -45,29 +46,23 @@
|
||||
const lastChecked = $checked[$page.url.pathname]
|
||||
const url = decodeRelay($page.params.relay)
|
||||
const filter = {kinds: [MESSAGE], "#h": [room]}
|
||||
const relay = deriveRelay(url)
|
||||
|
||||
const joinRoom = async () => {
|
||||
if (hasNip29($relay)) {
|
||||
joiningRoom = true
|
||||
const join = async () => {
|
||||
joiningRoom = true
|
||||
|
||||
const message = await getThunkError(nip29.joinRoom(url, room))
|
||||
const message = await getThunkError(joinRoom(url, room))
|
||||
|
||||
joiningRoom = false
|
||||
joiningRoom = false
|
||||
|
||||
if (message && !message.includes("already")) {
|
||||
return pushToast({theme: "error", message})
|
||||
}
|
||||
if (message && !message.includes("already")) {
|
||||
return pushToast({theme: "error", message})
|
||||
}
|
||||
|
||||
addRoomMembership(url, room, displayChannel(url, room))
|
||||
}
|
||||
|
||||
const leaveRoom = () => {
|
||||
if (hasNip29($relay)) {
|
||||
nip29.leaveRoom(url, room)
|
||||
}
|
||||
|
||||
const leave = () => {
|
||||
leaveRoom(url, room)
|
||||
removeRoomMembership(url, room)
|
||||
}
|
||||
|
||||
@@ -252,12 +247,12 @@
|
||||
{#snippet action()}
|
||||
<div class="row-2">
|
||||
{#if $userRoomsByUrl.get(url)?.has(room)}
|
||||
<Button class="btn btn-neutral btn-sm" onclick={leaveRoom}>
|
||||
<Button class="btn btn-neutral btn-sm" onclick={leave}>
|
||||
<Icon icon="arrows-a-logout-2" />
|
||||
Leave Room
|
||||
</Button>
|
||||
{:else}
|
||||
<Button class="btn btn-neutral btn-sm" disabled={joiningRoom} onclick={joinRoom}>
|
||||
<Button class="btn btn-neutral btn-sm" disabled={joiningRoom} onclick={join}>
|
||||
{#if joiningRoom}
|
||||
<span class="loading loading-spinner loading-sm"></span>
|
||||
{:else}
|
||||
|
||||
Reference in New Issue
Block a user