From 29469ef10a5f0ea8f42f9c9755a275251d81162c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 21 Nov 2018 15:23:25 +0100 Subject: [PATCH] Properly send to data when creating a post MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/components/Composer.vue | 23 +++++++++++++++++------ src/store/timeline.js | 7 +++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/components/Composer.vue b/src/components/Composer.vue index c23b2213..4b897e3a 100644 --- a/src/components/Composer.vue +++ b/src/components/Composer.vue @@ -386,13 +386,27 @@ export default { } ] }, - getCleanPost() { + getPostData() { let element = this.$refs.composerInput.cloneNode(true) Array.from(element.getElementsByClassName('emoji')).forEach((emoji) => { var em = document.createTextNode(emoji.getAttribute('alt')) emoji.replaceWith(em) }) - return element.innerText + let to = [] + const re = /@((\w+)(@[\w.]+)?)/g + let match = null + do { + match = re.exec(element.innerText) + if (match) { + to.push(match[1]) + } + } while (match) + + return { + content: element.innerText, + to: to, + type: this.type + } } }, methods: { @@ -411,10 +425,7 @@ export default { this.menuOpened = false }, createPost(event) { - this.$store.dispatch('post', { - content: this.getCleanPost, - type: this.type - }).then((response) => { + this.$store.dispatch('post', this.getPostData).then((response) => { this.post = '' this.$refs.composerInput.innerText = this.post }) diff --git a/src/store/timeline.js b/src/store/timeline.js index 9c89ea23..a5f0d4a5 100644 --- a/src/store/timeline.js +++ b/src/store/timeline.js @@ -32,6 +32,10 @@ const mutations = { state.since = data[item].published state.timeline.push(data[item]) } + }, + addPost(state, data) { + // FIXME: push data we receive to the timeline array + // state.timeline.push(data) } } const getters = { @@ -43,6 +47,9 @@ const actions = { post(context, post) { return axios.post(OC.generateUrl('apps/social/api/v1/post'), { data: post }).then((response) => { context.commit('addPost', { data: response.data }) + }).catch((error) => { + OC.Notification.showTemporary('Failed to create a post') + console.error('Failed to create a post', error) }) }, fetchTimeline(context, account) {