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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
<!--
- @copyright Copyright (c) 2019 Marco Ambrosini <marcoambrosini@icloud.com>
-
- @author Marco Ambrosini <marcoambrosini@icloud.com>
-
- @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/>.
-->
<docs>
This component is intended to be used both in `NewMessageForm` and `Message`
components.
</docs>
<template>
<a href="#"
class="quote"
:class="{'quote-own-message': isOwnMessageQuoted}"
@click.prevent="handleQuoteClick">
<div class="quote__main">
<div class="quote__main__author" role="heading" aria-level="4">
{{ getDisplayName }}
</div>
<div v-if="isFileShareMessage"
class="quote__main__text">
<RichText :text="message"
:arguments="richParameters"
:autolink="true" />
</div>
<blockquote v-else
class="quote__main__text">
<p>{{ shortenedQuoteMessage }}</p>
</blockquote>
</div>
<div v-if="isNewMessageFormQuote" class="quote__main__right">
<NcButton type="tertiary"
:aria-label="cancelQuoteLabel"
@click="handleAbortReply">
<template #icon>
<Close :size="20" />
</template>
</NcButton>
</div>
</a>
</template>
<script>
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import Close from 'vue-material-design-icons/Close.vue'
import RichText from '@juliushaertl/vue-richtext'
import FilePreview from './MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue'
import DefaultParameter from './MessagesList/MessagesGroup/Message/MessagePart/DefaultParameter.vue'
import { EventBus } from '../services/EventBus.js'
export default {
name: 'Quote',
components: {
NcButton,
Close,
RichText,
},
props: {
actorId: {
type: String,
required: true,
},
/**
* The sender of the message to be replied to.
*/
actorType: {
type: String,
required: true,
},
/**
* The display name of the sender of the message.
*/
actorDisplayName: {
type: String,
required: true,
},
/**
* The text of the message to be replied to.
*/
message: {
type: String,
required: true,
},
/**
* The text of the message to be replied to.
*/
messageParameters: {
type: [Array, Object],
required: true,
},
/**
* The message id of the message to be replied to.
*/
id: {
type: Number,
required: true,
},
/**
* The conversation token of the message to be replied to.
*/
token: {
type: String,
required: true,
},
/**
* If the quote component is used in the `NewMessageForm` component we display
* the remove button.
*/
isNewMessageFormQuote: {
type: Boolean,
default: false,
},
/**
* The parent message's id
*/
parentId: {
type: Number,
required: true,
},
},
computed: {
/**
* The message actor display name.
*
* @return {string}
*/
getDisplayName() {
const displayName = this.actorDisplayName.trim()
if (displayName === '' && this.actorType === 'guests') {
return t('spreed', 'Guest')
}
if (displayName === '') {
return t('spreed', 'Deleted user')
}
return displayName
},
isOwnMessageQuoted() {
return this.actorId === this.$store.getters.getActorId()
&& this.actorType === this.$store.getters.getActorType()
},
isFileShareMessage() {
return this.message === '{file}'
&& 'file' in this.messageParameters
},
richParameters() {
const richParameters = {}
Object.keys(this.messageParameters).forEach(function(p) {
const type = this.messageParameters[p].type
if (type === 'file') {
richParameters[p] = {
component: FilePreview,
props: Object.assign({
smallPreview: true,
}, this.messageParameters[p]
),
}
} else {
richParameters[p] = {
component: DefaultParameter,
props: this.messageParameters[p],
}
}
}.bind(this))
return richParameters
},
/**
* This is a simplified version of the last chat message.
* Parameters are parsed without markup (just replaced with the name),
* e.g. no avatars on mentions.
*
* @return {string} A simple message to show below the conversation name
*/
simpleQuotedMessage() {
if (!Object.keys(this.messageParameters).length) {
return this.message
}
const params = this.messageParameters
let subtitle = this.message
// We don't really use rich objects in the subtitle, instead we fall back to the name of the item
Object.keys(params).forEach((parameterKey) => {
subtitle = subtitle.replaceAll('{' + parameterKey + '}', params[parameterKey].name)
})
return subtitle
},
// Shorten the message to 250 characters and append three dots to the end of the
// string. This is needed because on very wide screens, if the 250 characters
// fit, the css rules won't ellipsize the text-overflow.
shortenedQuoteMessage() {
if (this.simpleQuotedMessage.length >= 250) {
return this.simpleQuotedMessage.substring(0, 250) + '…'
} else {
return this.simpleQuotedMessage
}
},
cancelQuoteLabel() {
return t('spreed', 'Cancel quote')
},
},
methods: {
/**
* Stops the quote-reply operation by removing the MessageToBeReplied from
* the quoteReplyStore.
*/
handleAbortReply() {
this.$store.dispatch('removeMessageToBeReplied', this.token)
EventBus.$emit('focus-chat-input')
},
handleQuoteClick() {
EventBus.$emit('focus-message', this.parentId)
},
},
}
</script>
<style lang="scss" scoped>
@import '../assets/variables';
.quote {
border-left: 4px solid var(--color-border-dark);
margin: 4px 0 4px 8px;
padding-left: 8px;
display: flex;
max-width: $messages-list-max-width - $message-utils-width;
&.quote-own-message {
border-left: 4px solid var(--color-primary);
}
&__main {
display: flex;
flex-direction: column;
flex: 1 1 auto;
&__author {
color: var(--color-text-maxcontrast);
}
&__text {
color: var(--color-text-lighter);
white-space: pre-wrap;
word-break: break-word;
& p {
text-overflow: ellipsis;
overflow: hidden;
// Allow 2 lines max and ellipsize the overflow;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
}
}
&__right {
flex: 0 0 44px;
color: var(--color-text-maxcontrast);
font-size: 13px;
padding: 0 8px 0 8px;
position: relative;
margin: auto;
}
}
</style>
|