feat: release v0.1.3 chat, profiles, and media

Keep read receipts for the other person only, and let photos, voice, and files stay cached until they are actually replaced.
This commit is contained in:
ahp
2026-10-09 19:05:59 +03:30
parent 3cce2158e9
commit d9a2abb44f
45 changed files with 2337 additions and 573 deletions
+36
View File
@@ -0,0 +1,36 @@
"use client";
import { useEffect, useState } from "react";
import { mediaObjectKey } from "@/lib/media";
import { loadCachedMedia } from "@/lib/transfer";
/** Local bytes for an image or similar object. A replacement has a new key and loads again. Video is not cached. */
export function useCachedObjectUrl(url: string, cacheable = true): string {
const key = mediaObjectKey(url);
const [local, setLocal] = useState("");
useEffect(() => {
if (!cacheable || !url) {
setLocal("");
return;
}
let dead = false;
let objectUrl = "";
void loadCachedMedia(url)
.then((blob) => {
if (dead) return;
objectUrl = URL.createObjectURL(blob);
setLocal(objectUrl);
})
.catch(() => {
if (!dead) setLocal(url);
});
return () => {
dead = true;
if (objectUrl) URL.revokeObjectURL(objectUrl);
};
}, [cacheable, key, url]);
if (!cacheable) return url;
return local;
}