forked from BRETT/BRETT
25 lines
639 B
TypeScript
25 lines
639 B
TypeScript
import type { CommentAttachment } from '~~/shared/utils/attachments'
|
|
|
|
export interface LiveComment {
|
|
id: number
|
|
content: string
|
|
createdAt: string
|
|
userName: string
|
|
userId: number
|
|
userColor: string | null
|
|
userAvatarUrl: string | null
|
|
uploadId: string
|
|
attachments?: CommentAttachment[]
|
|
}
|
|
|
|
export function useLiveComments() {
|
|
const liveComments = useState<LiveComment[]>('comments:live', () => [])
|
|
|
|
function pushLive(comment: LiveComment) {
|
|
if (liveComments.value.some(c => c.id === comment.id)) return
|
|
liveComments.value = [comment, ...liveComments.value].slice(0, 50)
|
|
}
|
|
|
|
return { liveComments, pushLive }
|
|
}
|