From c4fd04efb642b42b5829e25b4fc5d8b389fff8de Mon Sep 17 00:00:00 2001
From: Harrison Healey <harrisonmhealey@gmail.com>
Date: Tue, 4 Apr 2017 00:22:09 -0400
Subject: Fixed channel autocomplete flickering (#5961)

---
 .../components/suggestion/at_mention_provider.jsx  | 101 +++++++++++----------
 1 file changed, 51 insertions(+), 50 deletions(-)

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

diff --git a/webapp/components/suggestion/at_mention_provider.jsx b/webapp/components/suggestion/at_mention_provider.jsx
index 5f79e08ae..68a5c64bc 100644
--- a/webapp/components/suggestion/at_mention_provider.jsx
+++ b/webapp/components/suggestion/at_mention_provider.jsx
@@ -6,7 +6,6 @@ import Provider from './provider.jsx';
 
 import ChannelStore from 'stores/channel_store.jsx';
 import UserStore from 'stores/user_store.jsx';
-import SuggestionStore from 'stores/suggestion_store.jsx';
 
 import {autocompleteUsersInChannel} from 'actions/user_actions.jsx';
 
@@ -112,58 +111,60 @@ export default class AtMentionProvider extends Provider {
 
     handlePretextChanged(suggestionId, pretext) {
         const captured = XRegExp.cache('(?:^|\\W)@([\\pL\\d\\-_.]*)$', 'i').exec(pretext.toLowerCase());
-        if (captured) {
-            const prefix = captured[1];
-
-            this.startNewRequest(prefix);
-
-            autocompleteUsersInChannel(
-                prefix,
-                this.channelId,
-                (data) => {
-                    if (this.shouldCancelDispatch(prefix)) {
-                        return;
-                    }
-
-                    const members = data.in_channel;
-                    for (const id of Object.keys(members)) {
-                        members[id].type = Constants.MENTION_MEMBERS;
-                    }
-
-                    const nonmembers = data.out_of_channel;
-                    for (const id of Object.keys(nonmembers)) {
-                        nonmembers[id].type = Constants.MENTION_NONMEMBERS;
-                    }
-
-                    let specialMentions = [];
-                    if (!pretext.startsWith('/msg')) {
-                        specialMentions = ['here', 'channel', 'all'].filter((item) => {
-                            return item.startsWith(prefix);
-                        }).map((name) => {
-                            return {username: name, type: Constants.MENTION_SPECIAL};
-                        });
-                    }
-
-                    let users = members.concat(specialMentions).concat(nonmembers);
-                    const me = UserStore.getCurrentUser();
-                    users = users.filter((user) => {
-                        return user.id !== me.id;
-                    });
+        if (!captured) {
+            return false;
+        }
+
+        const prefix = captured[1];
+
+        this.startNewRequest(prefix);
+
+        autocompleteUsersInChannel(
+            prefix,
+            this.channelId,
+            (data) => {
+                if (this.shouldCancelDispatch(prefix)) {
+                    return;
+                }
+
+                const members = data.in_channel;
+                for (const id of Object.keys(members)) {
+                    members[id].type = Constants.MENTION_MEMBERS;
+                }
 
-                    const mentions = users.map((user) => '@' + user.username);
+                const nonmembers = data.out_of_channel;
+                for (const id of Object.keys(nonmembers)) {
+                    nonmembers[id].type = Constants.MENTION_NONMEMBERS;
+                }
 
-                    AppDispatcher.handleServerAction({
-                        type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS,
-                        id: suggestionId,
-                        matchedPretext: `@${captured[1]}`,
-                        terms: mentions,
-                        items: users,
-                        component: AtMentionSuggestion
+                let specialMentions = [];
+                if (!pretext.startsWith('/msg')) {
+                    specialMentions = ['here', 'channel', 'all'].filter((item) => {
+                        return item.startsWith(prefix);
+                    }).map((name) => {
+                        return {username: name, type: Constants.MENTION_SPECIAL};
                     });
                 }
-            );
-        } else {
-            SuggestionStore.clearSuggestions(suggestionId);
-        }
+
+                let users = members.concat(specialMentions).concat(nonmembers);
+                const me = UserStore.getCurrentUser();
+                users = users.filter((user) => {
+                    return user.id !== me.id;
+                });
+
+                const mentions = users.map((user) => '@' + user.username);
+
+                AppDispatcher.handleServerAction({
+                    type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS,
+                    id: suggestionId,
+                    matchedPretext: `@${captured[1]}`,
+                    terms: mentions,
+                    items: users,
+                    component: AtMentionSuggestion
+                });
+            }
+        );
+
+        return true;
     }
 }
-- 
cgit v1.2.3-1-g7c22

