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,
|
deriveOtherRooms,
|
||||||
hasNip29,
|
hasNip29,
|
||||||
alerts,
|
alerts,
|
||||||
|
deriveUserCanCreateRoom,
|
||||||
} from "@app/core/state"
|
} from "@app/core/state"
|
||||||
import {notifications} from "@app/util/notifications"
|
import {notifications} from "@app/util/notifications"
|
||||||
import {pushModal} from "@app/util/modal"
|
import {pushModal} from "@app/util/modal"
|
||||||
import {makeSpacePath} from "@app/util/routes"
|
import {makeSpacePath} from "@app/util/routes"
|
||||||
|
import {get} from "svelte/store"
|
||||||
|
|
||||||
const {url} = $props()
|
const {url} = $props()
|
||||||
|
|
||||||
@@ -69,6 +71,8 @@
|
|||||||
{replaceState},
|
{replaceState},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const canCreateRoom = get<boolean>(deriveUserCanCreateRoom(url))
|
||||||
|
|
||||||
const createInvite = () => pushModal(SpaceInvite, {url}, {replaceState})
|
const createInvite = () => pushModal(SpaceInvite, {url}, {replaceState})
|
||||||
|
|
||||||
const leaveSpace = () => pushModal(SpaceExit, {url}, {replaceState})
|
const leaveSpace = () => pushModal(SpaceExit, {url}, {replaceState})
|
||||||
@@ -185,10 +189,12 @@
|
|||||||
{#each $otherRooms as room, i (room)}
|
{#each $otherRooms as room, i (room)}
|
||||||
<MenuSpaceRoomItem {replaceState} {url} {room} />
|
<MenuSpaceRoomItem {replaceState} {url} {room} />
|
||||||
{/each}
|
{/each}
|
||||||
<SecondaryNavItem {replaceState} onclick={addRoom}>
|
{#if canCreateRoom}
|
||||||
<Icon icon={AddCircle} />
|
<SecondaryNavItem {replaceState} onclick={addRoom}>
|
||||||
Create room
|
<Icon icon={AddCircle} />
|
||||||
</SecondaryNavItem>
|
Create room
|
||||||
|
</SecondaryNavItem>
|
||||||
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<SecondaryNavItem
|
<SecondaryNavItem
|
||||||
{replaceState}
|
{replaceState}
|
||||||
|
|||||||
@@ -14,10 +14,9 @@
|
|||||||
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 {deriveUserCanCreateRoom, hasNip29, loadChannel} from "@app/core/state"
|
import {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()
|
||||||
|
|
||||||
@@ -52,8 +51,6 @@
|
|||||||
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
|
||||||
|
|
||||||
@@ -102,10 +99,7 @@
|
|||||||
<Icon icon={AltArrowLeft} />
|
<Icon icon={AltArrowLeft} />
|
||||||
Go back
|
Go back
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button type="submit" class="btn btn-primary" disabled={!name || loading || !hasNip29($relay)}>
|
||||||
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>
|
||||||
|
|||||||
+11
-7
@@ -53,6 +53,7 @@ import {
|
|||||||
ROOM_JOIN,
|
ROOM_JOIN,
|
||||||
ROOM_ADD_USER,
|
ROOM_ADD_USER,
|
||||||
ROOM_REMOVE_USER,
|
ROOM_REMOVE_USER,
|
||||||
|
ROOM_CREATE_PERMISSION,
|
||||||
ALERT_EMAIL,
|
ALERT_EMAIL,
|
||||||
ALERT_WEB,
|
ALERT_WEB,
|
||||||
ALERT_IOS,
|
ALERT_IOS,
|
||||||
@@ -762,15 +763,18 @@ export const deriveUserMembershipStatus = (url: string, room: string) =>
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const deriveUserCanCreateRoom = (url: string) =>
|
export const deriveUserCanCreateRoom = (url: string) =>
|
||||||
derived([pubkey, deriveEventsForUrl(url, [{kinds: [39004]}])], ([$pubkey, $events]) => {
|
derived(
|
||||||
const latest = last($events)
|
[pubkey, deriveEventsForUrl(url, [{kinds: [ROOM_CREATE_PERMISSION]}])],
|
||||||
|
([$pubkey, $events]) => {
|
||||||
|
const latest = last($events)
|
||||||
|
|
||||||
if (!latest) {
|
if (!latest) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return getTagValues("p", latest.tags).includes($pubkey!)
|
return getTagValues("p", latest.tags).includes($pubkey!)
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
||||||
// Other utils
|
// Other utils
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user