- 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
113 lines
4.7 KiB
Vue
113 lines
4.7 KiB
Vue
<script setup lang="ts">
|
|
// The open conversation's name, presence (channels) or online dot (DMs),
|
|
// the back button of narrow layouts (with the unread count of everything
|
|
// else), the channel's pins and leave actions and, for DMs only, the
|
|
// conversation-actions slot (a call button, for example). Under it, the
|
|
// connection strip shows whenever realtime is not connected. Presence is
|
|
// not announced to screen readers.
|
|
//
|
|
// Slot conversation-actions: { conversation } (the open DM's row), rendered
|
|
// only when the open conversation is a DM.
|
|
import { badgeText } from '../../lib/chatUnread'
|
|
import { shortName } from '../../lib/chatFormat'
|
|
|
|
const props = withDefaults(defineProps<{ back?: boolean; pinsOpen?: boolean }>(), { back: true, pinsOpen: false })
|
|
const emit = defineEmits<{ back: []; pins: [] }>()
|
|
const { t } = useI18n()
|
|
const chat = useChat()
|
|
|
|
const channel = computed(() => chat.activeChannel)
|
|
const dm = computed(() => chat.activeDm)
|
|
/** The open conversation's kind and row, for the DM-only slot. */
|
|
const conversation = computed(() => dm.value ?? null)
|
|
const dmName = computed(() => (dm.value ? shortName(chat.members.get(dm.value.other_user_id), '', t('chat.someone')) : ''))
|
|
const title = computed(() => (channel.value ? `# ${channel.value.name}` : dmName.value))
|
|
const eyebrow = computed(() => (channel.value ? t('chat.header.channel') : t('chat.header.dm')))
|
|
|
|
/** The connection strip copy; none when connected (or before the chat connects). */
|
|
const strip = computed(() => {
|
|
switch (chat.connection) {
|
|
case 'connecting':
|
|
return t('chat.connection.connecting')
|
|
case 'reconnecting':
|
|
return t('chat.connection.reconnecting')
|
|
case 'unavailable':
|
|
return t('chat.connection.unavailable')
|
|
default:
|
|
return ''
|
|
}
|
|
})
|
|
|
|
/** What waits elsewhere: unread DMs and mentions outside the open conversation. */
|
|
const elsewhere = computed(() => {
|
|
const open = chat.activeId
|
|
let n = chat.attention
|
|
if (open !== null) n -= chat.isChannel(open) ? chat.mentionsOf(open) : chat.unreadOf(open)
|
|
return Math.max(0, n)
|
|
})
|
|
|
|
const stack = computed(() => chat.othersOnline.slice(0, 3))
|
|
const more = computed(() => Math.max(0, chat.othersOnline.length - 3))
|
|
const dmOnline = computed(() => !!dm.value && chat.isOnline(dm.value.other_user_id))
|
|
const leaving = ref(false)
|
|
|
|
async function leave() {
|
|
if (!channel.value || leaving.value) return
|
|
leaving.value = true
|
|
try {
|
|
if (await chat.leaveChannel(channel.value)) emit('back')
|
|
} finally {
|
|
leaving.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<header class="chat-head">
|
|
<div class="chat-head-row">
|
|
<button v-if="props.back" class="chat-icon-btn chat-back" type="button" :aria-label="t('chat.header.back')" @click="emit('back')">
|
|
<ChatIcon name="arrow-left" />
|
|
<span v-if="badgeText(elsewhere)" class="chat-badge"
|
|
><span aria-hidden="true">{{ badgeText(elsewhere) }}</span><span class="chat-sr">, {{ t('chat.unread.messages', { n: elsewhere }, elsewhere) }}</span></span
|
|
>
|
|
</button>
|
|
<div class="chat-head-name">
|
|
<span class="chat-eyebrow">{{ eyebrow }}</span>
|
|
<h2 class="chat-title">{{ title }}</h2>
|
|
</div>
|
|
<div class="chat-presence" aria-hidden="true">
|
|
<template v-if="channel && chat.presenceAvailable">
|
|
<span v-if="stack.length" class="chat-presence-stack">
|
|
<ChatAvatar v-for="id in stack" :key="id" :user-id="id" :member="chat.members.get(id)" :size="24" />
|
|
</span>
|
|
<span v-if="more" class="chat-presence-text">+{{ more }}</span>
|
|
<span class="chat-presence-dot"></span>
|
|
<span class="chat-presence-text">{{ chat.onlineCount > 1 ? t('chat.header.online', { n: chat.onlineCount }) : t('chat.header.onlyYou') }}</span>
|
|
</template>
|
|
<template v-else-if="dmOnline">
|
|
<span class="chat-presence-dot"></span>
|
|
<span class="chat-presence-text">{{ t('chat.header.dmOnline') }}</span>
|
|
</template>
|
|
</div>
|
|
<div class="chat-head-actions">
|
|
<slot v-if="conversation && conversation.type === 'dm'" name="conversation-actions" :conversation="conversation" />
|
|
<button
|
|
v-if="channel"
|
|
class="chat-icon-btn"
|
|
type="button"
|
|
:aria-pressed="pinsOpen ? 'true' : 'false'"
|
|
:aria-label="t('chat.pins.title')"
|
|
:title="t('chat.pins.title')"
|
|
@click="emit('pins')"
|
|
>
|
|
<ChatIcon name="pin" />
|
|
</button>
|
|
<button v-if="channel" class="chat-icon-btn" type="button" :aria-label="t('chat.header.leave')" :title="t('chat.header.leave')" :disabled="leaving" @click="leave">
|
|
<ChatIcon name="out" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
<p v-if="strip" class="chat-strip">{{ strip }}</p>
|
|
</template>
|