Skip to content

Commit 0bd1b16

Browse files
committed
First init of adding caption to the uploaded media
Signed-off-by: Maksim Sukharev <[email protected]>
1 parent 7cd0c18 commit 0bd1b16

File tree

5 files changed

+68
-31
lines changed

5 files changed

+68
-31
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ the main body of the message as well as a quote.
7878
</div>
7979
<div v-else class="message-body__main__text" :class="{'system-message': isSystemMessage}">
8080
<Quote v-if="parent" :parent-id="parent" v-bind="quote" />
81-
<NcRichText :text="message"
81+
<NcRichText :text="renderedMessage"
8282
:arguments="richParameters"
8383
:autolink="true"
8484
:reference-limit="1" />
@@ -368,6 +368,13 @@ export default {
368368
type: String,
369369
required: true,
370370
},
371+
/**
372+
* The caption passed with media file.
373+
*/
374+
mediaCaption: {
375+
type: String,
376+
default: null,
377+
},
371378
/**
372379
* The parent message's id.
373380
*/
@@ -429,6 +436,14 @@ export default {
429436
return !this.isLastMessage && this.id === this.$store.getters.getVisualLastReadMessageId(this.token)
430437
},
431438
439+
renderedMessage() {
440+
if (!this.mediaCaption) {
441+
return this.message
442+
}
443+
// TODO decide if we want to see caption above media or below it
444+
return [this.message, this.mediaCaption].join(' ')
445+
},
446+
432447
messageObject() {
433448
return this.$store.getters.message(this.token, this.id)
434449
},

src/components/MessagesList/MessagesList.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ export default {
197197
continue
198198
}
199199
200+
// FIXME delete when could be received from backend
201+
if (message.message === '{file}' && message.messageType === 'comment' && !message.mediaCaption) {
202+
message.mediaCaption = 'You can also add mentions: {mention-user1} and emojis 😍'
203+
message.messageParameters['mention-user1'] = { type: 'user', id: 'bob', name: 'bob' }
204+
}
205+
200206
if (!this.messagesShouldBeGrouped(message, lastMessage)) {
201207
// Add the date separator for different days
202208
if (this.messagesHaveDifferentDate(message, lastMessage)) {

src/components/UploadEditor.vue

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
<template>
2323
<NcModal v-if="showModal"
24+
ref="modal"
2425
:size="isVoiceMessage ? 'small' : 'normal'"
2526
class="upload-editor"
2627
:container="container"
@@ -60,14 +61,16 @@
6061
<AudioPlayer :name="voiceMessageName"
6162
:local-url="voiceMessageLocalURL" />
6263
</template>
63-
<div class="upload-editor__actions">
64-
<NcButton type="tertiary" @click="handleDismiss">
65-
{{ t('spreed', 'Dismiss') }}
66-
</NcButton>
67-
<NcButton ref="submitButton" type="primary" @click="handleUpload">
68-
{{ t('spreed', 'Send') }}
69-
</NcButton>
70-
</div>
64+
<NewMessageForm v-if="modalContainerId"
65+
class="upload-editor__message-form"
66+
role="region"
67+
:token="token"
68+
:breakout-room="true"
69+
:container-id="modalContainerId"
70+
:aria-label="t('spreed', 'Post message')"
71+
:broadcast="true"
72+
@sent="handleUpload"
73+
@failure="handleDismiss" />
7174
</div>
7275
</NcModal>
7376
</template>
@@ -81,16 +84,25 @@ import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
8184
8285
import AudioPlayer from './MessagesList/MessagesGroup/Message/MessagePart/AudioPlayer.vue'
8386
import FilePreview from './MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue'
87+
import NewMessageForm from './NewMessageForm/NewMessageForm.vue'
8488
8589
export default {
8690
name: 'UploadEditor',
8791
8892
components: {
89-
NcModal,
90-
FilePreview,
91-
Plus,
9293
AudioPlayer,
94+
FilePreview,
9395
NcButton,
96+
NcModal,
97+
NewMessageForm,
98+
Plus,
99+
},
100+
101+
data() {
102+
return {
103+
mediaCaption: '',
104+
modalContainerId: null,
105+
}
94106
},
95107
96108
computed: {
@@ -125,8 +137,7 @@ export default {
125137
return this.files[Object.keys(this.files)[0]]
126138
},
127139
128-
// Hide the plus button in case this editor is used while sending a voice
129-
// message
140+
// Hide the plus button in case this editor is used while sending a voice message
130141
isVoiceMessage() {
131142
if (!this.firstFile) {
132143
return false
@@ -152,15 +163,16 @@ export default {
152163
watch: {
153164
showModal(show) {
154165
if (show) {
155-
this.focus()
166+
this.getContainerId()
156167
}
157168
},
158169
},
159170
160171
methods: {
161-
focus() {
172+
getContainerId() {
162173
this.$nextTick(() => {
163-
this.$refs.submitButton.$el.focus()
174+
// Postpone render of NewMessageForm until modal container is mounted
175+
this.modalContainerId = `#modal-description-${this.$refs.modal.randId}`
164176
})
165177
},
166178
@@ -169,7 +181,7 @@ export default {
169181
},
170182
171183
handleUpload() {
172-
this.$store.dispatch('uploadFiles', this.currentUploadId)
184+
this.$store.dispatch('uploadFiles', { uploadId: this.currentUploadId, mediaCaption: this.mediaCaption })
173185
},
174186
/**
175187
* Clicks the hidden file input when clicking the correspondent NcActionButton,
@@ -202,20 +214,15 @@ export default {
202214
padding: 16px;
203215
204216
&__previews {
205-
overflow-x: hidden !important;
206217
display: flex;
207218
position: relative;
208219
overflow: auto;
209220
flex-wrap: wrap;
210221
}
211-
&__actions {
212-
display: flex;
213-
justify-content: space-between;
222+
&__message-form {
214223
margin-top: 16px;
215224
margin-bottom: 4px;
216-
button {
217-
margin: 0 4px 0 4px;
218-
}
225+
width: 100%;
219226
}
220227
}
221228
@@ -229,4 +236,9 @@ export default {
229236
}
230237
}
231238
239+
:deep(.modal-container) {
240+
// Fix visibility for popovers, like EmojiPicker
241+
overflow: visible !important;
242+
}
243+
232244
</style>

src/store/fileUploadStore.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,11 @@ const actions = {
278278
* @param {Function} context.dispatch the contexts dispatch function.
279279
* @param {object} context.getters the contexts getters object.
280280
* @param {object} context.state the contexts state object.
281-
* @param {string} uploadId The unique uploadId
281+
* @param {object} data the wrapping object
282+
* @param {string} data.uploadId The unique uploadId
283+
* @param {string} [data.mediaCaption] The text caption to the media
282284
*/
283-
async uploadFiles({ commit, dispatch, state, getters }, uploadId) {
285+
async uploadFiles({ commit, dispatch, state, getters }, { uploadId, mediaCaption }) {
284286
if (state.currentUploadId === uploadId) {
285287
commit('setCurrentUploadId', undefined)
286288
}
@@ -353,7 +355,9 @@ const actions = {
353355
for (const index in shareableFiles) {
354356
const path = shareableFiles[index].sharePath
355357
const temporaryMessage = shareableFiles[index].temporaryMessage
356-
const metadata = JSON.stringify({ messageType: temporaryMessage.messageType })
358+
const metadata = mediaCaption
359+
? JSON.stringify({ messageType: temporaryMessage.messageType, mediaCaption })
360+
: JSON.stringify({ messageType: temporaryMessage.messageType })
357361
try {
358362
const token = temporaryMessage.token
359363
dispatch('markFileAsSharing', { uploadId, index })

src/store/fileUploadStore.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('fileUploadStore', () => {
161161
client.putFileContents.mockResolvedValue()
162162
shareFile.mockResolvedValue()
163163

164-
await store.dispatch('uploadFiles', 'upload-id1')
164+
await store.dispatch('uploadFiles', { uploadId: 'upload-id1' })
165165

166166
expect(client.putFileContents).toHaveBeenCalledTimes(2)
167167
expect(shareFile).toHaveBeenCalledTimes(2)
@@ -204,7 +204,7 @@ describe('fileUploadStore', () => {
204204
},
205205
})
206206

207-
await store.dispatch('uploadFiles', 'upload-id1')
207+
await store.dispatch('uploadFiles', { uploadId: 'upload-id1' })
208208

209209
expect(client.putFileContents).toHaveBeenCalledTimes(1)
210210
expect(shareFile).not.toHaveBeenCalled()
@@ -242,7 +242,7 @@ describe('fileUploadStore', () => {
242242
},
243243
})
244244

245-
await store.dispatch('uploadFiles', 'upload-id1')
245+
await store.dispatch('uploadFiles', { uploadId: 'upload-id1' })
246246

247247
expect(client.putFileContents).toHaveBeenCalledTimes(1)
248248
expect(shareFile).toHaveBeenCalledTimes(1)

0 commit comments

Comments
 (0)