// Shared messaging helpers used by both the Messages page and the floating chat dock. import { useSyncExternalStore } from "react"; import { api } from "./api"; import { isUnlocked, subscribeUnlock } from "./e2ee"; export const SYSTEM_ID = 0; // synthetic "Siftlode" system conversation partner id // Set-once cache of partner public keys (the server is the directory; keys never change). const pubCache = new Map(); export async function partnerPub(partnerId: number): Promise { const cached = pubCache.get(partnerId); if (cached) return cached; const r = await api.messagePublicKey(partnerId); pubCache.set(partnerId, r.public_key); return r.public_key; } // Live "is secure messaging unlocked on this device" — shared so the page and the dock agree. export function useUnlocked(): boolean { return useSyncExternalStore(subscribeUnlock, isUnlocked, isUnlocked); }