Email library: drop the 'Default' chip — pick an explicit account always

Bug: clicking the dot to change the server-side default account while
viewing 'Default' left a desynced state — the email list still showed
the OLD default's cached UIDs, but the server's default now pointed
at a different account. Opening any email used the visible UID +
account_id='' on the read endpoint, which resolved against the NEW
default account → wrong email content (or older mail entirely).

Fix: remove the 'Default' chip. _loadAccounts now auto-selects the
is_default account (or the first one) into state._libAccountId so the
list view + every per-email request always carries an explicit
account_id and can't desync from set-default.

The dot button still lives on each account chip for changing which
account the server treats as the default — but it no longer affects
which account the list is currently displaying.
This commit is contained in:
pewdiepie-archdaemon
2026-06-11 17:11:55 +09:00
parent 5d9d21f227
commit f2ccf8b21f
+14 -4
View File
@@ -1334,6 +1334,15 @@ async function _loadAccounts() {
const d = await r.json(); const d = await r.json();
state._libAccounts = d.accounts || []; state._libAccounts = d.accounts || [];
} catch (_) { state._libAccounts = []; } } catch (_) { state._libAccounts = []; }
// The 'Default' chip is gone — pick an explicit account so the email
// list and any per-email actions (open in new tab, mark read, etc.)
// always carry an account_id and can't desync from the server's
// is_default state.
if (!state._libAccountId && state._libAccounts.length) {
const def = state._libAccounts.find(a => a.is_default) || state._libAccounts[0];
state._libAccountId = def.id;
_publishActiveAccount();
}
_renderAccountsStrip(); _renderAccountsStrip();
} }
@@ -1342,10 +1351,11 @@ function _renderAccountsStrip() {
if (!strip) return; if (!strip) return;
strip.style.display = 'flex'; strip.style.display = 'flex';
const esc = s => String(s || '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;'); const esc = s => String(s || '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
const allActive = !state._libAccountId ? ' active' : ''; // The 'Default' chip caused desync bugs (changing the server-side
// 'Default' rather than 'All (default)' — this view shows the account // default via the dot while still on the cached 'default' view would
// marked is_default; cross-account aggregation is a separate feature. // open the wrong account's emails). Each account renders as its own
let html = `<button class="memory-toolbar-btn gallery-chip${allActive}" data-acc-id="">Default</button>`; // chip; the active one is selected explicitly via _loadAccounts.
let html = '';
// 6px dot — matches the sidebar notification-dot size. // 6px dot — matches the sidebar notification-dot size.
const _dotFilled = '<svg width="6" height="6" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="10"/></svg>'; const _dotFilled = '<svg width="6" height="6" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="10"/></svg>';
const _dotHollow = '<svg width="6" height="6" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3"><circle cx="12" cy="12" r="9"/></svg>'; const _dotHollow = '<svg width="6" height="6" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3"><circle cx="12" cy="12" r="9"/></svg>';