Move join before composing, and cache membership state
This commit is contained in:
parent
fadac80033
commit
30f52af4b1
10 changed files with 503 additions and 149 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { GROUP_ID } from "$lib/config";
|
||||
import { GROUP_ID, MODE } from "$lib/config";
|
||||
import { queryForum } from "$lib/relay";
|
||||
import { groupsStore } from "$lib/groups.svelte";
|
||||
|
||||
export type GroupMetadata = {
|
||||
name: string;
|
||||
|
|
@ -7,9 +8,20 @@ export type GroupMetadata = {
|
|||
about?: string;
|
||||
isPrivate: boolean;
|
||||
isClosed: boolean;
|
||||
isRestricted: boolean;
|
||||
isHidden: boolean;
|
||||
admins: string[];
|
||||
};
|
||||
|
||||
// NIP-29 access flags: private = members-only read, restricted = members-only
|
||||
// write, closed = join requests ignored, hidden = metadata hidden from non-members.
|
||||
export type GroupFlags = {
|
||||
isPrivate: boolean;
|
||||
isClosed: boolean;
|
||||
isRestricted: boolean;
|
||||
isHidden: boolean;
|
||||
};
|
||||
|
||||
let group = $state<GroupMetadata | null>(null);
|
||||
let loaded = $state(false);
|
||||
|
||||
|
|
@ -40,9 +52,33 @@ export async function loadGroup() {
|
|||
about: event.tags.find((t) => t[0] === "about")?.[1],
|
||||
isPrivate: event.tags.some((t) => t[0] === "private"),
|
||||
isClosed: event.tags.some((t) => t[0] === "closed"),
|
||||
isRestricted: event.tags.some((t) => t[0] === "restricted"),
|
||||
isHidden: event.tags.some((t) => t[0] === "hidden"),
|
||||
admins,
|
||||
};
|
||||
} finally {
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// A group's access flags from whichever store holds them: full mode keeps every
|
||||
// room in the groups list, simple mode has the single active group's metadata.
|
||||
export function getGroupFlags(groupId: string): GroupFlags | null {
|
||||
if (MODE === "full") {
|
||||
const g = groupsStore.list.find((x) => x.id === groupId);
|
||||
if (!g) return null;
|
||||
return {
|
||||
isPrivate: g.flags.includes("private"),
|
||||
isClosed: g.flags.includes("closed"),
|
||||
isRestricted: g.flags.includes("restricted"),
|
||||
isHidden: g.flags.includes("hidden"),
|
||||
};
|
||||
}
|
||||
if (!group) return null;
|
||||
return {
|
||||
isPrivate: group.isPrivate,
|
||||
isClosed: group.isClosed,
|
||||
isRestricted: group.isRestricted,
|
||||
isHidden: group.isHidden,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue