- threads: reply counts, ChatThreadPane with replies, live replies and thread mute - channel pins in ChatPinsPanel; a refused pin hides the action for the session - reactions, attachments with upload progress and bearer downloads, inline edits, the delete dialog (moderators also in channels) - link cards with the registerEmbedRenderer registry; linkify for escaped text - slash commands: the command picker over chatbots, dispatch with sender-only answers - slots conversation-actions (DMs only) and sidebar-footer - chat-tokens.css and chat-base.css, EN and PL copy, README
95 lines
3.0 KiB
Vue
95 lines
3.0 KiB
Vue
<script setup lang="ts">
|
|
// "Delete message?": the one confirmation of the chat. A native
|
|
// modal dialog; the keep button gets the initial focus, Esc and the
|
|
// backdrop cancel, and a failed delete keeps it open with the error line.
|
|
// One instance per message list; focus goes back to the opener, or to the
|
|
// list when the opener left with the deleted message.
|
|
import type { ChatMessage } from '../../lib/types'
|
|
import { shortName } from '../../lib/chatFormat'
|
|
|
|
const { t } = useI18n()
|
|
const chat = useChat()
|
|
const uid = useId()
|
|
const dialog = ref<HTMLDialogElement | null>(null)
|
|
const keepBtn = ref<HTMLButtonElement | null>(null)
|
|
const target = ref<ChatMessage | null>(null)
|
|
const busy = ref(false)
|
|
const error = ref('')
|
|
let opener: HTMLElement | null = null
|
|
let list: HTMLElement | null = null
|
|
|
|
const own = computed(() => !!target.value && target.value.sender_id === chat.userId)
|
|
const body = computed(() => {
|
|
const m = target.value
|
|
if (!m || own.value) return t('chat.delete.own')
|
|
return t('chat.delete.other', { name: shortName(chat.members.get(m.sender_id), m.sender_name, t('chat.someone')) })
|
|
})
|
|
|
|
function open(message: ChatMessage, from?: HTMLElement | null) {
|
|
target.value = message
|
|
error.value = ''
|
|
busy.value = false
|
|
opener = from ?? (document.activeElement instanceof HTMLElement ? document.activeElement : null)
|
|
list = opener?.closest<HTMLElement>('.chat-list, .chat-thread-list') ?? null
|
|
dialog.value?.showModal()
|
|
void nextTick(() => keepBtn.value?.focus())
|
|
}
|
|
|
|
function close() {
|
|
dialog.value?.close()
|
|
}
|
|
|
|
function onCancel(e: Event) {
|
|
// Esc while the delete is in flight waits for the answer.
|
|
if (busy.value) e.preventDefault()
|
|
}
|
|
|
|
function onClose() {
|
|
if (opener?.isConnected) opener.focus()
|
|
else list?.focus()
|
|
opener = null
|
|
list = null
|
|
target.value = null
|
|
}
|
|
|
|
function onBackdrop(e: MouseEvent) {
|
|
if (e.target === dialog.value && !busy.value) close()
|
|
}
|
|
|
|
async function confirm() {
|
|
const m = target.value
|
|
if (!m || busy.value) return
|
|
busy.value = true
|
|
error.value = ''
|
|
const failed = await chat.remove(m)
|
|
busy.value = false
|
|
if (failed) {
|
|
error.value = t(`chat.${failed}`)
|
|
return
|
|
}
|
|
close()
|
|
}
|
|
|
|
defineExpose({ open })
|
|
</script>
|
|
|
|
<template>
|
|
<dialog
|
|
ref="dialog"
|
|
class="chat-dialog chat-confirm"
|
|
:aria-labelledby="`chat-delete-h-${uid}`"
|
|
:aria-describedby="`chat-delete-b-${uid}`"
|
|
@cancel="onCancel"
|
|
@close="onClose"
|
|
@click="onBackdrop"
|
|
>
|
|
<h2 :id="`chat-delete-h-${uid}`" class="chat-dialog-title">{{ t('chat.delete.title') }}</h2>
|
|
<p :id="`chat-delete-b-${uid}`" class="chat-confirm-body">{{ body }}</p>
|
|
<p v-if="error" class="chat-error" role="alert">{{ error }}</p>
|
|
<div class="chat-btn-row">
|
|
<button class="chat-btn chat-btn--danger" type="button" :aria-busy="busy ? 'true' : undefined" :disabled="busy" @click="confirm">{{ t('chat.delete.confirm') }}</button>
|
|
<button ref="keepBtn" class="chat-btn chat-btn--ghost" type="button" :disabled="busy" @click="close">{{ t('chat.delete.keep') }}</button>
|
|
</div>
|
|
</dialog>
|
|
</template>
|