Extract relay-agnostic forum fetchers from the stores
This commit is contained in:
parent
54c0682dce
commit
a7b5d8f223
16 changed files with 694 additions and 531 deletions
|
|
@ -1,16 +1,7 @@
|
|||
import { queryForum } from "$lib/relay";
|
||||
import { fetchGroups, type GroupSummary } from "$lib/forum/groups";
|
||||
|
||||
export type GroupSummary = {
|
||||
id: string; // NIP-29 group id (the `d` tag) — also the room URL slug
|
||||
name: string;
|
||||
picture?: string;
|
||||
about?: string;
|
||||
createdAt: number;
|
||||
flags: string[]; // special NIP-29 markers present (private, hidden, closed, restricted)
|
||||
};
|
||||
|
||||
// NIP-29 metadata markers we surface as room tags, in display order.
|
||||
const SPECIAL_FLAGS = ["private", "hidden", "closed", "restricted"];
|
||||
export type { GroupSummary };
|
||||
|
||||
let list = $state<GroupSummary[]>([]);
|
||||
let loaded = $state(false);
|
||||
|
|
@ -24,26 +15,9 @@ export const groupsStore = {
|
|||
},
|
||||
};
|
||||
|
||||
// Fetch every group the relay hosts. NIP-29 publishes one kind 39000 metadata
|
||||
// event per group, so an unfiltered query enumerates them all.
|
||||
export async function loadGroups() {
|
||||
try {
|
||||
const events = await queryForum({ kinds: [39000] });
|
||||
list = events
|
||||
.map((e) => {
|
||||
const id = e.tags.find((t) => t[0] === "d")?.[1] ?? "";
|
||||
return {
|
||||
id,
|
||||
name: e.tags.find((t) => t[0] === "name")?.[1] ?? id,
|
||||
picture: e.tags.find((t) => t[0] === "picture")?.[1],
|
||||
about: e.tags.find((t) => t[0] === "about")?.[1],
|
||||
createdAt: e.created_at,
|
||||
flags: SPECIAL_FLAGS.filter((f) => e.tags.some((t) => t[0] === f)),
|
||||
};
|
||||
})
|
||||
.filter((g) => g.id)
|
||||
// Oldest first.
|
||||
.sort((a, b) => a.createdAt - b.createdAt);
|
||||
list = await fetchGroups(queryForum);
|
||||
} finally {
|
||||
loaded = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue