Prefetch adjacent emails while reading
This commit is contained in:
@@ -1788,6 +1788,34 @@ function _syncCardNavArrows(card) {
|
||||
if (next) next.disabled = !_findSiblingEmailCard(card, 1);
|
||||
}
|
||||
|
||||
const _emailReadPrefetching = new Set();
|
||||
|
||||
function _prefetchAdjacentEmails(card, count = 3) {
|
||||
if (!card || state._libFolder === '__scheduled__') return;
|
||||
const grid = card.closest('.doclib-grid');
|
||||
if (!grid) return;
|
||||
const cards = [...grid.querySelectorAll('.doclib-card[data-uid]')];
|
||||
const idx = cards.indexOf(card);
|
||||
if (idx === -1) return;
|
||||
const targets = [];
|
||||
for (let i = 1; i <= count; i++) {
|
||||
if (cards[idx + i]) targets.push(cards[idx + i]);
|
||||
}
|
||||
if (targets.length < count) {
|
||||
for (let i = 1; targets.length < count && cards[idx - i]; i++) targets.push(cards[idx - i]);
|
||||
}
|
||||
for (const target of targets) {
|
||||
const uid = target.dataset.uid;
|
||||
if (!uid) continue;
|
||||
const key = `${state._libAccountId || ''}|${state._libFolder}|${uid}`;
|
||||
if (_emailReadPrefetching.has(key)) continue;
|
||||
_emailReadPrefetching.add(key);
|
||||
fetch(`${API_BASE}/api/email/read/${encodeURIComponent(uid)}?folder=${encodeURIComponent(state._libFolder)}${_acct()}&mark_seen=false`)
|
||||
.catch(() => {})
|
||||
.finally(() => _emailReadPrefetching.delete(key));
|
||||
}
|
||||
}
|
||||
|
||||
async function _toggleCardPreview(card, em) {
|
||||
const grid = card.closest('.doclib-grid');
|
||||
|
||||
@@ -1843,6 +1871,7 @@ async function _toggleCardPreview(card, em) {
|
||||
|
||||
// Mark as read locally
|
||||
_syncEmailReadState(em.uid, true);
|
||||
_prefetchAdjacentEmails(card);
|
||||
|
||||
// Build the attachments wrap using the shared helper so the signature-
|
||||
// image filter (small inline PNGs/JPGs, Outlook image001 placeholders,
|
||||
|
||||
Reference in New Issue
Block a user