forked from Keelrleek/SoulStream
community: the drawer asks a peer for its card and the server for interests, and discover gets the similar-users shelf
This commit is contained in:
1 parent
64a7561750
commit
5160d97a5f
10 files changed
+412
-2
No files matched your search
@@ -52,6 +52,13 @@ export const community = $state({
|
||||
roomFavs: readJson(LS_FAVS, []),
|
||||
/** Which person the drawer shows, or null. */
|
||||
drawer: null,
|
||||
/** username → native Soulseek card ({...UserInfoDto} | {error}) for
|
||||
* the session; fetched only when a profile is surfaced (the drawer). */
|
||||
userInfo: {},
|
||||
/** username → {likes, hates} | {error}, same lifetime. */
|
||||
interests: {},
|
||||
/** The server's similar-users answer, or null before it was asked. */
|
||||
similar: null,
|
||||
/** key → true while an action runs (buttons disable on it). */
|
||||
busy: {},
|
||||
/** The last action's error, shown where it happened. */
|
||||
@@ -299,3 +306,37 @@ export async function initCommunity() {
|
||||
await Promise.all([refreshFreenet(), loadContacts()]);
|
||||
await refreshPersona();
|
||||
}
|
||||
|
||||
// ---- native Soulseek cards ---------------------------------------------------------
|
||||
/** Fetch a person's native card and interests once per session, both in
|
||||
* flight together; errors are kept per person so the drawer can say so. */
|
||||
export async function loadUserInfo(username) {
|
||||
if (!username) return;
|
||||
if (!community.userInfo[username]) {
|
||||
community.userInfo[username] = { pending: true };
|
||||
api.slskUserInfo(username)
|
||||
.then((v) => (community.userInfo[username] = v))
|
||||
.catch((e) => (community.userInfo[username] = { error: String(e) }));
|
||||
}
|
||||
if (!community.interests[username]) {
|
||||
community.interests[username] = { pending: true };
|
||||
api.slskUserInterests(username)
|
||||
.then((v) => (community.interests[username] = v))
|
||||
.catch((e) => (community.interests[username] = { error: String(e) }));
|
||||
}
|
||||
}
|
||||
export async function loadSimilar(force = false) {
|
||||
if (community.similar && !force) return;
|
||||
community.busy.similar = true;
|
||||
try {
|
||||
community.similar = { users: await api.slskSimilarUsers() };
|
||||
} catch (e) {
|
||||
community.similar = { users: [], error: String(e) };
|
||||
} finally {
|
||||
delete community.busy.similar;
|
||||
}
|
||||
}
|
||||
|
||||
// Dev handle beside `__soulstream` (state.svelte.js): probes reach the store
|
||||
// through this, never through a bare import (which would be a second copy).
|
||||
if (import.meta.env.DEV) globalThis.__community = community;
|
||||
Reference in new issue
Block a user