forked from coracle/flotilla
Move create room permission check to menu space
This commit is contained in:
committed by
Jon Staab
parent
a39a87ba6d
commit
69e3ee0aff
@@ -38,10 +38,12 @@
|
||||
deriveOtherRooms,
|
||||
hasNip29,
|
||||
alerts,
|
||||
deriveUserCanCreateRoom,
|
||||
} from "@app/core/state"
|
||||
import {notifications} from "@app/util/notifications"
|
||||
import {pushModal} from "@app/util/modal"
|
||||
import {makeSpacePath} from "@app/util/routes"
|
||||
import {get} from "svelte/store"
|
||||
|
||||
const {url} = $props()
|
||||
|
||||
@@ -69,6 +71,8 @@
|
||||
{replaceState},
|
||||
)
|
||||
|
||||
const canCreateRoom = get<boolean>(deriveUserCanCreateRoom(url))
|
||||
|
||||
const createInvite = () => pushModal(SpaceInvite, {url}, {replaceState})
|
||||
|
||||
const leaveSpace = () => pushModal(SpaceExit, {url}, {replaceState})
|
||||
@@ -185,10 +189,12 @@
|
||||
{#each $otherRooms as room, i (room)}
|
||||
<MenuSpaceRoomItem {replaceState} {url} {room} />
|
||||
{/each}
|
||||
<SecondaryNavItem {replaceState} onclick={addRoom}>
|
||||
<Icon icon={AddCircle} />
|
||||
Create room
|
||||
</SecondaryNavItem>
|
||||
{#if canCreateRoom}
|
||||
<SecondaryNavItem {replaceState} onclick={addRoom}>
|
||||
<Icon icon={AddCircle} />
|
||||
Create room
|
||||
</SecondaryNavItem>
|
||||
{/if}
|
||||
{:else}
|
||||
<SecondaryNavItem
|
||||
{replaceState}
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||
import {deriveUserCanCreateRoom, hasNip29, loadChannel} from "@app/core/state"
|
||||
import {hasNip29, loadChannel} from "@app/core/state"
|
||||
import {makeSpacePath} from "@app/util/routes"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {get} from "svelte/store"
|
||||
|
||||
const {url} = $props()
|
||||
|
||||
@@ -52,8 +51,6 @@
|
||||
goto(makeSpacePath(url, room.id))
|
||||
}
|
||||
|
||||
const canCreateRoom = get<boolean>(deriveUserCanCreateRoom(url))
|
||||
|
||||
const create = async () => {
|
||||
loading = true
|
||||
|
||||
@@ -102,10 +99,7 @@
|
||||
<Icon icon={AltArrowLeft} />
|
||||
Go back
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
class="btn btn-primary"
|
||||
disabled={!name || loading || !hasNip29($relay) || !canCreateRoom}>
|
||||
<Button type="submit" class="btn btn-primary" disabled={!name || loading || !hasNip29($relay)}>
|
||||
<Spinner {loading}>Create Room</Spinner>
|
||||
<Icon icon={AltArrowRight} />
|
||||
</Button>
|
||||
|
||||
+11
-7
@@ -53,6 +53,7 @@ import {
|
||||
ROOM_JOIN,
|
||||
ROOM_ADD_USER,
|
||||
ROOM_REMOVE_USER,
|
||||
ROOM_CREATE_PERMISSION,
|
||||
ALERT_EMAIL,
|
||||
ALERT_WEB,
|
||||
ALERT_IOS,
|
||||
@@ -762,15 +763,18 @@ export const deriveUserMembershipStatus = (url: string, room: string) =>
|
||||
)
|
||||
|
||||
export const deriveUserCanCreateRoom = (url: string) =>
|
||||
derived([pubkey, deriveEventsForUrl(url, [{kinds: [39004]}])], ([$pubkey, $events]) => {
|
||||
const latest = last($events)
|
||||
derived(
|
||||
[pubkey, deriveEventsForUrl(url, [{kinds: [ROOM_CREATE_PERMISSION]}])],
|
||||
([$pubkey, $events]) => {
|
||||
const latest = last($events)
|
||||
|
||||
if (!latest) {
|
||||
return true
|
||||
}
|
||||
if (!latest) {
|
||||
return true
|
||||
}
|
||||
|
||||
return getTagValues("p", latest.tags).includes($pubkey!)
|
||||
})
|
||||
return getTagValues("p", latest.tags).includes($pubkey!)
|
||||
},
|
||||
)
|
||||
|
||||
// Other utils
|
||||
|
||||
|
||||
Reference in New Issue
Block a user