支持跨端加密消息编辑与撤回
This commit is contained in:
1 parent
9b8c2026ea
commit
f5f116a266
6 files changed
+140
-23
No files matched your search
@@ -2,7 +2,7 @@
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useSession } from '../session'
|
||||
import { enableChat, localMessageAction, send, synchronize, trust } from '../chat/chat'
|
||||
import { enableChat, localMessageAction, mutateMessage, send, synchronize, trust } from '../chat/chat'
|
||||
import type { ChatLine } from '../chat/chat'
|
||||
import { downloadAttachment } from '../chat/attachments'
|
||||
import type { Attachment } from '../chat/attachments'
|
||||
@@ -17,6 +17,8 @@ const search = ref('')
|
||||
const favoritesOnly = ref(false)
|
||||
const reply = ref<ChatLine>()
|
||||
const deleting = ref<ChatLine>()
|
||||
const editing = ref<ChatLine>()
|
||||
const recalling = ref<ChatLine>()
|
||||
const error = ref('')
|
||||
const busy = ref(false)
|
||||
const view = ref<Awaited<ReturnType<typeof synchronize>>>()
|
||||
@@ -75,9 +77,29 @@ function confirm() {
|
||||
function submit() {
|
||||
void execute(async () => {
|
||||
if (!session.identity || !peer.value) return
|
||||
await send(session.identity, target.value, peer.value, draft.value, session.authorized, reply.value)
|
||||
if (editing.value) {
|
||||
await mutateMessage(session.identity, target.value, peer.value, { action: 'edit', id: editing.value.id, text: draft.value }, session.authorized)
|
||||
} else {
|
||||
await send(session.identity, target.value, peer.value, draft.value, session.authorized, reply.value)
|
||||
}
|
||||
draft.value = ''
|
||||
reply.value = undefined
|
||||
editing.value = undefined
|
||||
await refresh()
|
||||
})
|
||||
}
|
||||
|
||||
function edit(line: ChatLine) {
|
||||
editing.value = line
|
||||
reply.value = undefined
|
||||
draft.value = line.text
|
||||
}
|
||||
|
||||
function recall() {
|
||||
void execute(async () => {
|
||||
if (!session.identity || !peer.value || !recalling.value) return
|
||||
await mutateMessage(session.identity, target.value, peer.value, { action: 'recall', id: recalling.value.id }, session.authorized)
|
||||
recalling.value = undefined
|
||||
await refresh()
|
||||
})
|
||||
}
|
||||
@@ -124,6 +146,9 @@ watch(selected, () => {
|
||||
favoritesOnly.value = false
|
||||
reply.value = undefined
|
||||
deleting.value = undefined
|
||||
editing.value = undefined
|
||||
recalling.value = undefined
|
||||
draft.value = ''
|
||||
})
|
||||
watch(() => [session.inboxChanges, session.contactChanges, session.connection], sync)
|
||||
onMounted(() => { timer = setInterval(sync, 10_000) })
|
||||
@@ -169,14 +194,18 @@ onBeforeUnmount(() => clearInterval(timer))
|
||||
<ol class="chat-lines" aria-label="消息记录" aria-live="polite">
|
||||
<li v-for="line in lines" :key="line.peer + ':' + line.own + ':' + line.id" :class="{ own: line.own }">
|
||||
<blockquote v-if="line.quote">{{ line.quote }}</blockquote>
|
||||
<button v-if="line.attachment" type="button" class="plain" :disabled="busy"
|
||||
<span v-if="line.recalled" class="muted">消息已撤回</span>
|
||||
<button v-else-if="line.attachment" type="button" class="plain" :disabled="busy"
|
||||
@click="saveAttachment(line.attachment)">下载 {{ line.attachment.name }}</button>
|
||||
<span v-else>{{ line.text }}</span><small v-if="view?.unsent.includes(line.id)">待发送</small>
|
||||
<small v-if="line.edited && !line.recalled">已编辑</small>
|
||||
<div class="message-actions">
|
||||
<button type="button" class="plain" :disabled="busy" @click="reply = line">引用</button>
|
||||
<button type="button" class="plain" :disabled="busy" @click="localAction(line, 'favorite')">
|
||||
<button v-if="!line.recalled" type="button" class="plain" :disabled="busy || Boolean(editing)" @click="reply = line">引用</button>
|
||||
<button v-if="!line.recalled" type="button" class="plain" :disabled="busy" @click="localAction(line, 'favorite')">
|
||||
{{ line.favorite ? '取消收藏' : '收藏' }}
|
||||
</button>
|
||||
<button v-if="line.own && !line.recalled && !line.attachment" type="button" class="plain" :disabled="busy" @click="edit(line)">编辑</button>
|
||||
<button v-if="line.own && !line.recalled" type="button" class="plain" :disabled="busy" @click="recalling = line">撤回</button>
|
||||
<button type="button" class="plain" :disabled="busy || view?.unsent.includes(line.id)" @click="deleting = line">本机删除</button>
|
||||
</div>
|
||||
</li>
|
||||
@@ -187,14 +216,23 @@ onBeforeUnmount(() => clearInterval(timer))
|
||||
<button type="button" class="plain" :disabled="busy" @click="localAction(deleting, 'remove')">确认删除</button>
|
||||
<button type="button" class="plain" @click="deleting = undefined">取消</button>
|
||||
</div>
|
||||
<div v-if="recalling" class="confirmation">
|
||||
<p>撤回这条消息?</p>
|
||||
<button type="button" class="plain" :disabled="busy" @click="recall">确认撤回</button>
|
||||
<button type="button" class="plain" @click="recalling = undefined">取消</button>
|
||||
</div>
|
||||
<form class="chat-compose" @submit.prevent="submit">
|
||||
<div v-if="editing" class="chat-quote">
|
||||
<span>正在编辑消息</span>
|
||||
<button type="button" class="plain" @click="editing = undefined; draft = ''">取消编辑</button>
|
||||
</div>
|
||||
<div v-if="reply" class="chat-quote">
|
||||
<span>引用 {{ (reply.text || reply.attachment?.name || '').slice(0, 80) }}</span>
|
||||
<button type="button" class="plain" @click="reply = undefined">取消引用</button>
|
||||
</div>
|
||||
<label>发送附件<input type="file" :disabled="busy" @change="attach"></label>
|
||||
<label v-if="!editing">发送附件<input type="file" :disabled="busy" @change="attach"></label>
|
||||
<label>消息<textarea v-model="draft" required rows="3" maxlength="4000"></textarea></label>
|
||||
<button class="primary" :disabled="busy || !draft.trim()">发送</button>
|
||||
<button class="primary" :disabled="busy || !draft.trim()">{{ editing ? '保存编辑' : '发送' }}</button>
|
||||
</form>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
Reference in new issue
Block a user