接通双端加密语音录制与播放
This commit is contained in:
1 parent
149028267e
commit
87676ae983
13 files changed
+217
-10
No files matched your search
@@ -7,6 +7,8 @@ import type { ChatLine, Peer } from '../chat/chat'
|
||||
import type { Contact } from '../contacts'
|
||||
import { downloadAttachment } from '../chat/attachments'
|
||||
import type { Attachment } from '../chat/attachments'
|
||||
import VoiceRecorder from '../chat/VoiceRecorder.vue'
|
||||
import VoiceMessage from '../chat/VoiceMessage.vue'
|
||||
|
||||
const session = useSession()
|
||||
const route = useRoute()
|
||||
@@ -32,6 +34,7 @@ const recent = ref<Record<string, string>>({})
|
||||
const conversationQuery = ref('')
|
||||
const history = ref<HTMLOListElement>()
|
||||
const shareRead = ref(false)
|
||||
const pendingVoice = ref<File>()
|
||||
const view = ref<Awaited<ReturnType<typeof synchronize>>>()
|
||||
const target = computed(() => typeof route.params.user === 'string' ? route.params.user : '')
|
||||
const peer = computed(() => view.value?.peers.find((item) => item.id === selected.value))
|
||||
@@ -209,7 +212,10 @@ function attach(event: Event) {
|
||||
const input = event.target as HTMLInputElement
|
||||
const file = input.files?.[0]
|
||||
input.value = ''
|
||||
if (!file) return
|
||||
if (file) sendFile(file)
|
||||
}
|
||||
|
||||
function sendFile(file: File) {
|
||||
void execute(async () => {
|
||||
if (!session.identity || !peer.value) return
|
||||
await send(session.identity, target.value, peer.value, file, session.authorized)
|
||||
@@ -217,6 +223,16 @@ function attach(event: Event) {
|
||||
})
|
||||
}
|
||||
|
||||
function sendVoice(file: File) {
|
||||
pendingVoice.value = file
|
||||
}
|
||||
|
||||
watch([pendingVoice, busy], ([file, inProgress]) => {
|
||||
if (!file || inProgress) return
|
||||
pendingVoice.value = undefined
|
||||
sendFile(file)
|
||||
})
|
||||
|
||||
function saveAttachment(attachment: Attachment) {
|
||||
void execute(() => downloadAttachment(attachment, session.authorized))
|
||||
}
|
||||
@@ -281,6 +297,7 @@ watch(selected, () => {
|
||||
editing.value = undefined
|
||||
recalling.value = undefined
|
||||
forwarding.value = undefined
|
||||
pendingVoice.value = undefined
|
||||
draft.value = ''
|
||||
scheduleReceipt()
|
||||
})
|
||||
@@ -352,6 +369,7 @@ onBeforeUnmount(() => {
|
||||
:data-unread="!line.own && !line.read && !line.recalled ? line.id : undefined">
|
||||
<blockquote v-if="line.quote">{{ line.quote }}</blockquote>
|
||||
<span v-if="line.recalled" class="muted">消息已撤回</span>
|
||||
<VoiceMessage v-else-if="line.attachment?.voice" :attachment="line.attachment" />
|
||||
<button v-else-if="line.attachment" type="button" class="plain" :disabled="busy"
|
||||
@click="saveAttachment(line.attachment)">下载 {{ line.attachment.name }}</button>
|
||||
<span v-else><template v-for="(part, index) in messageParts(line.text)" :key="index"><button v-if="part.url && internalBrowser"
|
||||
@@ -409,6 +427,7 @@ onBeforeUnmount(() => {
|
||||
<button type="button" class="plain" @click="reply = undefined">取消引用</button>
|
||||
</div>
|
||||
<label v-if="!editing">发送附件<input type="file" :disabled="busy" @change="attach"></label>
|
||||
<VoiceRecorder v-if="!editing" :key="selected" :disabled="busy" @send="sendVoice" @error="error = $event" />
|
||||
<label>消息<textarea v-model="draft" required rows="3" maxlength="4000"></textarea></label>
|
||||
<button class="primary" :disabled="busy || !draft.trim()">{{ editing ? '保存编辑' : '发送' }}</button>
|
||||
</form>
|
||||
|
||||
Reference in new issue
Block a user