fix(outbox): two tabs no longer overwrite each other's queue (#268)
CI / Build & Quality Checks (pull_request) Successful in 1m40s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 6s
CI / Playwright smoke (e2e) (pull_request) Successful in 12m4s
CI / Build & Quality Checks (pull_request) Successful in 1m40s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 6s
CI / Playwright smoke (e2e) (pull_request) Successful in 12m4s
OutboxFeature loaded lotus_outbox_v1 once and then saved its own in-memory list over the key on every change, so a second tab's save dropped the first tab's unsent messages. persist() now re-reads the stored list and applies the change (add/remove by txnId) to it. Fixes #268 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a5471a0576
commit
97d2d195c3
@@ -94,10 +94,15 @@ export function OutboxFeature() {
|
|||||||
OFFLINE.has(mx.getSyncState()) ||
|
OFFLINE.has(mx.getSyncState()) ||
|
||||||
(typeof navigator !== 'undefined' && navigator.onLine === false);
|
(typeof navigator !== 'undefined' && navigator.onLine === false);
|
||||||
|
|
||||||
const persist = (next: OutboxEntry[]) => {
|
// [Gitea #268] Read-modify-write: another tab may have queued or cleared
|
||||||
if (next === entries) return;
|
// entries since we last looked, and saving our own copy over the key
|
||||||
|
// would drop theirs. Entries are added/removed by txnId, so applying our
|
||||||
|
// change to the stored list merges cleanly.
|
||||||
|
const persist = (update: (list: OutboxEntry[]) => OutboxEntry[]) => {
|
||||||
|
const stored = loadOutbox(userId);
|
||||||
|
const next = update(stored);
|
||||||
entries = next;
|
entries = next;
|
||||||
saveOutbox(userId, entries);
|
if (next !== stored) saveOutbox(userId, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,8 +128,8 @@ export function OutboxFeature() {
|
|||||||
if (!shouldKeepInOutbox(event.getType(), event.getContent())) return;
|
if (!shouldKeepInOutbox(event.getType(), event.getContent())) return;
|
||||||
live.set(txnId, { event, room });
|
live.set(txnId, { event, room });
|
||||||
if (event.status === EventStatus.NOT_SENT) scheduleBlipRetry(event);
|
if (event.status === EventStatus.NOT_SENT) scheduleBlipRetry(event);
|
||||||
persist(
|
persist((list) =>
|
||||||
withEntry(entries, {
|
withEntry(list, {
|
||||||
txnId,
|
txnId,
|
||||||
roomId: room.roomId,
|
roomId: room.roomId,
|
||||||
threadId: event.threadRootId ?? null,
|
threadId: event.threadRootId ?? null,
|
||||||
@@ -138,7 +143,7 @@ export function OutboxFeature() {
|
|||||||
// SENT, CANCELLED, or the remote echo replaced it (status null).
|
// SENT, CANCELLED, or the remote echo replaced it (status null).
|
||||||
live.delete(txnId);
|
live.delete(txnId);
|
||||||
autoRetries.delete(txnId);
|
autoRetries.delete(txnId);
|
||||||
persist(withoutEntry(entries, txnId));
|
persist((list) => withoutEntry(list, txnId));
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Re-send network failures, oldest first; a room stops at its first failure. */
|
/** Re-send network failures, oldest first; a room stops at its first failure. */
|
||||||
@@ -191,7 +196,7 @@ export function OutboxFeature() {
|
|||||||
return !!room && isDelivered(room, entry.txnId);
|
return !!room && isDelivered(room, entry.txnId);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
plan.drop.forEach((entry) => persist(withoutEntry(entries, entry.txnId)));
|
plan.drop.forEach((entry) => persist((list) => withoutEntry(list, entry.txnId)));
|
||||||
plan.restore.forEach((entry) => {
|
plan.restore.forEach((entry) => {
|
||||||
const room = mx.getRoom(entry.roomId);
|
const room = mx.getRoom(entry.roomId);
|
||||||
if (!room || live.has(entry.txnId)) return;
|
if (!room || live.has(entry.txnId)) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user