Files
Jakub Zych 269c75b5dd feat: threads, pins, reactions, attachments, link embeds and the command picker
- 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
2026-10-31 14:04:54 +01:00

81 lines
3.0 KiB
Vue

<script setup lang="ts">
// The open conversation: header (with the pins panel of a channel),
// messages, the typing line and the composer. With nothing open it shows
// the empty state.
//
// Slot conversation-actions: forwarded to ChatHeader (DMs only).
import { shortName } from '../../lib/chatFormat'
const props = withDefaults(defineProps<{ visible?: boolean; back?: boolean }>(), { visible: true, back: true })
const emit = defineEmits<{ back: [] }>()
const { t } = useI18n()
const chat = useChat()
const list = ref<{ scrollToBottom: (smooth?: boolean) => void } | null>(null)
const composer = ref<{ focus: () => void } | null>(null)
const pinsOpen = ref(false)
watch(
() => chat.activeId,
() => (pinsOpen.value = false),
)
const dmName = computed(() => (chat.activeDm ? shortName(chat.members.get(chat.activeDm.other_user_id), '', t('chat.someone')) : ''))
const name = computed(() => (chat.activeChannel ? `# ${chat.activeChannel.name}` : dmName.value))
/** Who is typing in the open conversation; empty without realtime. */
const typingLine = computed(() => {
const id = chat.activeId
if (id === null) return ''
const names = chat.typingIn(id).map((u) => shortName(chat.members.get(u), '', t('chat.someone')))
if (!names.length) return ''
if (names.length === 1) return t('chat.typing.one', { a: names[0] })
if (names.length === 2) return t('chat.typing.two', { a: names[0], b: names[1] })
return t('chat.typing.many')
})
// The store needs to know whether the conversation is on screen.
watch(
() => props.visible,
(v) => (chat.panelVisible = v),
{ immediate: true },
)
onBeforeUnmount(() => (chat.panelVisible = false))
function focus() {
void nextTick(() => composer.value?.focus())
}
defineExpose({ focus })
</script>
<template>
<section class="chat-panel" :aria-label="name || t('chat.name')">
<template v-if="chat.activeId !== null && chat.kind">
<ChatHeader :back="back" :pins-open="pinsOpen" @back="emit('back')" @pins="pinsOpen = !pinsOpen">
<template #conversation-actions="slotProps"><slot name="conversation-actions" v-bind="slotProps" /></template>
</ChatHeader>
<ChatPinsPanel v-if="pinsOpen && chat.activeChannel" @close="pinsOpen = false" />
<ChatMessageList
ref="list"
:key="chat.activeId"
:conversation-id="chat.activeId"
:name="name"
:kind="chat.kind"
:other-name="dmName"
:visible="visible"
/>
<div class="chat-typing" aria-hidden="true">{{ typingLine }}</div>
<ChatComposer
ref="composer"
:key="`c-${chat.activeId}`"
:conversation-id="chat.activeId"
:label="t('chat.composer.label', { name })"
:placeholder="t('chat.composer.placeholder', { name })"
@sent="list?.scrollToBottom()"
/>
</template>
<div v-else class="chat-panel-empty">
<p class="chat-panel-empty-title">{{ t('chat.pickTitle') }}</p>
<p class="chat-muted">{{ t('chat.pickText') }}</p>
</div>
</section>
</template>