Пометить все сообщения в папке как прочитанные
All checks were successful
Release / release (push) Successful in 2m45s

This commit is contained in:
vodyanoysh 2026-07-30 00:20:11 +07:00
parent 6dc7dde3f2
commit 46227b27f6
8 changed files with 67 additions and 1 deletions

View file

@ -88,6 +88,12 @@ export function registerMessageHandlers(manager: AccountManager): void {
await manager.deleteMessages(accountId, folderId, messageIds)
})
registerHandler('messages:markAllRead', async ({ accountId, folderId }) => {
assertId(accountId, 'accountId')
assertId(folderId, 'folderId')
await manager.markAllRead(accountId, folderId)
})
registerHandler('messages:attachment:download', async ({ accountId, folderId, messageId, attachmentId, filename, downloadFolder }) => {
try {
sendProgress(attachmentId, 'downloading', 10)

View file

@ -284,6 +284,17 @@ export class ImapProvider implements IEmailProvider {
}
}
async markAllRead(folderId: string): Promise<void> {
const lock = await this.client.getMailboxLock(folderId)
try {
const uids = await this.client.search({ seen: false }, { uid: true }) as number[]
if (!uids || uids.length === 0) return
await this.client.messageFlagsAdd(uids.join(','), ['\\Seen'], { uid: true })
} finally {
lock.release()
}
}
async deleteMessages(folderId: string, messageIds: string[]): Promise<void> {
const lock = await this.client.getMailboxLock(folderId)
try {

View file

@ -210,6 +210,12 @@ export class AccountManager {
)
}
async markAllRead(accountId: string, folderId: string): Promise<void> {
return this.withAutoReconnect(accountId, () =>
this.getProvider(accountId).markAllRead(folderId)
)
}
// ── Calendar ────────────────────────────────────────────
async listCalendars(accountId: string): Promise<CalendarInfo[]> {

View file

@ -14,6 +14,7 @@ const emit = defineEmits<{
close: []
mute: [durationMs: number | null]
unmute: []
markAllRead: []
}>()
const menuEl = ref<HTMLElement | null>(null)
@ -37,6 +38,10 @@ function handleUnmute(): void {
emit('unmute')
}
function handleMarkAllRead(): void {
emit('markAllRead')
}
function onMouseDown(e: MouseEvent): void {
if (menuEl.value && !menuEl.value.contains(e.target as Node)) {
emit('close')
@ -70,6 +75,12 @@ onUnmounted(() => {
class="context-menu"
:style="{ left: menuX + 'px', top: menuY + 'px' }"
>
<button class="menu-item" @click="handleMarkAllRead">
Отметить всё как прочитанное
</button>
<div class="menu-divider" />
<!-- Unmute if already muted -->
<button v-if="isMuted" class="menu-item" @click="handleUnmute">
Включить уведомления
@ -152,6 +163,12 @@ onUnmounted(() => {
background: rgba(255, 255, 255, 0.05);
}
.menu-divider {
height: 1px;
margin: 4px 6px;
background: rgba(255, 255, 255, 0.10);
}
.menu-item-submenu {
position: relative;
}

View file

@ -5,6 +5,7 @@ import { SpecialFolderRole } from '@shared/types/folder'
import { useFoldersStore } from '../../stores/folders.store'
import { useAccountsStore } from '../../stores/accounts.store'
import { useNotificationsStore } from '../../stores/notifications.store'
import { useMessagesStore } from '../../stores/messages.store'
import AppIcon from '../AppIcon.vue'
import type { IconName } from '../AppIcon.vue'
import FolderContextMenu from './FolderContextMenu.vue'
@ -17,6 +18,7 @@ const props = defineProps<{
const foldersStore = useFoldersStore()
const accountsStore = useAccountsStore()
const notificationsStore = useNotificationsStore()
const messagesStore = useMessagesStore()
const expanded = ref(true)
const contextMenu = ref<{ x: number; y: number } | null>(null)
@ -74,6 +76,13 @@ function handleUnmute(): void {
}
contextMenu.value = null
}
function handleMarkAllRead(): void {
if (accountsStore.activeAccountId) {
messagesStore.markAllRead(accountsStore.activeAccountId, props.folder.id)
}
contextMenu.value = null
}
</script>
<template>
@ -114,6 +123,7 @@ function handleUnmute(): void {
@close="closeContextMenu"
@mute="handleMute"
@unmute="handleUnmute"
@mark-all-read="handleMarkAllRead"
/>
<div v-if="hasChildren && expanded" class="folder-children">

View file

@ -278,6 +278,16 @@ export const useMessagesStore = defineStore('messages', () => {
)
}
async function markAllRead(accountId: string, folderId: string): Promise<void> {
await invoke('messages:markAllRead', { accountId, folderId })
if (accountsStore.activeAccountId === accountId && foldersStore.activeFolderId === folderId) {
for (const msg of messages.value) {
msg.flags.seen = true
}
}
foldersStore.setFolderUnread(accountId, folderId, 0)
}
async function toggleFlag(messageId: string): Promise<void> {
if (!accountsStore.activeAccountId || !foldersStore.activeFolderId) return
const msg = messages.value.find((m) => m.id === messageId)
@ -428,6 +438,7 @@ export const useMessagesStore = defineStore('messages', () => {
deleteOne,
toggleRead,
toggleFlag,
flagSelected
flagSelected,
markAllRead
}
})

View file

@ -29,6 +29,10 @@ export interface IpcChannelMap {
{ accountId: string; folderId: string; messageIds: string[] },
void
]
'messages:markAllRead': [
{ accountId: string; folderId: string },
void
]
'messages:attachment:download': [
{ accountId: string; folderId: string; messageId: string; attachmentId: string; filename: string; downloadFolder?: string },
{ success: boolean; savedPath?: string; error?: string }

View file

@ -27,6 +27,7 @@ export interface IEmailProvider {
fetchMessageBody(folderId: string, messageId: string): Promise<MessageBody>
downloadAttachment(folderId: string, messageId: string, attachmentId: string): Promise<Buffer>
updateFlags(folderId: string, messageIds: string[], flags: Partial<MessageFlags>): Promise<void>
markAllRead(folderId: string): Promise<void>
deleteMessages(folderId: string, messageIds: string[]): Promise<void>
onNewMail(callback: (folderId: string, envelope: MessageEnvelope) => void): void
offNewMail(): void