fix: low-tail correctness — thread notifs, call audio, OIDC expiry

Verify-then-fix batch of minor bugs; each staged diff reviewed by 2 agents
(both SHIP). Two listed items (N6 receipt-avatar refresh, H10 room-name
length reject) were already handled and left unchanged.

Threads:
- T5: a just-sent reply no longer under-notifies — `participated` also checks
  the local thread timeline for our own events, since the server-bundle
  `hasCurrentUserParticipated` lags.
- T6: a room set to "Mentions & Keywords only" no longer over-notifies Default
  thread replies — new `roomMentionsOnly` gate (behavior-identical when false;
  +4 unit tests).
- T7: thread-mode account-data writes are serialized with content carried
  forward (setAccountData is a bare PUT whose result lags the /sync echo, so
  plain serialization wouldn't stop the lost update); carry only on success.

Calls / audio:
- C-L2: a real incoming ring cancels a lingering Settings ringtone preview.
- C-L3: the ringtone AudioContext is primed on the first page gesture (via the
  always-mounted CallEmbedProvider) so the first ring after a cold load isn't
  silent.
- C-L5: useCallSpeakers depends on a stable boolean, so the tile MutationObserver
  + io.lotus.call_state subscription aren't rebuilt on every membership change.

Crypto:
- F5: the OIDC refresher forwards the freshly-refreshed token expiry
  (passed on the tokens object at runtime) as expiresInMs, so the persisted
  expiresAt no longer goes stale across reloads.

Gates: tsc 0, eslint 0, prettier clean, 860/860 tests, build ok.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-19 02:47:27 -04:00
co-authored by Claude Opus 4.8
parent 291e14ab48
commit a267e9e960
8 changed files with 147 additions and 25 deletions
+8 -2
View File
@@ -25,8 +25,14 @@ export const useCallSpeakers = (callEmbed: CallEmbed): Set<string> => {
const callMembers = useCallMembers(callSession);
const joined = useCallJoined(callEmbed);
// C-L5 — depend on a STABLE boolean, not the callMembers array (whose identity
// changes on every membership change). The MutationObserver + io.lotus.call_state
// subscription below already track tiles joining/leaving live, so rebuilding
// them on each membership change is pure churn.
const hasCallMembers = callMembers.length > 0;
useEffect(() => {
if (!callMembers || !joined) {
if (!hasCallMembers || !joined) {
setSpeakers(new Set<string>());
return undefined;
}
@@ -126,7 +132,7 @@ export const useCallSpeakers = (callEmbed: CallEmbed): Set<string> => {
bodyWatcher?.disconnect();
unsubLotus();
};
}, [callEmbed, callMembers, joined]);
}, [callEmbed, hasCallMembers, joined]);
return speakers;
};
+47 -13
View File
@@ -36,21 +36,19 @@ const getJoinedRoomIds = (mx: MatrixClient): Set<string> => {
return joined;
};
const writeThreadNotificationMode = async (
mx: MatrixClient,
// Apply a single mode change to a base content object, returning a fresh clone
// (never mutates the input).
const applyThreadMode = (
base: ThreadNotificationsContent,
roomId: string,
threadRootId: string,
mode: ThreadNotificationMode,
): Promise<void> => {
const current = readContent(mx);
const now = Date.now();
// Work on a mutable clone; prune produces a fresh object so the mutations
// below never touch the atom's/account-data's current content.
now: number,
): ThreadNotificationsContent => {
const next: ThreadNotificationsContent = {
...current,
...base,
rooms: Object.fromEntries(
Object.entries(current.rooms ?? {}).map(([rid, entries]) => [rid, { ...entries }]),
Object.entries(base.rooms ?? {}).map(([rid, entries]) => [rid, { ...entries }]),
),
};
@@ -70,10 +68,46 @@ const writeThreadNotificationMode = async (
rooms[roomId][threadRootId] = { mode, ts: now };
}
// ALWAYS prune before persisting to keep account data bounded.
const finalContent = pruneThreadNotifications(next, getJoinedRoomIds(mx), now);
return next;
};
await setAccountData(mx, AccountDataEvent.LotusThreadNotifications, finalContent);
// T7 — serialize writes so rapid, overlapping mode changes don't lost-update
// each other. `setAccountData` is a bare PUT whose result doesn't reach the
// local store until the /sync echo, so back-to-back writes would otherwise all
// read the same stale base and clobber one another. Each queued write instead
// bases its mutation on the previous write's RESULT; once the queue drains the
// carried base is dropped so the next independent write re-reads fresh (possibly
// externally-changed) server state.
let writeChain: Promise<unknown> = Promise.resolve();
let pendingWrites = 0;
let carriedContent: ThreadNotificationsContent | null = null;
const writeThreadNotificationMode = (
mx: MatrixClient,
roomId: string,
threadRootId: string,
mode: ThreadNotificationMode,
): Promise<void> => {
pendingWrites += 1;
const run = writeChain.then(async () => {
const now = Date.now();
const base = carriedContent ?? readContent(mx);
const next = applyThreadMode(base, roomId, threadRootId, mode, now);
// ALWAYS prune before persisting to keep account data bounded.
const finalContent = pruneThreadNotifications(next, getJoinedRoomIds(mx), now);
await setAccountData(mx, AccountDataEvent.LotusThreadNotifications, finalContent);
// Carry the result forward only on success, so a queued follow-up write bases
// on persisted content — never on a shape the server just rejected.
carriedContent = finalContent;
});
// Keep the chain alive on error; drop the carried base once the queue drains.
writeChain = run
.catch(() => {})
.finally(() => {
pendingWrites -= 1;
if (pendingWrites === 0) carriedContent = null;
});
return run;
};
export function useSetThreadNotificationMode(