支持本机删除群消息和打开群链接
This commit is contained in:
1 parent
5ec9c81f90
commit
fef421bd4b
7 files changed
+134
-40
No files matched your search
@@ -22,7 +22,7 @@
|
||||
| 加密群聊 | 创建群组、通过联系人或一次性链接及二维码邀请、管理成员和转让群主。群主可发布加密公告。群列表显示本机未读,并按账号同步置顶和免打扰。 |
|
||||
| 加密附件 | 两端可在私聊和群聊发送、下载最多 8 MiB 的文件,并在本机预览图片和视频。群聊支持多选、拖拽发送,以及文件、图片和视频分类。 |
|
||||
| 加密语音 | 两端可在私聊和群聊录制、取消或发送最长 60 秒的语音消息,接收方在本机解密播放。 |
|
||||
| 消息管理 | 私聊和群聊支持引用回复、编辑文字、撤回、本机搜索和收藏。消息可转发到已建立加密会话的群或已核验的联系人设备。私聊支持可选加密已读回执。 |
|
||||
| 消息管理 | 私聊和群聊支持引用回复、编辑文字、撤回、本机搜索、收藏和本机删除。可打开消息里的网页链接,并将消息转发到加密群或已核验的联系人设备。私聊支持可选加密已读回执。 |
|
||||
| Chromium 浏览器 | Windows 端支持独立窗口、多标签、导航、搜索、书签、历史、下载和隐私窗口,网页运行在独立会话中。 |
|
||||
|
||||
当前为开发预览。大文件分片、音视频和多设备历史同步仍在开发,Windows 安装包尚未发布。 [开发进度与验收记录](docs/progress.md)
|
||||
|
||||
+7
-1
@@ -75,7 +75,7 @@ Windows 浏览器新增可跨窗口保留的本地书签和历史,每类最多
|
||||
|
||||
## 聊天中的链接
|
||||
|
||||
加密文字消息中的 HTTPS 链接在端侧识别。Windows 从链接启动隔离 Chromium,Web 在独立标签页打开并隔离 opener。开发环境支持本机 HTTP。真实双端测试验证消息链接点击与 Chromium 地址显示。网页卡片与从浏览器分享给联系人仍待实现。
|
||||
私聊和群聊的加密文字消息均在端侧识别 HTTPS 链接。Windows 从链接启动隔离 Chromium,Web 在独立标签页打开并隔离 opener。开发环境支持本机 HTTP。网页卡片与从浏览器分享给联系人仍待实现。
|
||||
|
||||
## 会话导航和已读回执
|
||||
|
||||
@@ -192,3 +192,9 @@ Windows Electron 与 Edge 验证多选发送、拖拽和移除待发文件。模
|
||||
群主可生成或撤销有效 24 小时的一次性邀请链接,客户端在本机绘制二维码。Web 可以直接打开链接,Windows 群组页可以粘贴链接或邀请码。服务端只存邀请码摘要,生成新链接或转让群主会撤销旧链接。领取成功会生成待接受邀请,成员确认后才加入现有群权限流程。
|
||||
|
||||
接口测试验证并发领取仅一次成功、链接轮换、撤销、群主转让后失效及领取后权限隔离。Windows 与 Edge 验证二维码绘制、桌面端粘贴领取、Web 登录后领取和接受或拒绝流程。
|
||||
|
||||
## 从本机删除群消息
|
||||
|
||||
Windows 和 Web 可从本机缓存删除群消息。删除同时移除其本机收藏和分类入口,保留同步游标,重新进入群聊不会重复取回该记录。其他设备照常保留各自记录。已经另存的文件由用户在系统中管理。
|
||||
|
||||
集成测试验证 Windows 从群文件视图删除收藏文件后,重新进入群聊仍保持删除,Web 保留原消息。群链接在 Edge 新标签页与 Windows 隔离 Chromium 中实际打开。群聊、私聊和服务端投递回归共 8 项通过。
|
||||
@@ -432,6 +432,37 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
|
||||
await chat(owner).getByRole('button', { name: '下载 ' + dropped, exact: true }).waitFor()
|
||||
assert.equal(await chat(owner).getByRole('button', { name: '下载 ' + rejected, exact: true }).count(), 0)
|
||||
|
||||
const link = base + '/healthz'
|
||||
assert.equal(await send(owner, link), epoch)
|
||||
const webLink = chat(owner).getByRole('link', { name: link, exact: true })
|
||||
assert.equal(await webLink.getAttribute('rel'), 'noopener noreferrer')
|
||||
const popup = owner.waitForEvent('popup')
|
||||
await webLink.click()
|
||||
const webTab = await popup
|
||||
await webTab.waitForURL(link)
|
||||
assert.equal(await webTab.evaluate(() => window.opener === null), true)
|
||||
await webTab.close()
|
||||
const opened = desktop.waitForEvent('window')
|
||||
await chat(windows).getByRole('button', { name: link, exact: true }).click()
|
||||
const browserTab = await opened
|
||||
await browserTab.waitForFunction((expected) => document.querySelector('#address')?.value === expected, link)
|
||||
await browserTab.close()
|
||||
|
||||
await historyView(windows, '群文件').click()
|
||||
const localFile = chat(windows).getByRole('list', { name: '群文件' }).getByRole('listitem').filter({ hasText: firstBatch })
|
||||
await localFile.getByRole('button', { name: '收藏', exact: true }).click()
|
||||
await localFile.getByRole('button', { name: '取消收藏', exact: true }).waitFor()
|
||||
await localFile.getByRole('button', { name: '从本机删除', exact: true }).click()
|
||||
await chat(windows).getByRole('button', { name: '确认删除群消息', exact: true }).click()
|
||||
await localFile.waitFor({ state: 'detached' })
|
||||
assert.equal(await chat(owner).getByRole('button', { name: '下载 ' + firstBatch, exact: true }).count(), 1)
|
||||
await work(windows).getByRole('link', { name: '联系人' }).click()
|
||||
await work(windows).getByRole('link', { name: '群组' }).click()
|
||||
await windows.getByRole('link', { name: new RegExp(group) }).click()
|
||||
await chat(windows).getByRole('button', { name: '启用本机群聊' }).click()
|
||||
await chat(windows).getByText('群加密已建立', { exact: true }).waitFor()
|
||||
assert.equal(await chat(windows).getByRole('button', { name: '下载 ' + firstBatch, exact: true }).count(), 0)
|
||||
|
||||
const voiceUploads = []
|
||||
windows.on('request', (request) => {
|
||||
if (request.method() === 'POST' && request.url().includes('/attachments/')) voiceUploads.push(request.url())
|
||||
|
||||
+36
-10
@@ -5,11 +5,12 @@ import { APIError } from '../api'
|
||||
import { downloadAttachment, maxAttachmentSize } from './attachments'
|
||||
import type { Attachment } from './attachments'
|
||||
import MediaPreview from './MediaPreview.vue'
|
||||
import MessageText from './MessageText.vue'
|
||||
import ForwardDialog from './ForwardDialog.vue'
|
||||
import VoiceMessage from './VoiceMessage.vue'
|
||||
import VoiceRecorder from './VoiceRecorder.vue'
|
||||
import { enableChat, trust } from './chat'
|
||||
import { discardPendingGroupMessage, forwardGroupMessage, groupAttachmentPath, groupQuote, publishGroup, sendGroupMessage, setGroupFavorite, synchronizeGroup } from './group-chat'
|
||||
import { discardPendingGroupMessage, forwardGroupMessage, groupAttachmentPath, groupQuote, publishGroup, removeLocalGroupMessage, sendGroupMessage, setGroupFavorite, synchronizeGroup } from './group-chat'
|
||||
import type { ForwardDestination, GroupDetail, GroupDevice, GroupLine } from './group-chat'
|
||||
|
||||
const props = defineProps<{ group: GroupDetail }>()
|
||||
@@ -35,6 +36,7 @@ const mediaLimit = ref(mediaPageSize)
|
||||
const replying = ref<GroupLine>()
|
||||
const editing = ref<GroupLine>()
|
||||
const recalling = ref<GroupLine>()
|
||||
const deleting = ref<GroupLine>()
|
||||
const forwarding = ref<GroupLine>()
|
||||
const forwardStatus = ref('')
|
||||
const files = ref<File[]>([])
|
||||
@@ -275,6 +277,22 @@ function favorite(line: GroupLine) {
|
||||
})
|
||||
}
|
||||
|
||||
function removeLocal() {
|
||||
const identity = session.identity
|
||||
const message = deleting.value
|
||||
if (!identity || !message) return
|
||||
const matches = (line?: GroupLine) => line?.id === message.id && line.epoch === message.epoch && line.sender === message.sender
|
||||
void run(async () => {
|
||||
const updated = await removeLocalGroupMessage(identity, props.group, message)
|
||||
if (view.value) view.value.lines = updated
|
||||
if (matches(replying.value)) replying.value = undefined
|
||||
if (matches(editing.value)) { editing.value = undefined; draft.value = '' }
|
||||
if (matches(recalling.value)) recalling.value = undefined
|
||||
if (matches(forwarding.value)) forwarding.value = undefined
|
||||
deleting.value = undefined
|
||||
})
|
||||
}
|
||||
|
||||
function beginForward(line: GroupLine) {
|
||||
forwardStatus.value = ''
|
||||
forwarding.value = line
|
||||
@@ -413,21 +431,29 @@ onBeforeUnmount(() => {
|
||||
<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>
|
||||
<p v-else><MessageText :text="line.text" @error="error = $event" /></p>
|
||||
<small v-if="line.edited && !line.recalled" class="muted">已编辑</small>
|
||||
<div v-if="!line.recalled" class="message-actions">
|
||||
<button type="button" class="plain" :disabled="busy" @click="favorite(line)">{{ line.favorite ? '取消收藏' : '收藏' }}</button>
|
||||
<button type="button" class="plain" :disabled="busy" @click="beginForward(line)">转发</button>
|
||||
<template v-if="currentEpoch && line.epoch === currentEpoch">
|
||||
<button type="button" class="plain" :disabled="busy || view?.hasPending || !!editing" @click="replying = line">引用</button>
|
||||
<template v-if="line.sender === session.identity?.device.id">
|
||||
<button v-if="!line.attachment" type="button" class="plain" :disabled="busy || view?.hasPending" @click="edit(line)">编辑</button>
|
||||
<button type="button" class="plain" :disabled="busy || view?.hasPending" @click="recalling = line">撤回</button>
|
||||
<div class="message-actions">
|
||||
<template v-if="!line.recalled">
|
||||
<button type="button" class="plain" :disabled="busy" @click="favorite(line)">{{ line.favorite ? '取消收藏' : '收藏' }}</button>
|
||||
<button type="button" class="plain" :disabled="busy" @click="beginForward(line)">转发</button>
|
||||
<template v-if="currentEpoch && line.epoch === currentEpoch">
|
||||
<button type="button" class="plain" :disabled="busy || view?.hasPending || !!editing" @click="replying = line">引用</button>
|
||||
<template v-if="line.sender === session.identity?.device.id">
|
||||
<button v-if="!line.attachment" type="button" class="plain" :disabled="busy || view?.hasPending" @click="edit(line)">编辑</button>
|
||||
<button type="button" class="plain" :disabled="busy || view?.hasPending" @click="recalling = line">撤回</button>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
<button type="button" class="plain" :disabled="busy" @click="deleting = line">从本机删除</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-if="deleting" class="confirmation">
|
||||
<p>从本机群历史删除这条消息和它的收藏?</p>
|
||||
<button type="button" class="plain" :disabled="busy" @click="removeLocal">确认删除群消息</button>
|
||||
<button type="button" class="plain" @click="deleting = undefined">取消</button>
|
||||
</div>
|
||||
<button v-if="visibleLines.length < lines.length" type="button" class="plain" @click="mediaLimit += mediaPageSize">加载更多本机附件</button>
|
||||
<ForwardDialog v-if="forwarding && view" :key="[forwarding.epoch, forwarding.sender, forwarding.id].join('/')"
|
||||
:source-group="group.id" :pinned="view.pinned" :busy="busy" @confirm="forward" @cancel="forwarding = undefined" />
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = defineProps<{ text: string }>()
|
||||
const emit = defineEmits<{ error: [message: string] }>()
|
||||
const internalBrowser = window.xhchat?.openBrowser
|
||||
|
||||
const parts = computed(() => {
|
||||
const text = props.text
|
||||
const segments: { text: string; url?: string }[] = []
|
||||
let offset = 0
|
||||
for (const match of text.matchAll(/https?:\/\/[^\s<>"']+/giu)) {
|
||||
const label = match[0].replace(/[.,!?;:,。!?;:、))\]】]+$/u, '')
|
||||
if (label.length > 4096) continue
|
||||
try {
|
||||
const url = new URL(label)
|
||||
if (url.username || url.password ||
|
||||
(url.protocol !== 'https:' && !['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname))) continue
|
||||
if (match.index > offset) segments.push({ text: text.slice(offset, match.index) })
|
||||
segments.push({ text: label, url: url.href })
|
||||
offset = match.index + label.length
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (offset < text.length) segments.push({ text: text.slice(offset) })
|
||||
return segments
|
||||
})
|
||||
|
||||
async function open(url: string) {
|
||||
try {
|
||||
await internalBrowser?.(url)
|
||||
} catch (cause) {
|
||||
emit('error', cause instanceof Error ? cause.message : '无法打开网页链接')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span><template v-for="(part, index) in parts" :key="index"><button v-if="part.url && internalBrowser"
|
||||
type="button" class="chat-link" @click="open(part.url)">{{ part.text }}</button><a v-else-if="part.url"
|
||||
class="chat-link" :href="part.url" target="_blank" rel="noopener noreferrer">{{ part.text }}</a><template v-else>{{ part.text }}</template></template></span>
|
||||
</template>
|
||||
@@ -83,6 +83,20 @@ export function setGroupFavorite(identity: ChatIdentity, group: GroupDetail, mes
|
||||
})
|
||||
}
|
||||
|
||||
export function removeLocalGroupMessage(identity: ChatIdentity, group: GroupDetail, message: LineRef) {
|
||||
return update(identity, async (state, save) => {
|
||||
const chat = state.groupChats?.[group.id]
|
||||
if (!chat) return []
|
||||
const index = chat.lines.findIndex((line) => line.id === message.id && line.epoch === message.epoch && line.sender === message.sender)
|
||||
if (index !== -1) {
|
||||
chat.lines.splice(index, 1)
|
||||
await save(state)
|
||||
}
|
||||
// The cursor remains advanced so the removed message is not fetched again.
|
||||
return chat.lines
|
||||
})
|
||||
}
|
||||
|
||||
export function groupQuote(line: GroupLine) {
|
||||
return (line.text || line.attachment?.name || '').slice(0, 240)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import type { Attachment } from '../chat/attachments'
|
||||
import VoiceRecorder from '../chat/VoiceRecorder.vue'
|
||||
import VoiceMessage from '../chat/VoiceMessage.vue'
|
||||
import MediaPreview from '../chat/MediaPreview.vue'
|
||||
import MessageText from '../chat/MessageText.vue'
|
||||
|
||||
const session = useSession()
|
||||
const route = useRoute()
|
||||
@@ -54,31 +55,6 @@ const lines = computed(() => {
|
||||
(!favoritesOnly.value || line.favorite) &&
|
||||
(!query || [line.text, line.attachment?.name, line.quote].some((part) => part?.toLowerCase().includes(query))))
|
||||
})
|
||||
const internalBrowser = window.xhchat?.openBrowser
|
||||
|
||||
function messageParts(text: string) {
|
||||
const parts: { text: string; url?: string }[] = []
|
||||
let offset = 0
|
||||
for (const match of text.matchAll(/https?:\/\/[^\s<>"']+/giu)) {
|
||||
const label = match[0].replace(/[.,!?;:,。!?;:、))\]】]+$/u, '')
|
||||
try {
|
||||
const url = new URL(label)
|
||||
if (url.username || url.password || label.length > 4096 ||
|
||||
(url.protocol !== 'https:' && !['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname))) continue
|
||||
if (match.index > offset) parts.push({ text: text.slice(offset, match.index) })
|
||||
parts.push({ text: label, url: url.href })
|
||||
offset = match.index + label.length
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (offset < text.length) parts.push({ text: text.slice(offset) })
|
||||
return parts
|
||||
}
|
||||
|
||||
function openLink(url: string) {
|
||||
if (internalBrowser) void execute(() => internalBrowser(url))
|
||||
}
|
||||
let timer: ReturnType<typeof setInterval>
|
||||
let receiptTimer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
@@ -365,9 +341,7 @@ onBeforeUnmount(() => {
|
||||
<button type="button" class="plain" :disabled="busy"
|
||||
@click="saveAttachment(line.attachment)">下载 {{ line.attachment.name }}</button>
|
||||
</template>
|
||||
<span v-else><template v-for="(part, index) in messageParts(line.text)" :key="index"><button v-if="part.url && internalBrowser"
|
||||
type="button" class="chat-link" @click="openLink(part.url)">{{ part.text }}</button><a v-else-if="part.url"
|
||||
class="chat-link" :href="part.url" target="_blank" rel="noopener noreferrer">{{ part.text }}</a><template v-else>{{ part.text }}</template></template></span>
|
||||
<MessageText v-else :text="line.text" @error="error = $event" />
|
||||
<small v-if="view?.unsent.includes(line.id)">待发送</small>
|
||||
<small v-else-if="line.own && line.read && !line.recalled">已读</small>
|
||||
<small v-if="line.edited && !line.recalled">已编辑</small>
|
||||
|
||||
Reference in new issue
Block a user