From cd87a6712dca1ee922eab9f067e7a22f1113387c Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 20 Nov 2017 16:46:23 +0200 Subject: [PATCH] Add completion for groups. --- .../post_status_form/post_status_form.js | 14 ++++++++++++++ src/services/completion/completion.js | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 6fc84407c0..30c054b03e 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -74,6 +74,17 @@ const PostStatusForm = { name: '', img: image_url })) + } else if (firstchar === '!') { + const matchedGroups = filter(this.groups, (group) => group.nickname.match(this.textAtCaret.slice(1))) + if (matchedGroups.length <= 0) { + return false + } + return map(take(matchedGroups, 5), ({nickname, original_logo}) => ({ + // eslint-disable-next-line camelcase + screen_name: `!${nickname}`, + name: '', + img: original_logo || 'https://placehold.it/48x48' + })) } else { return false } @@ -90,6 +101,9 @@ const PostStatusForm = { }, emoji () { return this.$store.state.config.emoji || [] + }, + groups () { + return this.$store.state.groups.groups } }, methods: { diff --git a/src/services/completion/completion.js b/src/services/completion/completion.js index 11c4586715..3eeefd340b 100644 --- a/src/services/completion/completion.js +++ b/src/services/completion/completion.js @@ -37,7 +37,7 @@ export const addPositionToWords = (words) => { export const splitIntoWords = (str) => { // Split at word boundaries const regex = /\b/ - const triggers = /[@#:]+$/ + const triggers = /[@#:!]+$/ let split = str.split(regex)