增加加密群公告和群主转让

This commit is contained in:
xhgit committed 2026-11-15 17:20:18 +08:00
1 parent 52c0e52ffd
commit 47b76080c6
10 files changed
+163 -22

No files matched your search

+34
View File
@@ -20,6 +20,7 @@ const code = ref('')
const codes = ref<Record<string, string>>({})
const selected = ref<Record<string, string>>({})
const draft = ref('')
const announcementDraft = ref<string>()
const search = ref('')
const favoritesOnly = ref(false)
const historyViews = [
@@ -146,6 +147,17 @@ function establish() {
})
}
function saveAnnouncement() {
const identity = session.identity
const announcement = announcementDraft.value
if (!identity || announcement === undefined) return
void run(async () => {
await sendGroupMessage(identity, props.group, { announcement }, session.authorized)
announcementDraft.value = undefined
await refresh()
})
}
function send() {
const identity = session.identity
if (identity) void run(async () => {
@@ -239,6 +251,7 @@ watch(() => session.groupChange, (event) => { if (event?.groupId === props.group
watch(() => session.connection, (connection) => { if (connection === '实时连接已建立') queueRefresh() })
watch(currentEpoch, (epoch, previous) => {
if (!previous || epoch === previous) return
announcementDraft.value = undefined
if (editing.value || replying.value) draft.value = ''
editing.value = undefined
replying.value = undefined
@@ -283,6 +296,24 @@ onBeforeUnmount(() => {
<p v-if="ready" role="status">群加密已建立</p>
<p v-else-if="view?.current && !view.current.welcome">当前设备未获分配群密钥。</p>
<p v-else-if="!view?.current && group.role !== 'owner'">等待群主建立群加密会话。</p>
<section v-if="view && (view.announcement || (ready && group.role === 'owner'))" class="group-announcement" aria-label="群公告">
<h4>群公告</h4>
<p v-if="view.announcement" class="announcement-text">{{ view.announcement }}</p>
<p v-else class="muted">暂无群公告。</p>
<template v-if="ready && group.role === 'owner'">
<button v-if="announcementDraft === undefined" type="button" class="plain" :disabled="busy || view.hasPending"
@click="announcementDraft = view.announcement ?? ''">{{ view.announcement ? '编辑群公告' : '写群公告' }}</button>
<form v-else class="group-chat-composer" @submit.prevent="saveAnnouncement">
<label>公告内容<textarea v-model="announcementDraft" rows="3" maxlength="2000" /></label>
<div class="message-actions">
<button class="primary" :disabled="busy || view.hasPending || announcementDraft.trim() === (view.announcement ?? '')">
{{ announcementDraft.trim() ? '发布公告' : '清除公告' }}
</button>
<button type="button" class="plain" @click="announcementDraft = undefined">取消</button>
</div>
</form>
</template>
</section>
<details :open="!ready">
<summary>群设备和安全码</summary>
<p>本机安全码 <code class="group-security-code">{{ code }}</code></p>
@@ -385,6 +416,9 @@ onBeforeUnmount(() => {
<style scoped>
.group-chat { display: grid; gap: .7rem; padding-block: 1rem; }
.group-chat p, .group-chat h3 { margin: 0; }
.group-announcement { display: grid; gap: .45rem; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: .45rem; }
.group-announcement h4 { margin: 0; }
.announcement-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.group-security-code { overflow-wrap: anywhere; }
.group-device-member { margin-block: .75rem; }
.group-chat-lines { display: grid; gap: .75rem; max-height: 24rem; overflow-y: auto; margin: 0; padding: .7rem 0; list-style: none; }