138
138
139
139
<script>
140
140
141
+ import { toRefs } from 'vue'
141
142
import { Fragment } from 'vue-frag'
142
143
import { isNavigationFailure, NavigationFailureType } from 'vue-router'
143
144
@@ -162,7 +163,8 @@ import NcListItem from '@nextcloud/vue/dist/Components/NcListItem.js'
162
163
163
164
import ConversationIcon from './../../ConversationIcon.vue'
164
165
165
- import { CONVERSATION, PARTICIPANT, ATTENDEE } from '../../../constants.js'
166
+ import { useConversationInfo } from '../../../composables/useConversationInfo.js'
167
+ import { CONVERSATION, PARTICIPANT } from '../../../constants.js'
166
168
import { copyConversationLinkToClipboard } from '../../../services/urlService.js'
167
169
168
170
export default {
@@ -215,6 +217,16 @@ export default {
215
217
216
218
emits: ['click'],
217
219
220
+ setup(props) {
221
+ const { item, isSearchResult } = toRefs(props)
222
+ const { counterType, conversationInformation } = useConversationInfo({ item, isSearchResult })
223
+
224
+ return {
225
+ counterType,
226
+ conversationInformation,
227
+ }
228
+ },
229
+
218
230
data() {
219
231
return {
220
232
isDialogOpen: false,
@@ -226,18 +238,6 @@ export default {
226
238
return this.$store.getters.getMainContainerSelector()
227
239
},
228
240
229
- counterType() {
230
- if (this.item.unreadMentionDirect || (this.item.unreadMessages !== 0 && (
231
- this.item.type === CONVERSATION.TYPE.ONE_TO_ONE || this.item.type === CONVERSATION.TYPE.ONE_TO_ONE_FORMER
232
- ))) {
233
- return 'highlighted'
234
- } else if (this.item.unreadMention) {
235
- return 'outlined'
236
- } else {
237
- return ''
238
- }
239
- },
240
-
241
241
canFavorite() {
242
242
return this.item.participantType !== PARTICIPANT.TYPE.USER_SELF_JOINED
243
243
},
@@ -266,105 +266,13 @@ export default {
266
266
return this.item.canLeaveConversation
267
267
},
268
268
269
- conversationInformation() {
270
- // temporary item while joining
271
- if (!this.isSearchResult && !this.item.actorId) {
272
- return t('spreed', 'Joining conversation …')
273
- }
274
-
275
- if (!Object.keys(this.lastChatMessage).length) {
276
- return ''
277
- }
278
-
279
- if (this.shortLastChatMessageAuthor === '') {
280
- return this.simpleLastChatMessage
281
- }
282
-
283
- if (this.lastChatMessage.actorId === this.$store.getters.getUserId()) {
284
- return t('spreed', 'You: {lastMessage}', {
285
- lastMessage: this.simpleLastChatMessage,
286
- }, undefined, {
287
- escape: false,
288
- sanitize: false,
289
- })
290
- }
291
-
292
- if (this.item.type === CONVERSATION.TYPE.ONE_TO_ONE
293
- || this.item.type === CONVERSATION.TYPE.ONE_TO_ONE_FORMER
294
- || this.item.type === CONVERSATION.TYPE.CHANGELOG) {
295
- return this.simpleLastChatMessage
296
- }
297
-
298
- return t('spreed', '{actor}: {lastMessage}', {
299
- actor: this.shortLastChatMessageAuthor,
300
- lastMessage: this.simpleLastChatMessage,
301
- }, undefined, {
302
- escape: false,
303
- sanitize: false,
304
- })
305
- },
306
-
307
- // Get the last message for this conversation from the message store instead
308
- // of the conversations store. The message store is updated immediately,
309
- // while the conversations store is refreshed every 30 seconds. This allows
310
- // to display message previews in this component as soon as new messages are
311
- // received by the server.
312
- lastChatMessage() {
313
- return this.item.lastMessage
314
- },
315
-
316
269
dialogMessage() {
317
270
return t('spreed', 'Do you really want to delete "{displayName}"?', this.item, undefined, {
318
271
escape: false,
319
272
sanitize: false,
320
273
})
321
274
},
322
275
323
- /**
324
- * This is a simplified version of the last chat message.
325
- * Parameters are parsed without markup (just replaced with the name),
326
- * e.g. no avatars on mentions.
327
- *
328
- * @return {string} A simple message to show below the conversation name
329
- */
330
- simpleLastChatMessage() {
331
- if (!Object.keys(this.lastChatMessage).length) {
332
- return ''
333
- }
334
-
335
- const params = this.lastChatMessage.messageParameters
336
- let subtitle = this.lastChatMessage.message.trim()
337
-
338
- // We don't really use rich objects in the subtitle, instead we fall back to the name of the item
339
- Object.keys(params).forEach((parameterKey) => {
340
- subtitle = subtitle.replace('{' + parameterKey + '}', params[parameterKey].name)
341
- })
342
-
343
- return subtitle
344
- },
345
-
346
- /**
347
- * @return {string} Part of the name until the first space
348
- */
349
- shortLastChatMessageAuthor() {
350
- if (!Object.keys(this.lastChatMessage).length
351
- || this.lastChatMessage.systemMessage.length) {
352
- return ''
353
- }
354
-
355
- let author = this.lastChatMessage.actorDisplayName.trim()
356
- const spacePosition = author.indexOf(' ')
357
- if (spacePosition !== -1) {
358
- author = author.substring(0, spacePosition)
359
- }
360
-
361
- if (author.length === 0 && this.lastChatMessage.actorType === ATTENDEE.ACTOR_TYPE.GUESTS) {
362
- return t('spreed', 'Guest')
363
- }
364
-
365
- return author
366
- },
367
-
368
276
to() {
369
277
return this.item?.token
370
278
? {
0 commit comments