增加 Windows 与 Web 端到端加密群语音
This commit is contained in:
1 parent
9c84b38fd9
commit
de722039d6
8 files changed
+125
-16
No files matched your search
@@ -4,6 +4,8 @@ import { useSession } from '../session'
|
||||
import { downloadAttachment } from './attachments'
|
||||
import type { Attachment } from './attachments'
|
||||
import MediaPreview from './MediaPreview.vue'
|
||||
import VoiceMessage from './VoiceMessage.vue'
|
||||
import VoiceRecorder from './VoiceRecorder.vue'
|
||||
import { enableChat, trust } from './chat'
|
||||
import { discardPendingGroupMessage, groupAttachmentPath, publishGroup, sendGroupMessage, synchronizeGroup } from './group-chat'
|
||||
import type { GroupDetail, GroupDevice } from './group-chat'
|
||||
@@ -16,9 +18,11 @@ const codes = ref<Record<string, string>>({})
|
||||
const selected = ref<Record<string, string>>({})
|
||||
const draft = ref('')
|
||||
const file = ref<File>()
|
||||
const pendingVoice = ref<{ file: File; epoch: string }>()
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const ready = computed(() => view.value?.ready && view.value.current?.membershipVersion === props.group.membershipVersion)
|
||||
const recordingEpoch = computed(() => ready.value ? view.value?.current?.id : undefined)
|
||||
const members = computed(() => props.group.members.filter((member) => member.state === 'active' && member.id !== session.identity?.user.id))
|
||||
const canPublish = computed(() => Boolean(view.value && !view.value.current && members.value.every((member) =>
|
||||
view.value?.devices.some((device) => device.user === member.id && device.id === selected.value[member.id] && pinned(device)))))
|
||||
@@ -104,6 +108,10 @@ function sendFile() {
|
||||
})
|
||||
}
|
||||
|
||||
function sendVoice(recording: File, epoch?: string) {
|
||||
if (epoch) pendingVoice.value = { file: recording, epoch }
|
||||
}
|
||||
|
||||
function download(attachment: Attachment) {
|
||||
void run(() => downloadAttachment(attachment, session.authorized, groupAttachmentPath(props.group, attachment.id)))
|
||||
}
|
||||
@@ -117,6 +125,21 @@ function discard() {
|
||||
}
|
||||
|
||||
watch(() => props.group.membershipVersion, () => void run(refresh))
|
||||
watch([pendingVoice, busy, recordingEpoch, () => view.value?.hasPending], ([voice, inProgress, epoch, hasPending]) => {
|
||||
const identity = session.identity
|
||||
if (!voice || !identity) return
|
||||
if (voice.epoch !== epoch) {
|
||||
pendingVoice.value = undefined
|
||||
error.value = '群加密会话已变更,请重新录音'
|
||||
return
|
||||
}
|
||||
if (inProgress || hasPending) return
|
||||
pendingVoice.value = undefined
|
||||
void run(async () => {
|
||||
await sendGroupMessage(identity, props.group, voice.file, session.authorized, voice.epoch)
|
||||
await refresh()
|
||||
})
|
||||
})
|
||||
onMounted(() => { timer = setInterval(() => { if (code.value) void run(refresh, false) }, 2500) })
|
||||
onBeforeUnmount(() => clearInterval(timer))
|
||||
</script>
|
||||
@@ -159,7 +182,8 @@ onBeforeUnmount(() => clearInterval(timer))
|
||||
<ul v-if="view?.lines.length" class="group-chat-lines" aria-label="群消息记录">
|
||||
<li v-for="line in view.lines" :key="line.id">
|
||||
<small>{{ line.name }} · {{ new Date(line.time).toLocaleString() }}</small>
|
||||
<template v-if="line.attachment">
|
||||
<VoiceMessage v-if="line.attachment?.voice" :attachment="line.attachment" :path="groupAttachmentPath(group, line.attachment.id)" />
|
||||
<template v-else-if="line.attachment">
|
||||
<p>{{ line.attachment.name }} · {{ new Intl.NumberFormat().format(line.attachment.size) }} 字节</p>
|
||||
<MediaPreview v-if="line.attachment.media" :attachment="line.attachment" :path="groupAttachmentPath(group, line.attachment.id)" />
|
||||
<button type="button" class="plain" :disabled="busy" @click="download(line.attachment)">下载 {{ line.attachment.name }}</button>
|
||||
@@ -176,6 +200,8 @@ onBeforeUnmount(() => clearInterval(timer))
|
||||
<button class="primary" :disabled="busy || view?.hasPending || !draft.trim()">发送群消息</button>
|
||||
</form>
|
||||
<div v-if="ready" class="group-chat-composer">
|
||||
<VoiceRecorder v-if="recordingEpoch" :key="recordingEpoch" :epoch="recordingEpoch" :disabled="busy || view?.hasPending || !!pendingVoice"
|
||||
@send="sendVoice" @error="error = $event" />
|
||||
<label>选择群附件 <input type="file" :disabled="busy || view?.hasPending" @change="chooseFile"></label>
|
||||
<div v-if="file" class="message-actions">
|
||||
<span>{{ file.name }}</span>
|
||||
|
||||
Reference in new issue
Block a user