Пометить тред как прочитанный
All checks were successful
Release / release (push) Successful in 2m43s
All checks were successful
Release / release (push) Successful in 2m43s
This commit is contained in:
parent
b1c5929565
commit
d46c6562ee
3 changed files with 172 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ import { useComposeStore } from '../../stores/compose.store'
|
||||||
import { useIpc } from '../../composables/useIpc'
|
import { useIpc } from '../../composables/useIpc'
|
||||||
import MessageListItem from './MessageListItem.vue'
|
import MessageListItem from './MessageListItem.vue'
|
||||||
import ThreadListItem from './ThreadListItem.vue'
|
import ThreadListItem from './ThreadListItem.vue'
|
||||||
|
import ThreadContextMenu from './ThreadContextMenu.vue'
|
||||||
import AppIcon from '../AppIcon.vue'
|
import AppIcon from '../AppIcon.vue'
|
||||||
import { buildThreads, type Thread } from '../../utils/threading'
|
import { buildThreads, type Thread } from '../../utils/threading'
|
||||||
import type { MessageEnvelope } from '@shared/types/message'
|
import type { MessageEnvelope } from '@shared/types/message'
|
||||||
|
|
@ -170,6 +171,25 @@ function getThreadMessages(thread: Thread): import('@shared/types/message').Mess
|
||||||
return desc ? [...msgs].reverse() : [...msgs]
|
return desc ? [...msgs].reverse() : [...msgs]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Контекстное меню треда ────────────────────────────────
|
||||||
|
const threadContextMenu = ref<{ x: number; y: number; thread: Thread } | null>(null)
|
||||||
|
|
||||||
|
function handleThreadContextMenu(event: MouseEvent, thread: Thread): void {
|
||||||
|
event.preventDefault()
|
||||||
|
threadContextMenu.value = { x: event.clientX, y: event.clientY, thread }
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeThreadContextMenu(): void {
|
||||||
|
threadContextMenu.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleMarkThreadRead(seen: boolean): Promise<void> {
|
||||||
|
if (!threadContextMenu.value || !foldersStore.activeFolderId) return
|
||||||
|
const uids = threadContextMenu.value.thread.messages.map((m) => m.id)
|
||||||
|
await messagesStore.markThreadRead(uids, foldersStore.activeFolderId, seen)
|
||||||
|
threadContextMenu.value = null
|
||||||
|
}
|
||||||
|
|
||||||
// ── Thread expand animation ───────────────────────────────
|
// ── Thread expand animation ───────────────────────────────
|
||||||
function onExpandEnter(el: Element, done: () => void): void {
|
function onExpandEnter(el: Element, done: () => void): void {
|
||||||
const h = el as HTMLElement
|
const h = el as HTMLElement
|
||||||
|
|
@ -522,6 +542,7 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis
|
||||||
v-else
|
v-else
|
||||||
class="thread-group"
|
class="thread-group"
|
||||||
:class="{ 'thread-group--open': expandedThreadIds.has(thread.id) }"
|
:class="{ 'thread-group--open': expandedThreadIds.has(thread.id) }"
|
||||||
|
@contextmenu.prevent="(e: MouseEvent) => handleThreadContextMenu(e, thread)"
|
||||||
>
|
>
|
||||||
<ThreadListItem
|
<ThreadListItem
|
||||||
:thread="thread"
|
:thread="thread"
|
||||||
|
|
@ -575,6 +596,16 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<ThreadContextMenu
|
||||||
|
v-if="threadContextMenu"
|
||||||
|
:x="threadContextMenu.x"
|
||||||
|
:y="threadContextMenu.y"
|
||||||
|
:has-unread="threadContextMenu.thread.unreadCount > 0"
|
||||||
|
@close="closeThreadContextMenu"
|
||||||
|
@mark-read="handleMarkThreadRead(true)"
|
||||||
|
@mark-unread="handleMarkThreadRead(false)"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
118
src/renderer/src/components/messages/ThreadContextMenu.vue
Normal file
118
src/renderer/src/components/messages/ThreadContextMenu.vue
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, onMounted, onUnmounted } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
x: number
|
||||||
|
y: number
|
||||||
|
hasUnread: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
close: []
|
||||||
|
markRead: []
|
||||||
|
markUnread: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const menuEl = ref<HTMLElement | null>(null)
|
||||||
|
const menuX = ref(props.x)
|
||||||
|
const menuY = ref(props.y)
|
||||||
|
|
||||||
|
function handleMarkRead(): void {
|
||||||
|
emit('markRead')
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleMarkUnread(): void {
|
||||||
|
emit('markUnread')
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMouseDown(e: MouseEvent): void {
|
||||||
|
if (menuEl.value && !menuEl.value.contains(e.target as Node)) {
|
||||||
|
emit('close')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
document.addEventListener('mousedown', onMouseDown)
|
||||||
|
|
||||||
|
// Clamp position to viewport
|
||||||
|
if (menuEl.value) {
|
||||||
|
const rect = menuEl.value.getBoundingClientRect()
|
||||||
|
if (props.x + rect.width > window.innerWidth) {
|
||||||
|
menuX.value = Math.max(0, props.x - rect.width)
|
||||||
|
}
|
||||||
|
if (props.y + rect.height > window.innerHeight) {
|
||||||
|
menuY.value = Math.max(0, props.y - rect.height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
document.removeEventListener('mousedown', onMouseDown)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Teleport to="body">
|
||||||
|
<div
|
||||||
|
ref="menuEl"
|
||||||
|
class="context-menu"
|
||||||
|
:style="{ left: menuX + 'px', top: menuY + 'px' }"
|
||||||
|
>
|
||||||
|
<button v-if="hasUnread" class="menu-item" @click="handleMarkRead">
|
||||||
|
Пометить тред как прочитанный
|
||||||
|
</button>
|
||||||
|
<button v-else class="menu-item" @click="handleMarkUnread">
|
||||||
|
Пометить тред как непрочитанный
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</Teleport>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.context-menu {
|
||||||
|
position: fixed;
|
||||||
|
z-index: 99999;
|
||||||
|
min-width: 200px;
|
||||||
|
border-radius: 12px;
|
||||||
|
background:
|
||||||
|
linear-gradient(145deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.03) 100%),
|
||||||
|
rgba(14, 14, 22, 0.82);
|
||||||
|
backdrop-filter: blur(40px) saturate(2);
|
||||||
|
-webkit-backdrop-filter: blur(40px) saturate(2);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||||
|
box-shadow:
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.18),
|
||||||
|
0 8px 32px rgba(0, 0, 0, 0.55),
|
||||||
|
0 2px 8px rgba(0, 0, 0, 0.35);
|
||||||
|
padding: 4px;
|
||||||
|
animation: menu-in 140ms cubic-bezier(0.34, 1.15, 0.64, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes menu-in {
|
||||||
|
from { opacity: 0; transform: scale(0.95) translateY(-4px); }
|
||||||
|
to { opacity: 1; transform: scale(1) translateY(0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
width: 100%;
|
||||||
|
padding: 7px 12px;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
text-align: left;
|
||||||
|
transition: background var(--transition-fast), color var(--transition-fast);
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-item:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.08);
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-item:active {
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -320,6 +320,27 @@ export const useMessagesStore = defineStore('messages', () => {
|
||||||
selectedIds.value = new Set()
|
selectedIds.value = new Set()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function markThreadRead(uids: string[], folderId: string, seen: boolean): Promise<void> {
|
||||||
|
if (!accountsStore.activeAccountId) return
|
||||||
|
await invoke('messages:setFlags', {
|
||||||
|
accountId: accountsStore.activeAccountId,
|
||||||
|
folderId,
|
||||||
|
messageIds: uids,
|
||||||
|
flags: { seen }
|
||||||
|
})
|
||||||
|
const uidSet = new Set(uids)
|
||||||
|
let delta = 0
|
||||||
|
for (const msg of messages.value) {
|
||||||
|
if (uidSet.has(msg.id) && msg.flags.seen !== seen) {
|
||||||
|
delta += seen ? -1 : 1
|
||||||
|
msg.flags.seen = seen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (delta !== 0) {
|
||||||
|
foldersStore.updateFolderUnread(accountsStore.activeAccountId, folderId, delta)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function markSelectedAsRead(): Promise<void> {
|
async function markSelectedAsRead(): Promise<void> {
|
||||||
if (!accountsStore.activeAccountId || !foldersStore.activeFolderId || selectedIds.value.size === 0) return
|
if (!accountsStore.activeAccountId || !foldersStore.activeFolderId || selectedIds.value.size === 0) return
|
||||||
const ids = [...selectedIds.value]
|
const ids = [...selectedIds.value]
|
||||||
|
|
@ -439,6 +460,7 @@ export const useMessagesStore = defineStore('messages', () => {
|
||||||
toggleRead,
|
toggleRead,
|
||||||
toggleFlag,
|
toggleFlag,
|
||||||
flagSelected,
|
flagSelected,
|
||||||
markAllRead
|
markAllRead,
|
||||||
|
markThreadRead
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue