-
Notifications
You must be signed in to change notification settings - Fork 753
Expand file tree
/
Copy pathChatLog.vue
More file actions
176 lines (151 loc) · 3.41 KB
/
ChatLog.vue
File metadata and controls
176 lines (151 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template lang="pug">
.chatlog
n-timeline(
v-if='state.items.length > 0'
:icon-size='18'
size='large'
)
n-timeline-item(
v-for='item of state.items'
:key='item.id'
type='default'
:color='item.color'
:title='item.author'
:time='item.time'
)
template(#default)
div(v-html='item.text')
span.text-body-secondary(v-else)
em No chat log available.
</template>
<script setup>
import { onMounted, reactive } from 'vue'
import { DateTime } from 'luxon'
import { emojify } from '@twuni/emojify'
import uniq from 'lodash-es/uniq'
import {
NTimeline,
NTimelineItem
} from 'naive-ui'
// PROPS
const props = defineProps({
componentId: {
type: String,
required: true
}
})
// STATE
const state = reactive({
items: []
})
// bs5 colors
const colors = [
'#0d6efd',
'#dc3545',
'#20c997',
'#6f42c1',
'#fd7e14',
'#198754',
'#0dcaf0',
'#d63384',
'#ffc107',
'#6610f2',
'#adb5bd'
]
// MOUNTED
onMounted(() => {
const authorColors = {}
// Get chat log data from embedded json tag
const chatLog = JSON.parse(document.getElementById(`${props.componentId}-data`).textContent || '[]')
if (chatLog.length > 0) {
const authorNames = uniq(chatLog.map(l => l.author))
let idx = 1
let colorIdx = 0
for (const logItem of chatLog) {
// -> Get unique color per author
if (!authorColors[logItem.author]) {
authorColors[logItem.author] = colors[colorIdx]
colorIdx++
if (colorIdx >= colors.length) {
colorIdx = 0
}
}
// -> Format text
let txt = emojify(logItem.text)
if (txt.indexOf('@') >= 0) {
for (const authorName of authorNames) {
txt = txt.replaceAll(`@${authorName}`, `<span class="user-mention">${authorName}</span>`)
}
}
txt = txt.replaceAll('href="/user_uploads/', 'href="https://zulip.ietf.org/user_uploads/')
// -> Generate log item
state.items.push({
id: `logitem-${idx}`,
color: authorColors[logItem.author],
author: logItem.author,
text: txt,
time: DateTime.fromISO(logItem.time).toFormat('dd LLLL yyyy \'at\' HH:mm:ss a ZZZZ')
})
idx++
}
}
})
</script>
<style lang="scss">
@import '../shared/colors.scss';
.chatlog {
.n-timeline-item-content__content {
> div > p:last-child {
margin-bottom: 0;
}
blockquote {
background-color: $gray-100;
border-radius: 5px;
padding: 8px;
margin-top: -8px;
> p:last-child {
margin-bottom: 0;
}
}
.message_inline_image {
display: none;
}
// Manual user mention
.user-mention {
display: inline-block;
padding: 1px 5px;
background-color: rgba($purple, .05);
color: $purple;
font-weight: 500;
border-radius: 4px;
> .user-mention {
padding: 0;
&::before {
display: none;
}
}
&::before {
content: '@';
}
}
// User reply mention
.user-mention + a {
text-decoration: none;
color: $purple;
font-style: italic;
cursor: default;
}
}
}
[data-bs-theme="dark"] .chatlog {
.n-timeline-item-content__title {
color: #d63384 !important;
}
.n-timeline-item-content__content {
color: #fff !important;
}
.n-timeline-item-content__meta {
color: #0569ffd9 !important;
}
}
</style>