From 23e7414d356839a4866c978b676abafb0f6bbfa9 Mon Sep 17 00:00:00 2001
From: Harrison Healey <harrisonmhealey@gmail.com>
Date: Fri, 20 Jan 2017 08:19:23 -0500
Subject: Fixed channel mention autocomplete to not match completed mentions
 (#5101)

---
 webapp/components/suggestion/channel_mention_provider.jsx | 12 ++++++++++++
 1 file changed, 12 insertions(+)

(limited to 'webapp/components/suggestion/channel_mention_provider.jsx')

diff --git a/webapp/components/suggestion/channel_mention_provider.jsx b/webapp/components/suggestion/channel_mention_provider.jsx
index 63e6944ac..611f3de10 100644
--- a/webapp/components/suggestion/channel_mention_provider.jsx
+++ b/webapp/components/suggestion/channel_mention_provider.jsx
@@ -56,6 +56,18 @@ export default class ChannelMentionProvider extends Provider {
         if (captured) {
             const prefix = captured[3];
 
+            if ((/\s/).test(prefix)) {
+                // If there's a space, there's a chance that we've already completed this mention
+                const firstWordOfPrefix = prefix.split(' ')[0];
+
+                for (const channel of ChannelStore.getChannels()) {
+                    if (firstWordOfPrefix === channel.name) {
+                        // We've already mentioned this channel so there's nothing else to look for
+                        return;
+                    }
+                }
+            }
+
             this.startNewRequest(prefix);
 
             autocompleteChannels(
-- 
cgit v1.2.3-1-g7c22

