feat(frontend): installable on the phone with its own icon, title and manifest, missing avatars are asked again later

This commit is contained in:
hh committed 2026-10-19 02:05:41 +00:00
1 parent a1d3552519
commit 50922ef69a
8 files changed
+67 -22

No files matched your search

+19 -5
View File
@@ -4,13 +4,27 @@ import { PUBLIC_API_BASE_URL } from "$app/env/public";
const BASE = PUBLIC_API_BASE_URL;
const RETRY_DELAY = 2500;
const MISSING_TTL = 120_000;
export type AvatarKind = "peer" | "chat";
const MAX_CACHED = 240;
const ready = new Map<string, string>();
const missing = new Set<string>();
const missing = new Map<string, number>();
function isMissing(key: string): boolean {
const since = missing.get(key);
if (since === undefined) {
return false;
}
if (Date.now() - since < MISSING_TTL) {
return true;
}
missing.delete(key);
return false;
}
const inflight = new Map<string, Promise<string | null>>();
function cacheKey(account: number, kind: AvatarKind, id: number): string {
@@ -60,7 +74,7 @@ async function fetchAvatar(
await delay(RETRY_DELAY);
return fetchAvatar(account, kind, id, key, false);
}
missing.add(key);
missing.set(key, Date.now());
return null;
}
@@ -77,7 +91,7 @@ export function loadAvatar(
if (cached) {
return Promise.resolve(cached);
}
if (missing.has(key)) {
if (isMissing(key)) {
return Promise.resolve(null);
}
const existing = inflight.get(key);
@@ -110,7 +124,7 @@ async function fetchVariant(
await delay(RETRY_DELAY);
return fetchVariant(account, kind, id, uniqueId, key, false);
}
missing.add(key);
missing.set(key, Date.now());
return null;
}
@@ -128,7 +142,7 @@ export function loadAvatarVariant(
if (cached) {
return Promise.resolve(cached);
}
if (missing.has(key)) {
if (isMissing(key)) {
return Promise.resolve(null);
}
const existing = inflight.get(key);