+
{packages.map((licensePackage) => (
;
+const USER_CACHE_MAX_AGE = 5 * 60 * 1000;
+
interface contextValue {
get(userId: number): Promise;
}
@@ -31,6 +33,7 @@ const UserContext = createContext(undefined);
export default function UserProvider(props: { children: ReactNode }) {
const storageRef = useRef>({});
const pendingRef = useRef | undefined>>({});
+ const checkedAtRef = useRef>({});
const { send } = useMTP();
const { load } = useStorage();
@@ -66,17 +69,36 @@ export default function UserProvider(props: { children: ReactNode }) {
const cachedResult =
schemas.GetUserData.response.safeParse(cachedValue);
const cached = cachedResult.success ? cachedResult.data : undefined;
- if (cached) storageRef.current[userId] = cached;
+ if (cached) {
+ storageRef.current[userId] = cached;
+ const checkedAt = checkedAtRef.current[userId];
+ if (checkedAt && Date.now() - checkedAt < USER_CACHE_MAX_AGE) {
+ return cached;
+ }
+ }
try {
const userData = await send("GetUserData", { UserId: userId });
+ if (
+ userData.type === "ErrorNotFound" ||
+ userData.data.UserId === 0
+ ) {
+ delete storageRef.current[userId];
+ delete checkedAtRef.current[userId];
+ await cache?.profiles.delete(userId);
+ throw new Error("GetUserData failed: user not found");
+ }
if (userData.type.startsWith("Error")) {
throw new Error(`GetUserData failed: ${userData.type}`);
}
const user = userData.data;
storageRef.current[userId] = user;
+ checkedAtRef.current[userId] = Date.now();
return user;
} catch (error) {
- if (cached) return cached;
+ if (cached && storageRef.current[userId]) {
+ checkedAtRef.current[userId] = Date.now();
+ return cached;
+ }
throw error;
}
})();
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c058945..ab3dd0e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -5,7 +5,7 @@ settings:
excludeLinksFromLockfile: false
overrides:
- '@methanium/ui': https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
+ '@methanium/ui': https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
mtp: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz
importers:
@@ -13,8 +13,8 @@ importers:
.:
dependencies:
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
mtp:
specifier: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz
version: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz
@@ -89,8 +89,8 @@ importers:
apps/tauri:
dependencies:
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
'@tauri-apps/api':
specifier: ^2
version: 2.11.1
@@ -153,8 +153,8 @@ importers:
specifier: ^5.2.7
version: 5.2.7
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
'@radix-ui/primitive':
specifier: ^1.1.0
version: 1.1.4
@@ -532,8 +532,8 @@ importers:
specifier: ^2.9.20
version: 2.9.21(livekit-client@2.20.0(@types/dom-mediacapture-record@1.0.22))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(tslib@2.8.1)
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
'@tanstack/react-router':
specifier: ^1.169.1
version: 1.170.17(react-dom@19.2.7(react@19.2.7))(react@19.2.7)
@@ -583,8 +583,8 @@ importers:
packages/chat:
dependencies:
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
'@tanstack/pacer':
specifier: ^0.21.1
version: 0.21.1
@@ -664,8 +664,8 @@ importers:
specifier: ^6.41.1
version: 6.43.4
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
'@twemoji/api':
specifier: ^17.0.3
version: 17.0.3
@@ -682,8 +682,8 @@ importers:
packages/mtp:
dependencies:
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
'@tauri-apps/api':
specifier: ^2
version: 2.11.1
@@ -722,8 +722,8 @@ importers:
packages/notifications:
dependencies:
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
'@tanstack/react-router':
specifier: ^1.169.1
version: 1.170.17(react-dom@19.2.7(react@19.2.7))(react@19.2.7)
@@ -764,8 +764,8 @@ importers:
packages/onboarding:
dependencies:
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
'@tensamin/shared':
specifier: workspace:*
version: link:../shared
@@ -788,8 +788,8 @@ importers:
packages/settings:
dependencies:
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
'@tanstack/react-router':
specifier: ^1.169.1
version: 1.170.17(react-dom@19.2.7(react@19.2.7))(react@19.2.7)
@@ -828,8 +828,8 @@ importers:
packages/shared:
dependencies:
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
lucide-react:
specifier: ^1.14.0
version: 1.23.0(react@19.2.7)
@@ -846,8 +846,8 @@ importers:
packages/storage:
dependencies:
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
'@tauri-apps/api':
specifier: ^2
version: 2.11.1
@@ -870,8 +870,8 @@ importers:
packages/tauth:
dependencies:
'@methanium/ui':
- specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz
- version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
+ specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz
+ version: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)
'@tanstack/react-router':
specifier: ^1.0.0
version: 1.170.17(react-dom@19.2.7(react@19.2.7))(react@19.2.7)
@@ -1443,9 +1443,6 @@ packages:
'@fontsource-variable/public-sans@5.2.7':
resolution: {integrity: sha512-4mvade2J3slKkvwRkS+p8T3szet/0vhWoSnuUJTVU81Uo2pRpSZY/Y8bSLRqpSwzIPxjVmRJ53oq6JKP/l/PSg==}
- '@fontsource-variable/public-sans@5.3.0':
- resolution: {integrity: sha512-AVfkmAt50BMXWpOO21FAntiJFKGX6xTc2dSL8dxtDteONe9IuRXJWGbs0EbG955vAMCq23ENeuopuW87cGWDSQ==}
-
'@hono/node-server@1.19.14':
resolution: {integrity: sha512-GwtvgtXxnWsucXvbQXkRgqksiH2Qed37H9xHZocE5sA3N8O8O8/8FA3uclQXxXVzc9XBZuEOMK7+r02FmSpHtw==}
engines: {node: '>=18.14.1'}
@@ -1550,9 +1547,9 @@ packages:
'@marijn/find-cluster-break@1.0.3':
resolution: {integrity: sha512-FY+MKLBoTsLNJF/eLWaOsXGdz6uh3Iu1axjPf6TUq92IYumcTcXWHoS747JARLkcdlJ/Waiaxc5wQfFO8jC6NA==}
- '@methanium/ui@https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz':
- resolution: {integrity: sha512-I71TI1q0ykINusqZH41h5qfOuVLQPXrFa8AVFKKKCMSnIcbk0rWtrTdSQWj/fQZfOAk3f8+f5KT6EQ/lDVkw0A==, tarball: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz}
- version: 0.0.10
+ '@methanium/ui@https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz':
+ resolution: {integrity: sha512-o/IWQyE8UzBFRXcOcBLKMKl6SSjw1HLczvhB1snFH19DyVbLGTHkZ8Ty7fOAu36/8juQJeWEMurtKmYqJO6XkA==, tarball: https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz}
+ version: 0.0.22
peerDependencies:
react: ^19.2.7
react-dom: ^19.2.7
@@ -5746,8 +5743,6 @@ snapshots:
'@fontsource-variable/public-sans@5.2.7': {}
- '@fontsource-variable/public-sans@5.3.0': {}
-
'@hono/node-server@1.19.14(hono@4.12.27)':
dependencies:
hono: 4.12.27
@@ -5865,10 +5860,9 @@ snapshots:
'@marijn/find-cluster-break@1.0.3': {}
- '@methanium/ui@https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)':
+ '@methanium/ui@https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3)':
dependencies:
'@base-ui/react': 1.6.0(@date-fns/tz@1.5.0)(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react@19.2.7)
- '@fontsource-variable/public-sans': 5.3.0
'@tauri-apps/api': 2.11.1
class-variance-authority: 0.7.1
clsx: 2.1.1
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index d8793c9..87d0c28 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -6,5 +6,5 @@ allowBuilds:
electron-winstaller: true
esbuild: true
overrides:
- "@methanium/ui": "https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz"
+ "@methanium/ui": "https://git.methanium.net/methanium/ui/releases/download/0.0.22/methanium-ui.tgz"
mtp: "https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz"