支持私聊消息加密转发到群聊

This commit is contained in:
xhgit committed 2026-11-14 14:52:22 +08:00
1 parent 20e179a877
commit 9028ba0eed
8 files changed
+99 -62

No files matched your search

+20 -45
View File
@@ -2,8 +2,11 @@
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useSession } from '../session'
import { directory, enableChat, forwardMessage, localMessageAction, markRead, mutateMessage, recentConversations, send, setReadReceipts, synchronize, trust } from '../chat/chat'
import type { ChatLine, Peer } from '../chat/chat'
import { enableChat, localMessageAction, markRead, mutateMessage, readPrivateForward, recentConversations, send, setReadReceipts, synchronize, trust } from '../chat/chat'
import type { ChatLine } from '../chat/chat'
import { forwardContent } from '../chat/group-chat'
import type { ForwardDestination } from '../chat/group-chat'
import ForwardDialog from '../chat/ForwardDialog.vue'
import type { Contact } from '../contacts'
import { downloadAttachment } from '../chat/attachments'
import type { Attachment } from '../chat/attachments'
@@ -24,10 +27,7 @@ const deleting = ref<ChatLine>()
const editing = ref<ChatLine>()
const recalling = ref<ChatLine>()
const forwarding = ref<ChatLine>()
const destinations = ref<Contact[]>([])
const destination = ref('')
const destinationDevice = ref('')
const forwardDevices = ref<Peer[]>([])
const forwardStatus = ref('')
const error = ref('')
const busy = ref(false)
const contacts = ref<Contact[]>([])
@@ -249,31 +249,18 @@ function localAction(line: ChatLine, action: 'favorite' | 'remove') {
}
function beginForward(line: ChatLine) {
void execute(async () => {
destinations.value = (await session.contacts()).filter((contact) => contact.state === 'friend')
destination.value = ''
destinationDevice.value = ''
forwardDevices.value = []
forwarding.value = line
})
forwardStatus.value = ''
forwarding.value = line
}
function loadForwardDevices() {
destinationDevice.value = ''
forwardDevices.value = []
if (!destination.value) return
void execute(async () => {
const devices = await directory(session.authorized, destination.value)
forwardDevices.value = devices.filter((device) => device.mls && view.value?.pinned[device.id] === device.publicKey)
destinationDevice.value = forwardDevices.value[0]?.id ?? ''
})
}
function submitForward() {
void execute(async () => {
const device = forwardDevices.value.find((candidate) => candidate.id === destinationDevice.value)
if (!session.identity || !forwarding.value || !device) return
await forwardMessage(session.identity, forwarding.value, destination.value, device, session.authorized)
function submitForward(destination: ForwardDestination) {
const identity = session.identity
const message = forwarding.value
if (identity && message) void execute(async () => {
const status = await forwardContent(identity, destination, session.authorized,
() => readPrivateForward(identity, message, session.authorized))
if (forwarding.value !== message) return
forwardStatus.value = status
forwarding.value = undefined
await refresh()
})
@@ -298,6 +285,7 @@ watch(selected, () => {
editing.value = undefined
recalling.value = undefined
forwarding.value = undefined
forwardStatus.value = ''
pendingVoice.value = undefined
draft.value = ''
scheduleReceipt()
@@ -336,6 +324,7 @@ onBeforeUnmount(() => {
</aside>
<div class="device-content chat-page">
<p v-if="error" class="error" role="alert">{{ error }}</p>
<p v-if="forwardStatus" role="status">{{ forwardStatus }}</p>
<button v-if="!ownCode" type="button" class="primary" :disabled="busy" @click="enable">启用本机加密聊天</button>
<template v-else>
<details open>
@@ -405,22 +394,8 @@ onBeforeUnmount(() => {
<button type="button" class="plain" :disabled="busy" @click="recall">确认撤回</button>
<button type="button" class="plain" @click="recalling = undefined">取消</button>
</div>
<form v-if="forwarding" class="contact-preferences confirmation" @submit.prevent="submitForward">
<label>转发给
<select v-model="destination" :disabled="busy" @change="loadForwardDevices">
<option value="">选择联系人</option>
<option v-for="contact in destinations" :key="contact.id" :value="contact.id">{{ contact.alias || contact.username }}</option>
</select>
</label>
<label v-if="forwardDevices.length">接收设备
<select v-model="destinationDevice" :disabled="busy">
<option v-for="device in forwardDevices" :key="device.id" :value="device.id">{{ device.name }}</option>
</select>
</label>
<p v-else-if="destination && !busy" class="muted">请先在对方聊天中核验接收设备。</p>
<button class="primary" :disabled="busy || !destinationDevice">确认转发</button>
<button type="button" class="plain" :disabled="busy" @click="forwarding = undefined">取消</button>
</form>
<ForwardDialog v-if="forwarding && view" :key="[forwarding.peer, forwarding.id, forwarding.own].join('/')"
:pinned="view.pinned" :busy="busy" @confirm="submitForward" @cancel="forwarding = undefined" />
<form class="chat-compose" @submit.prevent="submit">
<div v-if="editing" class="chat-quote">
<span>正在编辑消息</span>