mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-11 11:27:03 +00:00
Disable create room button if no permission
This commit is contained in:
committed by
Jon Staab
parent
5b22d6ac01
commit
a39a87ba6d
@@ -14,9 +14,10 @@
|
|||||||
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, loadChannel} from "@app/core/state"
|
import {deriveUserCanCreateRoom, hasNip29, loadChannel} from "@app/core/state"
|
||||||
import {makeSpacePath} from "@app/util/routes"
|
import {makeSpacePath} from "@app/util/routes"
|
||||||
import {pushToast} from "@app/util/toast"
|
import {pushToast} from "@app/util/toast"
|
||||||
|
import {get} from "svelte/store"
|
||||||
|
|
||||||
const {url} = $props()
|
const {url} = $props()
|
||||||
|
|
||||||
@@ -51,6 +52,8 @@
|
|||||||
goto(makeSpacePath(url, room.id))
|
goto(makeSpacePath(url, room.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const canCreateRoom = get<boolean>(deriveUserCanCreateRoom(url))
|
||||||
|
|
||||||
const create = async () => {
|
const create = async () => {
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
@@ -99,7 +102,10 @@
|
|||||||
<Icon icon={AltArrowLeft} />
|
<Icon icon={AltArrowLeft} />
|
||||||
Go back
|
Go back
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" class="btn btn-primary" disabled={!name || loading || !hasNip29($relay)}>
|
<Button
|
||||||
|
type="submit"
|
||||||
|
class="btn btn-primary"
|
||||||
|
disabled={!name || loading || !hasNip29($relay) || !canCreateRoom}>
|
||||||
<Spinner {loading}>Create Room</Spinner>
|
<Spinner {loading}>Create Room</Spinner>
|
||||||
<Icon icon={AltArrowRight} />
|
<Icon icon={AltArrowRight} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
groupBy,
|
groupBy,
|
||||||
always,
|
always,
|
||||||
tryCatch,
|
tryCatch,
|
||||||
|
last,
|
||||||
} from "@welshman/lib"
|
} from "@welshman/lib"
|
||||||
import type {Socket} from "@welshman/net"
|
import type {Socket} from "@welshman/net"
|
||||||
import {Pool, load, AuthStateEvent, AuthStatus, SocketEvent, netContext} from "@welshman/net"
|
import {Pool, load, AuthStateEvent, AuthStatus, SocketEvent, netContext} from "@welshman/net"
|
||||||
@@ -760,6 +761,17 @@ export const deriveUserMembershipStatus = (url: string, room: string) =>
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const deriveUserCanCreateRoom = (url: string) =>
|
||||||
|
derived([pubkey, deriveEventsForUrl(url, [{kinds: [39004]}])], ([$pubkey, $events]) => {
|
||||||
|
const latest = last($events)
|
||||||
|
|
||||||
|
if (!latest) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return getTagValues("p", latest.tags).includes($pubkey!)
|
||||||
|
})
|
||||||
|
|
||||||
// Other utils
|
// Other utils
|
||||||
|
|
||||||
export const encodeRelay = (url: string) =>
|
export const encodeRelay = (url: string) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user