- 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
50 lines
2.9 KiB
Vue
50 lines
2.9 KiB
Vue
<script setup lang="ts">
|
|
// One message, left-aligned with the author's initials. The body goes
|
|
// through renderChatText only (escape-first inline markdown, autolinks and
|
|
// member mentions); it is the only HTML binding of the layer. Names and
|
|
// every other field are text bindings.
|
|
import type { ChatMember, ChatMessage } from '../../lib/types'
|
|
import { shortName } from '../../lib/chatFormat'
|
|
import { mentionsHandle, renderChatText } from '../../lib/chatText'
|
|
import { fmtDateTime, fmtTime } from '../../lib/format'
|
|
|
|
const props = defineProps<{ message: ChatMessage; followUp?: boolean; author?: ChatMember | null; meId: number | null }>()
|
|
const { t } = useI18n()
|
|
const chat = useChat()
|
|
|
|
const mine = computed(() => props.meId !== null && props.message.sender_id === props.meId)
|
|
const name = computed(() => shortName(props.author, props.message.sender_name, t('chat.someone')))
|
|
const time = computed(() => fmtTime(props.message.created_at))
|
|
const timeTitle = computed(() => fmtDateTime(props.message.created_at))
|
|
const isBot = computed(() => !!props.author?.is_bot)
|
|
/** Someone else's message that mentions you gets the accent marker. */
|
|
const mentionsMe = computed(() => !mine.value && mentionsHandle(props.message.content, chat.myHandle))
|
|
const editedTitle = computed(() => (props.message.edited_at ? t('chat.msg.editedAt', { at: fmtDateTime(props.message.edited_at) }) : ''))
|
|
const deleted = computed(() => !!props.message.deleted_at)
|
|
const rendered = computed(() => renderChatText(props.message.content, chat.membersByHandle))
|
|
</script>
|
|
|
|
<template>
|
|
<article class="chat-msg" :class="{ 'is-follow': followUp, 'is-mention': mentionsMe }" :data-message-id="message.id">
|
|
<div class="chat-msg-gutter">
|
|
<ChatAvatar v-if="!followUp" :user-id="message.sender_id" :member="author" :fallback="message.sender_name" :me="mine" />
|
|
<time v-else class="chat-msg-time" :datetime="message.created_at" :title="timeTitle">{{ time }}</time>
|
|
</div>
|
|
<div class="chat-msg-content">
|
|
<div v-if="!followUp" class="chat-msg-head">
|
|
<span class="chat-msg-name">{{ name }}</span>
|
|
<span v-if="isBot" class="chat-tag">{{ t('chat.msg.bot') }}</span>
|
|
<span v-else-if="mine" class="chat-tag chat-tag--me">{{ t('chat.msg.you') }}</span>
|
|
<time class="chat-msg-time" :datetime="message.created_at" :title="timeTitle">{{ time }}</time>
|
|
<span v-if="message.edited_at" class="chat-msg-edited" :title="editedTitle">{{ t('chat.msg.edited') }}</span>
|
|
</div>
|
|
<span v-else class="chat-sr">{{ name }}, {{ time }}:</span>
|
|
<p v-if="deleted" class="chat-msg-deleted">{{ t('chat.msg.deleted') }}</p>
|
|
<template v-else>
|
|
<div v-if="message.content" class="chat-msg-body" v-html="rendered"></div>
|
|
<span v-if="followUp && message.edited_at" class="chat-msg-edited" :title="editedTitle">{{ t('chat.msg.edited') }}</span>
|
|
</template>
|
|
</div>
|
|
</article>
|
|
</template>
|