2022-12-05 05:41:53 +00:00
|
|
|
import { createMemo, Show } from 'solid-js'
|
2022-11-21 05:06:53 +00:00
|
|
|
import MarkdownIt from 'markdown-it'
|
2022-11-16 12:25:37 +00:00
|
|
|
import { clsx } from 'clsx'
|
|
|
|
import styles from './Message.module.scss'
|
2022-11-21 05:06:53 +00:00
|
|
|
import DialogAvatar from './DialogAvatar'
|
2022-12-05 05:41:53 +00:00
|
|
|
import { locale } from '../../stores/ui'
|
|
|
|
import type { Message, ChatMember } from '../../graphql/types.gen'
|
2022-11-16 12:25:37 +00:00
|
|
|
|
|
|
|
type Props = {
|
2022-12-05 05:41:53 +00:00
|
|
|
content: Message
|
|
|
|
ownId: number
|
|
|
|
members: ChatMember[]
|
2022-11-16 12:25:37 +00:00
|
|
|
}
|
|
|
|
|
2022-11-21 05:06:53 +00:00
|
|
|
const md = new MarkdownIt({
|
|
|
|
linkify: true
|
|
|
|
})
|
|
|
|
|
2022-11-16 12:25:37 +00:00
|
|
|
const Message = (props: Props) => {
|
2022-12-05 05:41:53 +00:00
|
|
|
const formattedTime = createMemo<string>(() => {
|
|
|
|
return new Date(props.content.createdAt * 1000).toLocaleTimeString(locale(), {
|
|
|
|
hour: 'numeric',
|
|
|
|
minute: 'numeric'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// возвращать ID автора
|
|
|
|
const isOwn = props.ownId === Number(props.content.author)
|
|
|
|
|
2022-11-16 12:25:37 +00:00
|
|
|
return (
|
2022-12-05 05:41:53 +00:00
|
|
|
<div class={clsx(styles.Message, isOwn && styles.own)}>
|
|
|
|
<Show when={!isOwn}>
|
2022-11-21 05:06:53 +00:00
|
|
|
<div class={styles.author}>
|
|
|
|
<DialogAvatar size="small" name={'Message Author'} />
|
|
|
|
<div class={styles.name}>Message Author</div>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
<div class={styles.body}>
|
2022-12-05 05:41:53 +00:00
|
|
|
<div innerHTML={md.render(props.content.body)} />
|
2022-11-21 05:06:53 +00:00
|
|
|
</div>
|
2022-12-05 05:41:53 +00:00
|
|
|
<div class={styles.time}>{formattedTime()}</div>
|
2022-11-16 12:25:37 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Message
|