为双端群聊增加端到端加密附件
This commit is contained in:
1 parent
5988ad6ed6
commit
a95a007768
21 files changed
+405
-84
No files matched your search
@@ -1,8 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { useSession } from '../session'
|
||||
import { downloadAttachment } from './attachments'
|
||||
import type { Attachment } from './attachments'
|
||||
import MediaPreview from './MediaPreview.vue'
|
||||
import { enableChat, trust } from './chat'
|
||||
import { discardPendingGroupMessage, publishGroup, sendGroupMessage, synchronizeGroup } from './group-chat'
|
||||
import { discardPendingGroupMessage, groupAttachmentPath, publishGroup, sendGroupMessage, synchronizeGroup } from './group-chat'
|
||||
import type { GroupDetail, GroupDevice } from './group-chat'
|
||||
|
||||
const props = defineProps<{ group: GroupDetail }>()
|
||||
@@ -12,6 +15,7 @@ const code = ref('')
|
||||
const codes = ref<Record<string, string>>({})
|
||||
const selected = ref<Record<string, string>>({})
|
||||
const draft = ref('')
|
||||
const file = ref<File>()
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const ready = computed(() => view.value?.ready && view.value.current?.membershipVersion === props.group.membershipVersion)
|
||||
@@ -84,6 +88,26 @@ function send() {
|
||||
})
|
||||
}
|
||||
|
||||
function chooseFile(event: Event) {
|
||||
const input = event.target as HTMLInputElement
|
||||
file.value = input.files?.[0]
|
||||
input.value = ''
|
||||
}
|
||||
|
||||
function sendFile() {
|
||||
const identity = session.identity
|
||||
const selectedFile = file.value
|
||||
if (identity && selectedFile) void run(async () => {
|
||||
await sendGroupMessage(identity, props.group, selectedFile, session.authorized)
|
||||
file.value = undefined
|
||||
await refresh()
|
||||
})
|
||||
}
|
||||
|
||||
function download(attachment: Attachment) {
|
||||
void run(() => downloadAttachment(attachment, session.authorized, groupAttachmentPath(props.group, attachment.id)))
|
||||
}
|
||||
|
||||
function discard() {
|
||||
const identity = session.identity
|
||||
if (identity) void run(async () => {
|
||||
@@ -135,7 +159,12 @@ 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>
|
||||
<p>{{ line.text }}</p>
|
||||
<template v-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>
|
||||
</template>
|
||||
<p v-else>{{ line.text }}</p>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-if="view?.hasPending" role="status">
|
||||
@@ -146,6 +175,14 @@ onBeforeUnmount(() => clearInterval(timer))
|
||||
<label>群消息<textarea v-model="draft" rows="3" maxlength="8000" required /></label>
|
||||
<button class="primary" :disabled="busy || view?.hasPending || !draft.trim()">发送群消息</button>
|
||||
</form>
|
||||
<div v-if="ready" class="group-chat-composer">
|
||||
<label>选择群附件 <input type="file" :disabled="busy || view?.hasPending" @change="chooseFile"></label>
|
||||
<div v-if="file" class="message-actions">
|
||||
<span>{{ file.name }}</span>
|
||||
<button type="button" class="plain" :disabled="busy || view?.hasPending" @click="sendFile">发送群附件</button>
|
||||
<button type="button" class="plain" :disabled="busy" @click="file = undefined">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
@@ -160,4 +197,5 @@ onBeforeUnmount(() => clearInterval(timer))
|
||||
.group-chat-composer { display: grid; gap: .55rem; }
|
||||
.group-chat-composer textarea { display: block; width: 100%; resize: vertical; font: inherit; }
|
||||
.group-chat button { justify-self: start; }
|
||||
.media-preview :deep(img), .media-preview :deep(video) { display: block; max-width: 100%; max-height: 18rem; }
|
||||
</style>
|
||||
Reference in new issue
Block a user