Skip to content

Commit 701763e

Browse files
authored
Merge pull request #10730 from nextcloud/feat/5354/captions-frontend
feat(NewMessageUploadEditor) - caption to file share
2 parents ab03ae1 + 892c22b commit 701763e

File tree

7 files changed

+254
-141
lines changed

7 files changed

+254
-141
lines changed

src/components/MessagesList/MessagesGroup/Message/Message.spec.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ describe('Message.vue', () => {
325325
const messageEl = wrapper.findComponent({ name: 'NcRichText' })
326326
// note: indices as object keys are on purpose
327327
expect(messageEl.props('arguments')).toMatchObject(expectedRichParameters)
328+
return messageEl
328329
}
329330

330331
test('renders mentions', () => {
@@ -364,7 +365,7 @@ describe('Message.vue', () => {
364365
)
365366
})
366367

367-
test('renders file previews', () => {
368+
test('renders single file preview', () => {
368369
const params = {
369370
actor: {
370371
id: 'alice',
@@ -391,6 +392,36 @@ describe('Message.vue', () => {
391392
)
392393
})
393394

395+
test('renders single file preview with caption', () => {
396+
const caption = 'text caption'
397+
const params = {
398+
actor: {
399+
id: 'alice',
400+
name: 'Alice',
401+
type: 'user',
402+
},
403+
file: {
404+
path: 'some/path',
405+
type: 'file',
406+
},
407+
}
408+
const messageEl = renderRichObject(
409+
caption,
410+
params, {
411+
actor: {
412+
component: Mention,
413+
props: params.actor,
414+
},
415+
file: {
416+
component: FilePreview,
417+
props: params.file,
418+
},
419+
}
420+
)
421+
422+
expect(messageEl.props('text')).toBe('{file}' + '\n\n' + caption)
423+
})
424+
394425
test('renders deck cards', () => {
395426
const params = {
396427
actor: {

src/components/MessagesList/MessagesGroup/Message/Message.vue

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ the main body of the message as well as a quote.
4747
class="message-body__main__text">
4848
<Quote v-if="parent" v-bind="parent" />
4949
<div class="single-emoji">
50-
{{ message }}
50+
{{ renderedMessage }}
5151
</div>
5252
</div>
5353
<div v-else-if="showJoinCallButton" class="message-body__main__text call-started">
54-
<NcRichText :text="message"
54+
<NcRichText :text="renderedMessage"
5555
:arguments="richParameters"
5656
autolink
5757
dir="auto"
5858
:reference-limit="0" />
5959
<CallButton />
6060
</div>
6161
<div v-else-if="showResultsButton || isSystemMessage" class="message-body__main__text system-message">
62-
<NcRichText :text="message"
62+
<NcRichText :text="renderedMessage"
6363
:arguments="richParameters"
6464
autolink
6565
dir="auto"
@@ -72,7 +72,7 @@ the main body of the message as well as a quote.
7272
show-as-button />
7373
</div>
7474
<div v-else-if="isDeletedMessage" class="message-body__main__text deleted-message">
75-
<NcRichText :text="message"
75+
<NcRichText :text="renderedMessage"
7676
:arguments="richParameters"
7777
autolink
7878
dir="auto"
@@ -83,7 +83,7 @@ the main body of the message as well as a quote.
8383
@mouseover="handleMarkdownMouseOver"
8484
@mouseleave="handleMarkdownMouseLeave">
8585
<Quote v-if="parent" v-bind="parent" />
86-
<NcRichText :text="message"
86+
<NcRichText :text="renderedMessage"
8787
:arguments="richParameters"
8888
autolink
8989
dir="auto"
@@ -457,6 +457,11 @@ export default {
457457
type: Array,
458458
default: () => { return [] },
459459
},
460+
461+
referenceId: {
462+
type: String,
463+
default: '',
464+
},
460465
},
461466
462467
emits: ['toggle-combined-system-message'],
@@ -502,6 +507,15 @@ export default {
502507
return !this.isLastMessage && this.id === this.$store.getters.getVisualLastReadMessageId(this.token)
503508
},
504509
510+
renderedMessage() {
511+
if (this.messageParameters?.file && this.message !== '{file}') {
512+
// Add a new line after file to split content into different paragraphs
513+
return '{file}' + '\n\n' + this.message
514+
} else {
515+
return this.message
516+
}
517+
},
518+
505519
messageObject() {
506520
return this.$store.getters.message(this.token, this.id)
507521
},
@@ -568,7 +582,7 @@ export default {
568582
let match
569583
let emojiStrings = ''
570584
let emojiCount = 0
571-
const trimmedMessage = this.message.trim()
585+
const trimmedMessage = this.renderedMessage.trim()
572586
573587
// eslint-disable-next-line no-cond-assign
574588
while (match = regex.exec(trimmedMessage)) {
@@ -600,6 +614,7 @@ export default {
600614
props: Object.assign({
601615
token: this.token,
602616
itemType,
617+
referenceId: this.referenceId,
603618
}, this.messageParameters[p]),
604619
}
605620
} else if (type === 'deck-card') {

src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
'file-preview--row-layout': rowLayout }"
3333
@click.exact="handleClick"
3434
@keydown.enter="handleClick">
35-
<div v-if="!isLoading"
35+
<div v-if="!isLoading || fallbackLocalUrl"
3636
class="image-container"
3737
:class="{'playable': isPlayable}">
3838
<span v-if="isPlayable && !smallPreview" class="play-video-button">
@@ -121,6 +121,13 @@ export default {
121121
type: String,
122122
required: true,
123123
},
124+
/**
125+
* Reference id from the message
126+
*/
127+
referenceId: {
128+
type: String,
129+
default: '',
130+
},
124131
/**
125132
* File name
126133
*/
@@ -283,6 +290,10 @@ export default {
283290
return this.name
284291
},
285292
293+
fallbackLocalUrl() {
294+
return this.$store.getters.getLocalUrl(this.referenceId)
295+
},
296+
286297
previewTooltip() {
287298
if (this.shouldShowFileDetail) {
288299
// no tooltip as the file name is already visible directly
@@ -363,6 +374,9 @@ export default {
363374
if (this.previewType === PREVIEW_TYPE.TEMPORARY) {
364375
return this.localUrl
365376
}
377+
if (this.fallbackLocalUrl) {
378+
return this.fallbackLocalUrl
379+
}
366380
if (this.previewType === PREVIEW_TYPE.MIME_ICON || this.rowLayout) {
367381
return OC.MimeType.getIconUrl(this.mimetype)
368382
}

src/components/NewMessage/NewMessage.vue

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109

110110
<!-- Send buttons -->
111111
<template v-else>
112-
<NcActions v-if="!broadcast"
112+
<NcActions v-if="!broadcast && !upload"
113113
:container="container"
114114
:force-menu="true">
115115
<!-- Silent send -->
@@ -240,6 +240,14 @@ export default {
240240
default: false,
241241
},
242242
243+
/**
244+
* Upload files caption.
245+
*/
246+
upload: {
247+
type: Boolean,
248+
default: false,
249+
},
250+
243251
/**
244252
* Show an indicator if someone is currently typing a message.
245253
*/
@@ -359,11 +367,11 @@ export default {
359367
},
360368
361369
showAttachmentsMenu() {
362-
return this.canShareFiles && !this.broadcast
370+
return this.canShareFiles && !this.broadcast && !this.upload
363371
},
364372
365373
showAudioRecorder() {
366-
return !this.hasText && this.canUploadFiles && !this.broadcast
374+
return !this.hasText && this.canUploadFiles && !this.broadcast && !this.upload
367375
},
368376
showTypingStatus() {
369377
return this.hasTypingIndicator && this.supportTypingStatus
@@ -446,8 +454,15 @@ export default {
446454
},
447455
448456
handleUploadStart() {
449-
// refocus on upload start as the user might want to type again while the upload is running
450-
this.focusInput()
457+
if (this.upload) {
458+
return
459+
}
460+
this.$nextTick(() => {
461+
// reset main input in chat view after upload file with caption
462+
this.text = this.$store.getters.currentMessageInput(this.token)
463+
// refocus on upload start as the user might want to type again while the upload is running
464+
this.focusInput()
465+
})
451466
},
452467
453468
/**
@@ -466,6 +481,12 @@ export default {
466481
}
467482
}
468483
484+
if (this.upload) {
485+
this.$emit('sent', this.text)
486+
this.$store.dispatch('setCurrentMessageInput', { token: this.token, text: '' })
487+
return
488+
}
489+
469490
if (this.hasText) {
470491
// FIXME upstream: https://github.com/nextcloud-libraries/nextcloud-vue/issues/4492
471492
const temp = document.createElement('textarea')

0 commit comments

Comments
 (0)