diff --git a/app/api/push/preview/route.ts b/app/api/push/preview/route.ts index 32c6bb08..2d18b44a 100644 --- a/app/api/push/preview/route.ts +++ b/app/api/push/preview/route.ts @@ -40,17 +40,53 @@ export async function GET(request: NextRequest) { return NextResponse.json({ error: 'Incomplete JMAP session' }, { status: 502 }); } - // Find the inbox, then pull the most recent unread message in it. We use - // a single batched JMAP request with back-references so this round-trip - // is one POST regardless of how many messages exist. + const inboxRes = await fetch(apiUrl, { + method: 'POST', + headers: { + Authorization: creds.authHeader, + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], + methodCalls: [ + [ + 'Mailbox/query', + { accountId, filter: { role: 'inbox' }, limit: 1 }, + 'mb', + ], + ], + }), + }); + + if (!inboxRes.ok) { + return NextResponse.json({ error: 'JMAP mailbox query failed' }, { status: 502 }); + } + + const inboxData = (await inboxRes.json()) as { + methodResponses: [string, Record, string][]; + }; + + const inboxBody = inboxData.methodResponses.find( + ([method]) => method === 'Mailbox/query', + )?.[1] as { ids?: string[] } | undefined; + + const inboxId = inboxBody?.ids?.[0]; + + if (!inboxId) { + return NextResponse.json({ + email: null, + unreadTotal: 0, + }, { + headers: { + 'Cache-Control': 'no-store', + }, + }); + } + + // Pull the most recent unread message from the resolved Inbox mailbox. const requestBody = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ - [ - 'Mailbox/query', - { accountId, filter: { role: 'inbox' }, limit: 1 }, - 'mb', - ], [ 'Email/query', { @@ -58,7 +94,7 @@ export async function GET(request: NextRequest) { filter: { operator: 'AND', conditions: [ - { inMailbox: { resultOf: 'mb', name: 'Mailbox/query', path: '/ids/0' } }, + { inMailbox: inboxId }, { notKeyword: '$seen' }, ], }, diff --git a/components/email/email-list.tsx b/components/email/email-list.tsx index bcafc915..d37c3c68 100644 --- a/components/email/email-list.tsx +++ b/components/email/email-list.tsx @@ -283,7 +283,7 @@ export function EmailList({
- {selectedEmailIds.size} {selectedEmailIds.size === 1 ? 'email' : 'emails'} selected + {t('batch_actions.selected_messages', { count: selectedEmailIds.size })}
@@ -338,7 +338,7 @@ export function EmailList({ disabled={isProcessing} className="text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50" > - Cancel + {t('batch_actions.clear_selection')}
diff --git a/locales/cs/common.json b/locales/cs/common.json index e6c0b6b4..1e85c39c 100644 --- a/locales/cs/common.json +++ b/locales/cs/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "Vybrat zprávy", "select_all": "Vybrat vše", + "selected_messages": "{count, plural, one {Vybraný 1 e-mail} other {Vybrané # e-maily}}", "mark_read": "Označit jako přečtené", "mark_unread": "Označit jako nepřečtené", "delete": "Odstranit", diff --git a/locales/de/common.json b/locales/de/common.json index 5c938227..0f1d6b54 100644 --- a/locales/de/common.json +++ b/locales/de/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "E-Mails auswählen", "select_all": "Alle auswählen", + "selected_messages": "{count, plural, one {1 E-Mail} other {# E-Mails}} ausgewählt", "mark_read": "Als gelesen markieren", "mark_unread": "Als ungelesen markieren", "delete": "Löschen", diff --git a/locales/en/common.json b/locales/en/common.json index 47d1fa68..0f3f3037 100644 --- a/locales/en/common.json +++ b/locales/en/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "Select emails", "select_all": "Select all", + "selected_messages": "{count, plural, one {1 email} other {# emails}} selected", "mark_read": "Mark as read", "mark_unread": "Mark as unread", "delete": "Delete", diff --git a/locales/es/common.json b/locales/es/common.json index 10cbdd07..dc1f21e9 100644 --- a/locales/es/common.json +++ b/locales/es/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "Seleccionar correos", "select_all": "Seleccionar todo", + "selected_messages": "{count, plural, one {1 correo electrónico seleccionado} other {# correos electrónicos seleccionados}}", "mark_read": "Marcar como leído", "mark_unread": "Marcar como no leído", "delete": "Eliminar", diff --git a/locales/fr/common.json b/locales/fr/common.json index c4857487..dcc95efc 100644 --- a/locales/fr/common.json +++ b/locales/fr/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "Sélectionner les e-mails", "select_all": "Tout sélectionner", + "selected_messages": "{count, plural, one {1 e-mail sélectionné} other {# e-mails sélectionnés}}", "mark_read": "Marquer comme lu", "mark_unread": "Marquer comme non lu", "delete": "Supprimer", diff --git a/locales/it/common.json b/locales/it/common.json index dc1f082c..38ea645a 100644 --- a/locales/it/common.json +++ b/locales/it/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "Seleziona e-mail", "select_all": "Seleziona tutto", + "selected_messages": "{count} email {count, plural, one {selezionata} other {selezionate}}", "mark_read": "Segna come letto", "mark_unread": "Segna come non letto", "delete": "Elimina", diff --git a/locales/ja/common.json b/locales/ja/common.json index e67fa936..c8a17a3a 100644 --- a/locales/ja/common.json +++ b/locales/ja/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "メールを選択", "select_all": "すべて選択", + "selected_messages": "{count, plural, one {1} other {#}}通のメールが選択されました", "mark_read": "既読にする", "mark_unread": "未読にする", "delete": "削除", diff --git a/locales/ko/common.json b/locales/ko/common.json index 7c00e835..4e8f3235 100644 --- a/locales/ko/common.json +++ b/locales/ko/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "메일 선택", "select_all": "모두 선택", + "selected_messages": "이메일 {count, plural, one {1개} other {#건}} 선택됨", "mark_read": "읽은 상태로 표시", "mark_unread": "읽지 않은 상태로 표시", "delete": "삭제", diff --git a/locales/lv/common.json b/locales/lv/common.json index 7abb64d6..0e9c2f31 100644 --- a/locales/lv/common.json +++ b/locales/lv/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "Atlasīt vēstules", "select_all": "Atlasīt visas", + "selected_messages": "{count, plural, one {Izvēlēta 1 e-pasta vēstule} other {Izvēlētas # e-pasta vēstules}}", "mark_read": "Atzīmēt kā izlasītu", "mark_unread": "Atzīmēt kā nelasītu", "delete": "Dzēst", diff --git a/locales/nl/common.json b/locales/nl/common.json index d752be42..bbd41291 100644 --- a/locales/nl/common.json +++ b/locales/nl/common.json @@ -185,6 +185,7 @@ "select": "E-mails selecteren", "select_all": "Alles selecteren", "mark_read": "Markeren als gelezen", + "selected_messages": "{count, plural, one {1 e-mail} other {# e-mails}} geselecteerd", "mark_unread": "Markeren als ongelezen", "delete": "Verwijderen", "delete_confirm_title": "E-mails verwijderen", diff --git a/locales/pl/common.json b/locales/pl/common.json index b8245b42..94b1952a 100644 --- a/locales/pl/common.json +++ b/locales/pl/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "Zaznacz wiadomości", "select_all": "Zaznacz wszystkie", + "selected_messages": "Wybrano {count, plural, one {1 wiadomość} other {# wiadomości}} e-mail", "mark_read": "Oznacz jako przeczytane", "mark_unread": "Oznacz jako nieprzeczytane", "delete": "Usuń", diff --git a/locales/pt/common.json b/locales/pt/common.json index df87b588..982e2852 100644 --- a/locales/pt/common.json +++ b/locales/pt/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "Selecionar e-mails", "select_all": "Selecionar tudo", + "selected_messages": "{count, plural, one {1 e-mail selecionado} other {# e-mails selecionados}}", "mark_read": "Marcar como lido", "mark_unread": "Marcar como não lido", "delete": "Excluir", diff --git a/locales/ru/common.json b/locales/ru/common.json index 609af525..aca594f9 100644 --- a/locales/ru/common.json +++ b/locales/ru/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "Выбрать письма", "select_all": "Выбрать все", + "selected_messages": "Выбрано {count, plural, one {1 письмо} other {# письма}}", "mark_read": "Отметить прочитанными", "mark_unread": "Отметить непрочитанными", "delete": "Удалить", diff --git a/locales/tr/common.json b/locales/tr/common.json index 5d8baa16..4c15473f 100644 --- a/locales/tr/common.json +++ b/locales/tr/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "E-postaları seç", "select_all": "Tümünü seç", + "selected_messages": "{count, plural, one {1 e-posta} other {# e-posta}} seçildi", "mark_read": "Okundu olarak işaretle", "mark_unread": "Okunmadı olarak işaretle", "delete": "Sil", diff --git a/locales/uk/common.json b/locales/uk/common.json index 20d15cc1..d1856e7d 100644 --- a/locales/uk/common.json +++ b/locales/uk/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "Виберіть електронні листи", "select_all": "Вибрати все", + "selected_messages": "Вибрано {count, plural, one {1 електронний лист} other {# електронні листи}}", "mark_read": "Позначити як прочитане", "mark_unread": "Позначити як непрочитане", "delete": "Видалити", diff --git a/locales/zh/common.json b/locales/zh/common.json index 28432a26..36dc53fb 100644 --- a/locales/zh/common.json +++ b/locales/zh/common.json @@ -184,6 +184,7 @@ "batch_actions": { "select": "选择邮件", "select_all": "全选", + "selected_messages": "已選取 {count, plural, one {1} other {#}} 封電子郵件", "mark_read": "标记为已读", "mark_unread": "标记为未读", "delete": "删除",