Refractoring Stage 6.5 Migrated the snooze, attachment, and OpenPGP mail UI to the explicit mail feature API.

This commit is contained in:
2026-10-16 20:31:59 +03:00
parent f19573a337
commit 84a63441ef
14 changed files with 178 additions and 108 deletions
+21 -23
View File
@@ -16,10 +16,10 @@ function nextMorning(daysAhead) {
function openSnoozeDialog(items) {
const eligible = items.filter(message => message?.uid && mailUi.connectedAccount);
if (!eligible.length) {
toast('Snoozing is available for messages in a connected mailbox.');
mailUi.toast('Snoozing is available for messages in a connected mailbox.');
return;
}
const root = $('#modal-root');
const root = mailUi.select('#modal-root');
const tomorrow = nextMorning(1);
const laterToday = new Date(Date.now() + 3 * 60 * 60 * 1000);
root.innerHTML = `<div class="modal-overlay"><div class="compose-modal"><div class="modal-head"><span>${eligible.length === 1 ? 'Snooze message' : `Snooze ${eligible.length} messages`}</span><button class="modal-close" aria-label="Close">×</button></div><div class="compose-fields"><p class="account-note">The message will be hidden in ep-mail until then; the server copy remains in place.</p><div class="snooze-options" style="display:grid;gap:8px;padding:10px 0"><button class="outline-button" data-snooze-at="${laterToday.getTime()}">In 3 hours · ${laterToday.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })}</button><button class="outline-button" data-snooze-at="${tomorrow.getTime()}">Tomorrow · 9:00 AM</button><button class="outline-button" data-snooze-at="${nextMorning(7).getTime()}">Next week · 9:00 AM</button></div><label class="compose-line"><span>Custom reminder</span><input id="snooze-custom-time" type="datetime-local" value="${localDateTimeValue(tomorrow)}"></label><p id="snooze-status" class="account-status" aria-live="polite"></p></div><div class="compose-footer"><button class="discard modal-close">Cancel</button><button class="send-button" id="snooze-custom">Set reminder</button></div></div></div>`;
@@ -31,7 +31,7 @@ function openSnoozeDialog(items) {
const schedule = async dueAt => {
if (!Number.isFinite(dueAt) || dueAt <= Date.now()) {
$('#snooze-status').textContent = 'Choose a reminder time in the future.';
mailUi.select('#snooze-status').textContent = 'Choose a reminder time in the future.';
return;
}
const buttons = [...root.querySelectorAll('button')];
@@ -49,11 +49,11 @@ function openSnoozeDialog(items) {
});
}
close();
toast(eligible.length === 1 ? 'Message snoozed' : `${eligible.length} messages snoozed`);
mailUi.toast(eligible.length === 1 ? 'Message snoozed' : `${eligible.length} messages snoozed`);
mailUi.state.selectedIds.clear();
await mailUi.syncMailbox(false, { offset: 0 });
} catch (error) {
$('#snooze-status').textContent = error.message || 'Could not set the reminder.';
mailUi.select('#snooze-status').textContent = error.message || 'Could not set the reminder.';
buttons.forEach(button => { button.disabled = false; });
}
};
@@ -61,8 +61,8 @@ function openSnoozeDialog(items) {
root.querySelectorAll('[data-snooze-at]').forEach(button => {
button.onclick = () => schedule(Number(button.dataset.snoozeAt));
});
$('#snooze-custom').onclick = () => schedule(new Date($('#snooze-custom-time').value).getTime());
$('#snooze-custom-time').focus();
mailUi.select('#snooze-custom').onclick = () => schedule(new Date(mailUi.select('#snooze-custom-time').value).getTime());
mailUi.select('#snooze-custom-time').focus();
}
function unsnoozeMessage(message) {
@@ -72,13 +72,13 @@ function unsnoozeMessage(message) {
sourceFolder,
dueAt: null
}).then(async () => {
toast('Message returned to its mailbox');
mailUi.toast('Message returned to its mailbox');
await mailUi.syncMailbox(false, { offset: 0 });
}).catch(error => toast(error.message || 'Could not return the message'));
}).catch(error => mailUi.toast(error.message || 'Could not return the message'));
}
function showMessageActions(message) {
const root = $('#modal-root');
const root = mailUi.select('#modal-root');
root.innerHTML = `<div class="modal-overlay"><div class="compose-modal"><div class="modal-head"><span>Message actions</span><button class="modal-close" aria-label="Close">×</button></div><div class="compose-fields snooze-options" style="display:grid;gap:8px;padding-bottom:16px"><button class="outline-button" data-message-action="unread">Mark unread</button><button class="outline-button" data-message-action="snooze">Snooze</button><button class="outline-button" data-message-action="label">Add label</button><button class="outline-button" data-message-action="inbox">Move to Inbox</button></div></div></div>`;
root.querySelectorAll('.modal-close').forEach(button => button.onclick = () => { root.innerHTML = ''; });
root.querySelector('.modal-overlay').onclick = event => {
@@ -86,8 +86,7 @@ function showMessageActions(message) {
};
}
const renderListBeforeSnooze = mailUi.renderList;
renderList = function () {
mailUi.wrapRenderList(renderListBeforeSnooze => function () {
if (mailUi.state.activeFolder === 'Snoozed') {
const originalMessages = mailUi.state.messages.slice();
const snoozedMessages = mailUi.state.messages.filter(message => message.snoozedUntil);
@@ -103,7 +102,7 @@ renderList = function () {
message.deleted = deleted;
});
mailUi.state.messages.splice(0, mailUi.state.messages.length, ...originalMessages);
for (const row of $$('.message')) {
for (const row of mailUi.selectAll('.message')) {
const message = mailUi.state.messages.find(item => item.id === Number(row.dataset.id));
if (!message?.snoozedUntil) continue;
const due = new Date(message.snoozedUntil);
@@ -113,21 +112,20 @@ renderList = function () {
}
return;
}
renderListBeforeSnooze();
};
return renderListBeforeSnooze();
});
const openMessageBeforeSnooze = mailUi.openMessage;
openMessage = function (id) {
mailUi.wrapOpenMessage(openMessageBeforeSnooze => function (id) {
openMessageBeforeSnooze(id);
const message = mailUi.state.messages.find(item => item.id === id);
const tools = $('.reader-tools');
const tools = mailUi.select('.reader-tools');
if (!message || !tools) return;
const snoozed = mailUi.state.activeFolder === 'Snoozed';
tools.insertAdjacentHTML('afterbegin', `<button class="icon-button" id="${snoozed ? 'reader-unsnooze' : 'reader-snooze'}" title="${snoozed ? 'Return to inbox' : 'Snooze'}">${snoozed ? '↩' : '◷'}</button>`);
};
});
document.addEventListener('DOMContentLoaded', () => {
$('#mark-unread').insertAdjacentHTML('afterend', '<button class="icon-button" id="snooze-selected" title="Snooze selected messages">◷</button>');
mailUi.select('#mark-unread').insertAdjacentHTML('afterend', '<button class="icon-button" id="snooze-selected" title="Snooze selected messages">◷</button>');
if (window.daybreakMail?.checkSnoozeReminders) {
const checkReminders = () => window.daybreakMail.checkSnoozeReminders()
.catch(error => console.error('Could not check mail reminders:', error));
@@ -146,7 +144,7 @@ document.addEventListener('click', event => {
event.stopImmediatePropagation();
if (action) {
const message = mailUi.state.messages.find(item => item.id === mailUi.state.activeMessage);
$('#modal-root').innerHTML = '';
mailUi.select('#modal-root').innerHTML = '';
if (!message) return;
if (action.dataset.messageAction === 'snooze') openSnoozeDialog([message]);
else if (action.dataset.messageAction === 'label') addMessageLabel(message);
@@ -156,8 +154,8 @@ document.addEventListener('click', event => {
if (type === 'unread') message.unread = true;
if (type === 'inbox') message.archived = false;
mailUi.renderList();
toast(type === 'unread' ? 'Marked unread' : 'Moved to Inbox');
}).catch(error => toast(error.message || 'Could not update the message'));
mailUi.toast(type === 'unread' ? 'Marked unread' : 'Moved to Inbox');
}).catch(error => mailUi.toast(error.message || 'Could not update the message'));
}
return;
}