From fe3f3e39a38c0321e37256aac3f351e51ffde7ce Mon Sep 17 00:00:00 2001 From: Cyrille Bollu Date: Wed, 11 Sep 2019 15:00:32 +0200 Subject: [PATCH] Makes sure there are valid recipients when posting to a direct message Signed-off-by: Cyrille Bollu --- src/components/Composer.vue | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/Composer.vue b/src/components/Composer.vue index 96d88ce1..2135a45b 100644 --- a/src/components/Composer.vue +++ b/src/components/Composer.vue @@ -743,7 +743,7 @@ export default { let contentHtml = element.innerHTML let to = [] let hashtags = [] - const mentionRegex = /@(([\w-_.]+)(@[\w-.]+)?)/g + const mentionRegex = /]+>]+>]+>@([\w-_.]+@[\w-.]+)/g let match = null do { match = mentionRegex.exec(contentHtml) @@ -783,8 +783,18 @@ export default { this.$refs.composerInput.oninput(event) }, createPost(event) { + + let postData = this.getPostData() + + // Abort if the post is a direct message and no valid mentions were found + if (this.type === 'direct' && postData.to.length === 0) { + OC.Notification.showTemporary(t('social', 'Error while trying to post your message: Could not find any valid recipients.'), { type: 'error' }) + return + } + + // Post toot this.loading = true - this.$store.dispatch('post', this.getPostData()).then((response) => { + this.$store.dispatch('post', postData).then((response) => { this.loading = false this.replyTo = null this.post = '' @@ -793,6 +803,7 @@ export default { this.miniatures = [] this.$store.dispatch('refreshTimeline') }) + }, remoteSearchAccounts(text) { return axios.get(OC.generateUrl('apps/social/api/v1/global/accounts/search?search=' + text))