支持向已核验设备加密转发文字和附件

This commit is contained in:
xhgit committed 2026-11-13 19:28:24 +08:00
1 parent f5f116a266
commit 0b89634af2
6 files changed
+81 -6

No files matched your search

+57 -2
View File
@@ -2,8 +2,9 @@
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useSession } from '../session'
import { enableChat, localMessageAction, mutateMessage, send, synchronize, trust } from '../chat/chat'
import type { ChatLine } from '../chat/chat'
import { directory, enableChat, forwardMessage, localMessageAction, mutateMessage, send, synchronize, trust } from '../chat/chat'
import type { ChatLine, Peer } from '../chat/chat'
import type { Contact } from '../contacts'
import { downloadAttachment } from '../chat/attachments'
import type { Attachment } from '../chat/attachments'
@@ -19,6 +20,11 @@ const reply = ref<ChatLine>()
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 error = ref('')
const busy = ref(false)
const view = ref<Awaited<ReturnType<typeof synchronize>>>()
@@ -130,6 +136,37 @@ 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
})
}
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)
forwarding.value = undefined
await refresh()
})
}
function sync() {
if (ownCode.value) void execute(refresh)
}
@@ -148,6 +185,7 @@ watch(selected, () => {
deleting.value = undefined
editing.value = undefined
recalling.value = undefined
forwarding.value = undefined
draft.value = ''
})
watch(() => [session.inboxChanges, session.contactChanges, session.connection], sync)
@@ -204,6 +242,7 @@ onBeforeUnmount(() => clearInterval(timer))
<button v-if="!line.recalled" type="button" class="plain" :disabled="busy" @click="localAction(line, 'favorite')">
{{ line.favorite ? '取消收藏' : '收藏' }}
</button>
<button v-if="!line.recalled" type="button" class="plain" :disabled="busy" @click="beginForward(line)">转发</button>
<button v-if="line.own && !line.recalled && !line.attachment" type="button" class="plain" :disabled="busy" @click="edit(line)">编辑</button>
<button v-if="line.own && !line.recalled" type="button" class="plain" :disabled="busy" @click="recalling = line">撤回</button>
<button type="button" class="plain" :disabled="busy || view?.unsent.includes(line.id)" @click="deleting = line">本机删除</button>
@@ -221,6 +260,22 @@ onBeforeUnmount(() => clearInterval(timer))
<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>
<form class="chat-compose" @submit.prevent="submit">
<div v-if="editing" class="chat-quote">
<span>正在编辑消息</span>