- realtime.ts: the page's one Centrifuge client, setRealtimeAuth, onUserEvent for user:{me} events the chat does not handle
- chatEvents, chatFormat, chatText, chatUnread, format, media, tabs ported; copy passed in localized
- useChat over useState: channels with join and leave, DMs, member list, unread and mention counts, read marks, typing, presence, polling fallback
- ChatPanel, ChatHeader, ChatMessage, ChatDmList, ChatMemberPicker, ChatMentionPopup, ChatAvatar, ChatIcon, ChatNotices
- EN and PL strings
63 lines
2.6 KiB
Vue
63 lines
2.6 KiB
Vue
<script setup lang="ts">
|
|
// The host's channels: the joined ones to open, the ones the user left to
|
|
// join again. There is no create button: members join and leave the
|
|
// channels the host seeds. The sidebar-footer slot sits below the list
|
|
// (an app's link to its friends page, for example).
|
|
import type { ChatChannel } from '../../lib/types'
|
|
import { badgeText } from '../../lib/chatUnread'
|
|
|
|
const emit = defineEmits<{ opened: [conversationId: number] }>()
|
|
const { t } = useI18n()
|
|
const chat = useChat()
|
|
|
|
const left = computed(() => chat.channels.filter((c) => !c.joined))
|
|
const busy = ref<number | null>(null)
|
|
|
|
async function open(c: ChatChannel) {
|
|
if (busy.value !== null) return
|
|
busy.value = c.id
|
|
try {
|
|
if (await chat.openChannel(c)) emit('opened', c.conversation_id)
|
|
} finally {
|
|
busy.value = null
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<nav class="chat-channels" :aria-label="t('chat.channels')">
|
|
<h2 class="chat-section-title">{{ t('chat.channels') }}</h2>
|
|
<ul class="chat-rows">
|
|
<li v-for="c in chat.joinedChannels" :key="c.id">
|
|
<button
|
|
class="chat-row chat-channel"
|
|
:class="{ 'is-unread': c.unread > 0, 'is-active': chat.activeId === c.conversation_id }"
|
|
type="button"
|
|
:data-channel-slug="c.slug"
|
|
:aria-current="chat.activeId === c.conversation_id ? 'true' : undefined"
|
|
:aria-busy="busy === c.id ? 'true' : undefined"
|
|
@click="open(c)"
|
|
>
|
|
<span class="chat-row-name"><span aria-hidden="true">#</span> {{ c.name }}</span>
|
|
<span v-if="c.mentions > 0" class="chat-badge chat-badge--mention"
|
|
><span aria-hidden="true">@</span><span class="chat-sr">, {{ t('chat.unread.mentions', { n: c.mentions }, c.mentions) }}</span></span
|
|
>
|
|
<span v-if="badgeText(c.unread)" class="chat-badge"
|
|
><span aria-hidden="true">{{ badgeText(c.unread) }}</span><span class="chat-sr">, {{ t('chat.unread.messages', { n: c.unread }, c.unread) }}</span></span
|
|
>
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
<template v-if="left.length">
|
|
<h3 class="chat-section-subtitle">{{ t('chat.channelsLeft') }}</h3>
|
|
<ul class="chat-rows">
|
|
<li v-for="c in left" :key="c.id" class="chat-row chat-row--static">
|
|
<span class="chat-row-name"><span aria-hidden="true">#</span> {{ c.name }}</span>
|
|
<button class="chat-link-btn" type="button" :data-channel-slug="c.slug" :disabled="busy === c.id" @click="open(c)">{{ t('chat.join') }}</button>
|
|
</li>
|
|
</ul>
|
|
</template>
|
|
<slot name="sidebar-footer" />
|
|
</nav>
|
|
</template>
|