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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
<!--
- @copyright Copyright (c) 2019 Marco Ambrosini <marcoambrosini@pm.me>
-
- @author Marco Ambrosini <marcoambrosini@pm.me>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<template>
<div class="message-group">
<div v-if="dateSeparator"
class="message-group__date-header">
<span class="date"
role="heading"
aria-level="3">{{ dateSeparator }}</span>
</div>
<div class="wrapper"
:class="{'wrapper--system': isSystemMessage}">
<div v-if="!isSystemMessage" class="messages__avatar">
<AuthorAvatar
:author-type="actorType"
:author-id="actorId"
:display-name="actorDisplayName" />
</div>
<ul class="messages">
<Message
v-for="(message, index) of messages"
:key="message.id"
v-bind="message"
:is-first-message="index === 0"
:next-message-id="(messages[index + 1] && messages[index + 1].id) || nextMessageId"
:previous-message-id="(index > 0 && messages[index - 1].id) || previousMessageId"
:last-read-message-id="lastReadMessageId"
:actor-type="actorType"
:actor-id="actorId"
:actor-display-name="actorDisplayName"
:show-author="!isSystemMessage"
:is-temporary="message.timestamp === 0" />
</ul>
</div>
</div>
</template>
<script>
import AuthorAvatar from './AuthorAvatar'
import Message from './Message/Message'
import { ATTENDEE } from '../../../constants'
export default {
name: 'MessagesGroup',
components: {
AuthorAvatar,
Message,
},
inheritAttrs: false,
props: {
/**
* The message id.
*/
// FIXME: looks unused
id: {
type: [String, Number],
required: true,
},
/**
* The conversation token.
*/
token: {
type: String,
required: true,
},
/**
* The messages object.
*/
messages: {
type: Array,
required: true,
},
previousMessageId: {
type: [String, Number],
default: 0,
},
nextMessageId: {
type: [String, Number],
default: 0,
},
// FIXME: read from messagesStore as this is the same value for all
lastReadMessageId: {
type: [String, Number],
default: 0,
},
},
computed: {
/**
* The message actor type.
* @returns {string}
*/
actorType() {
return this.messages[0].actorType
},
/**
* The message actor id.
* @returns {string}
*/
actorId() {
return this.messages[0].actorId
},
/**
* The message date.
* @returns {string}
*/
dateSeparator() {
return this.messages[0].dateSeparator || ''
},
/**
* The message actor display name.
* @returns {string}
*/
actorDisplayName() {
const displayName = this.messages[0].actorDisplayName.trim()
if (this.actorType === ATTENDEE.ACTOR_TYPE.GUESTS) {
return this.$store.getters.getGuestName(this.token, this.actorId)
}
if (displayName === '') {
return t('spreed', '[Unknown username]')
}
return displayName
},
/**
* Whether the given message is a system message
* @returns {bool}
*/
isSystemMessage() {
return this.messages[0].systemMessage.length !== 0
},
},
}
</script>
<style lang="scss" scoped>
@import '../../../assets/variables';
.message-group {
&__date-header {
display: block;
text-align: center;
padding-top: 20px;
position: relative;
margin: 20px 0;
.date {
margin-right: $clickable-area * 2;
content: attr(data-date);
padding: 4px 12px;
left: 50%;
color: var(--color-text-maxcontrast);
background-color: var(--color-background-dark);
border-radius: var(--border-radius-pill);
}
}
}
.wrapper {
max-width: $messages-list-max-width;
display: flex;
margin: auto;
padding: 0;
&--system {
padding-left: $clickable-area + 8px;
}
&:focus {
background-color: rgba(47, 47, 47, 0.068);
}
}
.messages {
flex: auto;
display: flex;
padding: 8px 0 8px 0;
flex-direction: column;
width: 100%;
&__avatar {
position: sticky;
top: 0;
height: 52px;
width: 52px;
padding: 18px 10px 10px 10px;
}
}
</style>
|