Use userRoomsByUrl
This commit is contained in:
+3
-3
@@ -65,7 +65,7 @@ import {
|
||||
loadMembership,
|
||||
loadSettings,
|
||||
getDefaultPubkeys,
|
||||
getMembershipUrls,
|
||||
userRoomsByUrl,
|
||||
} from "@app/state"
|
||||
|
||||
// Utils
|
||||
@@ -301,7 +301,7 @@ export const setRelayPolicy = (url: string, read: boolean, write: boolean) => {
|
||||
url,
|
||||
...INDEXER_RELAYS,
|
||||
...ctx.app.router.FromUser().getUrls(),
|
||||
...getMembershipUrls(userMembership.get()),
|
||||
...userRoomsByUrl.get().keys(),
|
||||
],
|
||||
})
|
||||
}
|
||||
@@ -322,7 +322,7 @@ export const setInboxRelayPolicy = (url: string, enabled: boolean) => {
|
||||
relays: [
|
||||
...INDEXER_RELAYS,
|
||||
...ctx.app.router.FromUser().getUrls(),
|
||||
...getMembershipUrls(userMembership.get()),
|
||||
...userRoomsByUrl.get().keys(),
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
import RoomCreate from "@app/components/RoomCreate.svelte"
|
||||
import MenuSpaceRoomItem from "@app/components/MenuSpaceRoomItem.svelte"
|
||||
import {
|
||||
getMembershipUrls,
|
||||
userRoomsByUrl,
|
||||
hasMembershipUrl,
|
||||
userMembership,
|
||||
memberships,
|
||||
deriveUserRooms,
|
||||
deriveOtherRooms,
|
||||
@@ -93,7 +92,7 @@
|
||||
</Button>
|
||||
</li>
|
||||
<li>
|
||||
{#if getMembershipUrls($userMembership).includes(url)}
|
||||
{#if $userRoomsByUrl.has(url)}
|
||||
<Button on:click={leaveSpace} class="text-error">
|
||||
<Icon icon="exit" />
|
||||
Leave Space
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import CardButton from "@lib/components/CardButton.svelte"
|
||||
import MenuSpacesItem from "@app/components/MenuSpacesItem.svelte"
|
||||
import SpaceAdd from "@app/components/SpaceAdd.svelte"
|
||||
import {userMembership, getMembershipUrls, PLATFORM_RELAY} from "@app/state"
|
||||
import {userRoomsByUrl, PLATFORM_RELAY} from "@app/state"
|
||||
import {pushModal} from "@app/modal"
|
||||
|
||||
const addSpace = () => pushModal(SpaceAdd)
|
||||
@@ -15,8 +15,8 @@
|
||||
{#if PLATFORM_RELAY}
|
||||
<MenuSpacesItem url={PLATFORM_RELAY} />
|
||||
<Divider />
|
||||
{:else if getMembershipUrls($userMembership).length > 0}
|
||||
{#each getMembershipUrls($userMembership) as url (url)}
|
||||
{:else if $userRoomsByUrl.size > 0}
|
||||
{#each $userRoomsByUrl.keys() as url (url)}
|
||||
<MenuSpacesItem {url} />
|
||||
{/each}
|
||||
<Divider />
|
||||
|
||||
@@ -10,13 +10,7 @@
|
||||
import MenuSpaces from "@app/components/MenuSpaces.svelte"
|
||||
import MenuSettings from "@app/components/MenuSettings.svelte"
|
||||
import PrimaryNavItemSpace from "@app/components/PrimaryNavItemSpace.svelte"
|
||||
import {
|
||||
userMembership,
|
||||
getMembershipUrls,
|
||||
canDecrypt,
|
||||
PLATFORM_RELAY,
|
||||
PLATFORM_LOGO,
|
||||
} from "@app/state"
|
||||
import {userRoomsByUrl, canDecrypt, PLATFORM_RELAY, PLATFORM_LOGO} from "@app/state"
|
||||
import {pushModal} from "@app/modal"
|
||||
import {makeSpacePath} from "@app/routes"
|
||||
import {notifications} from "@app/notifications"
|
||||
@@ -31,7 +25,7 @@
|
||||
|
||||
const openChat = () => ($canDecrypt ? goto("/chat") : pushModal(ChatEnable, {next: "/chat"}))
|
||||
|
||||
$: spaceUrls = getMembershipUrls($userMembership)
|
||||
$: spaceUrls = Array.from($userRoomsByUrl.keys())
|
||||
$: spacePaths = spaceUrls.map(url => makeSpacePath(url))
|
||||
$: anySpaceNotifications = spacePaths.some(
|
||||
path => !$page.url.pathname.startsWith(path) && $notifications.has(path),
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import type {Page} from "@sveltejs/kit"
|
||||
import {userMembership, makeChatId, decodeRelay, encodeRelay, getMembershipUrls} from "@app/state"
|
||||
import {makeChatId, decodeRelay, encodeRelay, userRoomsByUrl} from "@app/state"
|
||||
|
||||
export const makeSpacePath = (url: string, ...extra: string[]) => {
|
||||
let path = `/spaces/${encodeRelay(url)}`
|
||||
@@ -28,7 +28,7 @@ export const makeThreadPath = (url: string, eventId?: string) => {
|
||||
export const getPrimaryNavItem = ($page: Page) => $page.route?.id?.split("/")[1]
|
||||
|
||||
export const getPrimaryNavItemIndex = ($page: Page) => {
|
||||
const urls = getMembershipUrls(userMembership.get())
|
||||
const urls = Array.from(userRoomsByUrl.get().keys())
|
||||
|
||||
switch (getPrimaryNavItem($page)) {
|
||||
case "discover":
|
||||
|
||||
+1
-1
@@ -638,7 +638,7 @@ export const userRoomsByUrl = withGetter(
|
||||
|
||||
export const deriveUserRooms = (url: string) =>
|
||||
derived(userRoomsByUrl, $userRoomsByUrl =>
|
||||
sortBy(roomComparator(url), uniq(Array.from($userRoomsByUrl.get(url) || []))),
|
||||
sortBy(roomComparator(url), uniq(Array.from($userRoomsByUrl.get(url) || [GENERAL]))),
|
||||
)
|
||||
|
||||
export const deriveOtherRooms = (url: string) =>
|
||||
|
||||
@@ -185,11 +185,11 @@
|
||||
}
|
||||
|
||||
// Listen for space data, populate space-based notifications
|
||||
let spacesSub: any
|
||||
let unsubSpaces: any
|
||||
|
||||
userMembership.subscribe($membership => {
|
||||
spacesSub?.close()
|
||||
spacesSub = listenForNotifications()
|
||||
unsubSpaces?.()
|
||||
unsubSpaces = listenForNotifications()
|
||||
})
|
||||
|
||||
// Listen for chats, populate chat-based notifications
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
import SpaceCheck from "@app/components/SpaceCheck.svelte"
|
||||
import ProfileCircles from "@app/components/ProfileCircles.svelte"
|
||||
import {
|
||||
userMembership,
|
||||
memberships,
|
||||
membershipByPubkey,
|
||||
getMembershipUrls,
|
||||
userRoomsByUrl,
|
||||
getDefaultPubkeys,
|
||||
} from "@app/state"
|
||||
import {discoverRelays} from "@app/commands"
|
||||
@@ -98,7 +98,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{#if getMembershipUrls($userMembership).includes(relay.url)}
|
||||
{#if $userRoomsByUrl.has(relay.url)}
|
||||
<div
|
||||
class="tooltip absolute -right-1 -top-1 h-5 w-5 rounded-full bg-primary"
|
||||
data-tip="You are already a member of this space.">
|
||||
|
||||
@@ -22,8 +22,7 @@
|
||||
channelsById,
|
||||
deriveUserRooms,
|
||||
deriveOtherRooms,
|
||||
userMembership,
|
||||
getMembershipUrls,
|
||||
userRoomsByUrl,
|
||||
} from "@app/state"
|
||||
import {makeChatPath, makeRoomPath, makeSpacePath} from "@app/routes"
|
||||
import {notifications} from "@app/notifications"
|
||||
@@ -51,7 +50,7 @@
|
||||
</div>
|
||||
<strong slot="title">Home</strong>
|
||||
<div slot="action" class="row-2">
|
||||
{#if !getMembershipUrls($userMembership).includes(url)}
|
||||
{#if !$userRoomsByUrl.has(url)}
|
||||
<Button class="btn btn-primary btn-sm" on:click={joinSpace}>
|
||||
<Icon icon="login-2" />
|
||||
Join Space
|
||||
|
||||
@@ -24,13 +24,12 @@
|
||||
import ChannelCompose from "@app/components/ChannelCompose.svelte"
|
||||
import {
|
||||
userSettingValues,
|
||||
userMembership,
|
||||
decodeRelay,
|
||||
deriveEventsForUrl,
|
||||
GENERAL,
|
||||
tagRoom,
|
||||
LEGACY_MESSAGE,
|
||||
getMembershipRoomsByUrl,
|
||||
userRoomsByUrl,
|
||||
displayChannel,
|
||||
} from "@app/state"
|
||||
import {setChecked} from "@app/notifications"
|
||||
@@ -160,7 +159,7 @@
|
||||
</strong>
|
||||
<div slot="action" class="row-2">
|
||||
{#if room !== GENERAL}
|
||||
{#if getMembershipRoomsByUrl(url, $userMembership).includes(room)}
|
||||
{#if $userRoomsByUrl.get(url)?.has(room)}
|
||||
<Button class="btn btn-neutral btn-sm" on:click={leaveRoom}>
|
||||
<Icon icon="arrows-a-logout-2" />
|
||||
Leave Room
|
||||
|
||||
Reference in New Issue
Block a user