增加群附件多选和拖拽批量发送 #37
No files matched your search
@@ -20,7 +20,7 @@
|
||||
| 联系人 | 按用户名查找、处理好友申请、管理备注与分组,以及拉黑。变更可在双端实时同步。 |
|
||||
| 加密文字聊天 | 在两个已核验设备之间发送 MLS 加密消息,支持离线接收。 |
|
||||
| 加密群聊 | 创建群组、邀请联系人、管理成员和转让群主。群主可发布加密公告。群列表显示本机未读,并按账号同步置顶和免打扰。 |
|
||||
| 加密附件 | 两端可在私聊和群聊发送、下载最多 8 MiB 的文件,并在本机预览图片和视频。群聊提供文件、图片和视频的分类视图。 |
|
||||
| 加密附件 | 两端可在私聊和群聊发送、下载最多 8 MiB 的文件,并在本机预览图片和视频。群聊支持多选、拖拽发送,以及文件、图片和视频分类。 |
|
||||
| 加密语音 | 两端可在私聊和群聊录制、取消或发送最长 60 秒的语音消息,接收方在本机解密播放。 |
|
||||
| 消息管理 | 私聊和群聊支持引用回复、编辑文字、撤回、本机搜索和收藏。消息可转发到已建立加密会话的群或已核验的联系人设备。私聊支持可选加密已读回执。 |
|
||||
| Chromium 浏览器 | Windows 端支持独立窗口、多标签、导航、搜索、书签、历史、下载和隐私窗口,网页运行在独立会话中。 |
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ MLS 凭据由标准 Base64 的 publicKey 和 signature 组成,使用 UTF-8 前
|
||||
|
||||
附件密文上限为 8 MiB 加 16 字节认证标签。重复提交相同 ID 和密文为幂等操作。附件按投递保留期清理,文件名和密钥只通过 MLS 消息传递。
|
||||
|
||||
群组详情包含十进制字符串 membershipVersion。已接受成员变化会递增版本,待处理邀请和角色变化保留版本。active 成员可以查看其他有效成员,群主与管理员还可查看待处理邀请。群主可解散、调整管理员和移除成员。管理员可改名、邀请好友和移除普通成员。
|
||||
群组详情包含十进制字符串 membershipVersion。有效成员变更和群主转让会递增版本,待处理邀请和管理员升降保留版本。active 成员可以查看其他有效成员,群主与管理员还可查看待处理邀请。群主可解散、调整管理员和移除成员。管理员可改名、邀请好友和移除普通成员。
|
||||
|
||||
群主可使用 `transfer` 和有效成员的 `target` 转让群主。转让会将原群主设为普通成员,更新群版本,由新群主创建后续 MLS 会话。公告使用现有 MLS 密文投递接口,客户端验证公告来自该会话经核验的群主设备。
|
||||
|
||||
|
||||
@@ -180,3 +180,9 @@ Windows 和 Web 的群列表按当前设备显示未读投递数量,免打扰
|
||||
群主可用当前群会话设备发布、编辑和清除公告,公告正文通过 MLS 群密文传递。已经同步的公告保存在本机,新加入的设备从其加入后的会话获取公告,群主可以重新发布。群主可以把管理权转让给已接受邀请的成员,原群主成为普通成员,可以主动退出。转让更新群版本,新群主建立新会话前旧会话停止发送。
|
||||
|
||||
Windows 和 Edge 验证加密发布与清除公告、群主转让、原群主退出和新群主建立会话。服务端测试覆盖普通成员、管理员、外部账号、受邀未入群成员及向自己转让的拒绝路径。
|
||||
|
||||
## 群附件拖拽和批量发送
|
||||
|
||||
群附件发送区支持文件多选、拖拽、移除单项与清空待发列表。每批最多 8 个,单文件上限 8 MiB。客户端逐个加密和发送,展示批次进度。中断时未进入加密发件箱的文件留在当前页面,可再次提交,已进入发件箱的密文沿用现有重试机制。群会话变更会停止当前批次,剩余文件由用户在新会话中确认发送。
|
||||
|
||||
Windows Electron 与 Edge 验证多选发送、拖拽和移除待发文件。模拟第二个文件上传失败后只重试剩余文件,已送达的文件未重复出现。群聊、私聊与服务端投递回归共 7 项通过。
|
||||
@@ -390,6 +390,48 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
|
||||
await historyView(windows, '消息').click()
|
||||
await player.waitFor({ state: 'detached' })
|
||||
|
||||
const firstBatch = '批量一-' + id() + '.txt'
|
||||
const secondBatch = '批量二-' + id() + '.txt'
|
||||
const payload = (name) => ({ name, mimeType: 'text/plain', buffer: Buffer.from(name) })
|
||||
const ownerDrop = chat(owner).getByRole('region', { name: '群附件发送区' })
|
||||
await ownerDrop.locator('input:enabled').setInputFiles([payload(firstBatch), payload(secondBatch)])
|
||||
const queue = ownerDrop.getByRole('list', { name: '待发附件' })
|
||||
assert.equal(await queue.getByRole('listitem').count(), 2)
|
||||
const uploadMatcher = (url) => url.pathname.includes('/groups/') && url.pathname.includes('/attachments/') && url.searchParams.has('epoch')
|
||||
let uploadAttempts = 0
|
||||
const interruptSecondUpload = async (route) => {
|
||||
uploadAttempts++
|
||||
if (uploadAttempts === 2) await route.fulfill({ status: 503, json: { error: { message: '测试上传暂不可用' } } })
|
||||
else await route.continue()
|
||||
}
|
||||
await owner.route(uploadMatcher, interruptSecondUpload)
|
||||
await ownerDrop.getByRole('button', { name: '发送群附件', exact: true }).click()
|
||||
await chat(windows).getByRole('button', { name: '下载 ' + firstBatch, exact: true }).waitFor()
|
||||
await chat(owner).getByRole('alert').getByText('测试上传暂不可用').waitFor()
|
||||
assert.equal(await queue.getByRole('listitem').count(), 1)
|
||||
assert.equal(await queue.getByText(secondBatch, { exact: true }).count(), 1)
|
||||
await owner.unroute(uploadMatcher, interruptSecondUpload)
|
||||
await ownerDrop.getByRole('button', { name: '发送群附件', exact: true }).click()
|
||||
await chat(windows).getByRole('button', { name: '下载 ' + secondBatch, exact: true }).waitFor()
|
||||
assert.equal(await chat(windows).getByRole('button', { name: '下载 ' + firstBatch, exact: true }).count(), 1)
|
||||
await queue.waitFor({ state: 'detached' })
|
||||
|
||||
const dropped = '拖入附件-' + id() + '.txt'
|
||||
const rejected = '移出附件-' + id() + '.txt'
|
||||
const transfer = await windows.evaluateHandle((names) => {
|
||||
const data = new DataTransfer()
|
||||
for (const name of names) data.items.add(new File([name], name, { type: 'text/plain' }))
|
||||
return data
|
||||
}, [dropped, rejected])
|
||||
const desktopDrop = chat(windows).getByRole('region', { name: '群附件发送区' })
|
||||
await desktopDrop.dispatchEvent('dragover', { dataTransfer: transfer })
|
||||
await desktopDrop.dispatchEvent('drop', { dataTransfer: transfer })
|
||||
await transfer.dispose()
|
||||
await desktopDrop.getByRole('button', { name: '移除 ' + rejected, exact: true }).click()
|
||||
await desktopDrop.getByRole('button', { name: '发送群附件', exact: true }).click()
|
||||
await chat(owner).getByRole('button', { name: '下载 ' + dropped, exact: true }).waitFor()
|
||||
assert.equal(await chat(owner).getByRole('button', { name: '下载 ' + rejected, exact: true }).count(), 0)
|
||||
|
||||
const voiceUploads = []
|
||||
windows.on('request', (request) => {
|
||||
if (request.method() === 'POST' && request.url().includes('/attachments/')) voiceUploads.push(request.url())
|
||||
|
||||
+85
-17
@@ -2,7 +2,7 @@
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { useSession } from '../session'
|
||||
import { APIError } from '../api'
|
||||
import { downloadAttachment } from './attachments'
|
||||
import { downloadAttachment, maxAttachmentSize } from './attachments'
|
||||
import type { Attachment } from './attachments'
|
||||
import MediaPreview from './MediaPreview.vue'
|
||||
import ForwardDialog from './ForwardDialog.vue'
|
||||
@@ -37,7 +37,10 @@ const editing = ref<GroupLine>()
|
||||
const recalling = ref<GroupLine>()
|
||||
const forwarding = ref<GroupLine>()
|
||||
const forwardStatus = ref('')
|
||||
const file = ref<File>()
|
||||
const files = ref<File[]>([])
|
||||
const maxBatchFiles = 8
|
||||
const draggingFiles = ref(false)
|
||||
const batchProgress = ref('')
|
||||
const pendingVoice = ref<{ file: File; epoch: string }>()
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
@@ -191,19 +194,68 @@ function recall() {
|
||||
})
|
||||
}
|
||||
|
||||
function chooseFile(event: Event) {
|
||||
function chooseFiles(event: Event) {
|
||||
const input = event.target as HTMLInputElement
|
||||
file.value = input.files?.[0]
|
||||
if (input.files) addFiles(input.files)
|
||||
input.value = ''
|
||||
}
|
||||
|
||||
function sendFile() {
|
||||
function addFiles(selection: FileList) {
|
||||
if (!currentEpoch.value || busy.value || view.value?.hasPending || editing.value || !selection.length) return
|
||||
error.value = ''
|
||||
if (selection.length + files.value.length > maxBatchFiles) {
|
||||
error.value = '每批最多发送 8 个群附件'
|
||||
return
|
||||
}
|
||||
const incoming = Array.from(selection)
|
||||
const oversized = incoming.find((item) => item.size > maxAttachmentSize)
|
||||
if (oversized) {
|
||||
error.value = oversized.name + ' 超过单文件 8 MiB 上限'
|
||||
return
|
||||
}
|
||||
files.value.push(...incoming)
|
||||
}
|
||||
|
||||
function dragFiles(event: DragEvent) {
|
||||
if (!event.dataTransfer?.types.includes('Files')) return
|
||||
event.preventDefault()
|
||||
draggingFiles.value = Boolean(currentEpoch.value && !busy.value && !view.value?.hasPending && !editing.value)
|
||||
event.dataTransfer.dropEffect = draggingFiles.value ? 'copy' : 'none'
|
||||
}
|
||||
|
||||
function leaveDropArea(event: DragEvent) {
|
||||
const area = event.currentTarget as HTMLElement
|
||||
if (!(event.relatedTarget instanceof Node) || !area.contains(event.relatedTarget)) draggingFiles.value = false
|
||||
}
|
||||
|
||||
function dropFiles(event: DragEvent) {
|
||||
draggingFiles.value = false
|
||||
if (event.dataTransfer?.types.includes('Files')) {
|
||||
event.preventDefault()
|
||||
addFiles(event.dataTransfer.files)
|
||||
}
|
||||
}
|
||||
|
||||
function sendFiles() {
|
||||
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()
|
||||
const epoch = currentEpoch.value
|
||||
if (!identity || !epoch || !files.value.length) return
|
||||
void run(async () => {
|
||||
const total = files.value.length
|
||||
try {
|
||||
for (let index = 0; index < total && active; index++) {
|
||||
const file = files.value[0]
|
||||
if (!file || epoch !== currentEpoch.value) break
|
||||
batchProgress.value = `正在发送 ${index + 1} / ${total}`
|
||||
await sendGroupMessage(identity, props.group, file, session.authorized, epoch)
|
||||
// Once the encrypted envelope is queued, that outbox owns retrying it.
|
||||
files.value.shift()
|
||||
await refresh()
|
||||
if (view.value?.hasPending) break
|
||||
}
|
||||
} finally {
|
||||
batchProgress.value = ''
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -252,6 +304,7 @@ watch(() => session.connection, (connection) => { if (connection === '实时连
|
||||
watch(currentEpoch, (epoch, previous) => {
|
||||
if (!previous || epoch === previous) return
|
||||
announcementDraft.value = undefined
|
||||
draggingFiles.value = false
|
||||
if (editing.value || replying.value) draft.value = ''
|
||||
editing.value = undefined
|
||||
replying.value = undefined
|
||||
@@ -286,7 +339,7 @@ onBeforeUnmount(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="group-chat" aria-label="群消息">
|
||||
<section class="group-chat" aria-label="群消息" @dragover.prevent @drop.prevent>
|
||||
<h3>群消息</h3>
|
||||
<p v-if="error" class="error" role="alert">{{ error }}</p>
|
||||
<p v-if="forwardStatus" role="status">{{ forwardStatus }}</p>
|
||||
@@ -402,12 +455,22 @@ onBeforeUnmount(() => {
|
||||
<div v-if="ready && !editing" class="group-chat-composer">
|
||||
<VoiceRecorder v-if="currentEpoch" :key="currentEpoch" :epoch="currentEpoch" :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>
|
||||
<button type="button" class="plain" :disabled="busy || view?.hasPending" @click="sendFile">发送群附件</button>
|
||||
<button type="button" class="plain" :disabled="busy" @click="file = undefined">取消</button>
|
||||
</div>
|
||||
<section class="group-drop-zone" aria-label="群附件发送区" :class="{ dragging: draggingFiles }"
|
||||
@dragover="dragFiles" @dragleave="leaveDropArea" @drop="dropFiles">
|
||||
<label>选择群附件 <input type="file" multiple :disabled="busy || view?.hasPending" @change="chooseFiles"></label>
|
||||
<p class="muted">也可拖入文件。每批最多 8 个,单个文件最大 8 MiB。</p>
|
||||
<ul v-if="files.length" class="group-file-queue" aria-label="待发附件">
|
||||
<li v-for="(item, index) in files" :key="item.name + '/' + index">
|
||||
<span>{{ item.name }}</span>
|
||||
<button type="button" class="plain" :aria-label="'移除 ' + item.name" :disabled="busy" @click="files.splice(index, 1)">移除</button>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-if="batchProgress" role="status">{{ batchProgress }}</p>
|
||||
<div v-if="files.length" class="message-actions">
|
||||
<button type="button" class="plain" :disabled="busy || view?.hasPending" @click="sendFiles">发送群附件</button>
|
||||
<button type="button" class="plain" :disabled="busy" @click="files = []">清空待发附件</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
@@ -431,6 +494,11 @@ onBeforeUnmount(() => {
|
||||
.group-media li { min-width: 0; padding: .7rem; border: 1px solid var(--line); border-radius: .45rem; }
|
||||
.group-chat-composer { display: grid; gap: .55rem; }
|
||||
.group-chat-composer textarea { display: block; width: 100%; resize: vertical; font: inherit; }
|
||||
.group-drop-zone { display: grid; gap: .5rem; padding: .65rem .8rem; border: 1px dashed var(--line); border-radius: .45rem; }
|
||||
.group-drop-zone.dragging { border-color: var(--green); background: var(--green-soft); }
|
||||
.group-file-queue { display: grid; gap: .35rem; margin: 0; padding: 0; list-style: none; }
|
||||
.group-file-queue li { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
|
||||
.group-file-queue span { overflow-wrap: anywhere; }
|
||||
.group-chat button { justify-self: start; }
|
||||
.media-preview :deep(img), .media-preview :deep(video) { display: block; max-width: 100%; max-height: 18rem; }
|
||||
</style>
|
||||
@@ -1,7 +1,7 @@
|
||||
import { base64, decode } from './engine'
|
||||
import type { Call } from './chat'
|
||||
|
||||
const maxSize = 8 * 1024 * 1024
|
||||
export const maxAttachmentSize = 8 * 1024 * 1024
|
||||
const encoder = new TextEncoder()
|
||||
const decoder = new TextDecoder('utf-8', { fatal: true })
|
||||
const mediaTypes = ['image/jpeg', 'image/png', 'image/webp', 'image/gif', 'video/mp4', 'video/webm'] as const
|
||||
@@ -44,7 +44,7 @@ function safeName(name: string) {
|
||||
}
|
||||
|
||||
export async function sealAttachment(file: File) {
|
||||
if (file.size > maxSize) throw new Error('附件超过 8 MiB')
|
||||
if (file.size > maxAttachmentSize) throw new Error('附件超过 8 MiB')
|
||||
const key = crypto.getRandomValues(new Uint8Array(32))
|
||||
const iv = crypto.getRandomValues(new Uint8Array(12))
|
||||
const attachment: Attachment = { id: crypto.randomUUID(), name: safeName(file.name), size: file.size, key: base64(key), iv: base64(iv) }
|
||||
@@ -106,7 +106,7 @@ export function decodeMessage(message: Uint8Array): ChatContent {
|
||||
const value = JSON.parse(decoder.decode(message.subarray(2))) as Attachment | null
|
||||
if (!value || typeof value.id !== 'string' || !/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/.test(value.id) ||
|
||||
typeof value.name !== 'string' || value.name !== safeName(value.name) ||
|
||||
!Number.isInteger(value.size) || value.size < 0 || value.size > maxSize ||
|
||||
!Number.isInteger(value.size) || value.size < 0 || value.size > maxAttachmentSize ||
|
||||
(value.voice !== undefined && value.voice !== true) ||
|
||||
(value.media !== undefined && (!mediaType(value.media) || value.voice === true)) ||
|
||||
typeof value.key !== 'string' || decode(value.key).length !== 32 ||
|
||||
|
||||
Reference in new issue
Block a user