5858 </Actions >
5959 </div >
6060 <div
61+ v-if =" !isReadOnly"
6162 class =" new-message-form__button" >
6263 <EmojiPicker @select =" addEmoji" >
6364 <button
8081 ref =" advancedInput"
8182 v-model =" text"
8283 :token =" token"
84+ :active-input =" !isReadOnly"
85+ :placeholder-text =" placeholderText"
8386 @update:contentEditable =" contentEditableToParsed"
8487 @submit =" handleSubmit"
8588 @files-pasted =" handleFiles" />
8689 </div >
8790 <button
91+ :disabled =" isReadOnly"
8892 type =" submit"
8993 :aria-label =" t('spreed', 'Send message')"
9094 class =" new-message-form__button submit icon-confirm-fade"
96100
97101<script >
98102import AdvancedInput from ' ./AdvancedInput/AdvancedInput'
99- import { getFilePickerBuilder } from ' @nextcloud/dialogs'
103+ import { getFilePickerBuilder , showError } from ' @nextcloud/dialogs'
100104import { postNewMessage } from ' ../../services/messagesService'
101105import Quote from ' ../Quote'
102106import Actions from ' @nextcloud/vue/dist/Components/Actions'
@@ -149,6 +153,16 @@ export default {
149153 }
150154 },
151155
156+ isReadOnly () {
157+ return this .conversation .readOnly === CONVERSATION .STATE .READ_ONLY
158+ },
159+
160+ placeholderText () {
161+ return this .isReadOnly
162+ ? t (' spreed' , ' This conversation has been locked' )
163+ : t (' spreed' , ' Write message, @ to mention someone …' )
164+ },
165+
152166 messageToBeReplied () {
153167 return this .$store .getters .getMessageToBeReplied (this .token )
154168 },
@@ -158,7 +172,7 @@ export default {
158172 },
159173
160174 canShareAndUploadFiles () {
161- return ! this .currentUserIsGuest && this .conversation . readOnly === CONVERSATION . STATE . READ_WRITE
175+ return ! this .currentUserIsGuest && ! this .isReadOnly
162176 },
163177
164178 attachmentFolder () {
@@ -238,8 +252,8 @@ export default {
238252 * Sends the new message
239253 */
240254 async handleSubmit () {
241-
242255 if (this .parsedText !== ' ' ) {
256+ const oldMessage = this .parsedText
243257 const temporaryMessage = createTemporaryMessage (this .parsedText , this .token )
244258 this .$store .dispatch (' addTemporaryMessage' , temporaryMessage)
245259 this .text = ' '
@@ -270,7 +284,22 @@ export default {
270284 })
271285 }
272286 } catch (error) {
273- console .debug (` error while submitting message ${ error} ` )
287+ let statusCode = null
288+ console .debug (` error while submitting message ${ error} ` , error)
289+ if (error .isAxiosError ) {
290+ statusCode = error .response .status
291+ }
292+ // 403 when room is read-only, 412 when switched to lobby mode
293+ if (statusCode === 403 || statusCode === 412 ) {
294+ showError (t (' spreed' , ' No permission to post messages in this conversation' ))
295+ } else {
296+ showError (t (' spreed' , ' Could not post message: {errorMessage}' , { errorMessage: error .message || error }))
297+ }
298+
299+ // restore message to allow re-sending
300+ this .$store .dispatch (' deleteMessage' , temporaryMessage)
301+ this .text = oldMessage
302+ this .parsedText = oldMessage
274303 }
275304 }
276305 },
0 commit comments