From 47f92441aced1e2dd6e85fc18f27330d88e07593 Mon Sep 17 00:00:00 2001
From: Harrison Healey <harrisonmhealey@gmail.com>
Date: Thu, 8 Sep 2016 08:48:53 -0400
Subject: PLT-4100 Made SuggestionList dividers optional (#3990)

* Made SuggestionList dividers optional

* Stopped mutating the User object in the AtMentionProvider
---
 .../components/suggestion/at_mention_provider.jsx   | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 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 87cdc6894..248e459b5 100644
--- a/webapp/components/suggestion/at_mention_provider.jsx
+++ b/webapp/components/suggestion/at_mention_provider.jsx
@@ -99,7 +99,7 @@ class AtMentionSuggestion extends Suggestion {
     }
 }
 
-function filterUsersByPrefix(users, prefix, limit) {
+function filterUsersByPrefix(users, prefix, limit, type) {
     const filtered = [];
 
     for (const id of Object.keys(users)) {
@@ -117,7 +117,8 @@ function filterUsersByPrefix(users, prefix, limit) {
             (user.first_name && user.first_name.toLowerCase().startsWith(prefix)) ||
             (user.last_name && user.last_name.toLowerCase().startsWith(prefix)) ||
             (user.nickname && user.nickname.toLowerCase().startsWith(prefix))) {
-            filtered.push(user);
+            // create a new object here since we're mutating it by adding the type field
+            filtered.push(Object.assign({}, user, {type}));
         }
     }
 
@@ -145,15 +146,15 @@ export default class AtMentionProvider {
 
             // Filter users by prefix.
             const filteredMembers = filterUsersByPrefix(
-                    channelMembers, prefix, MaxUserSuggestions);
+                    channelMembers, prefix, MaxUserSuggestions, Constants.MENTION_MEMBERS);
             const filteredNonmembers = filterUsersByPrefix(
-                    channelNonmembers, prefix, MaxUserSuggestions - filteredMembers.length);
+                    channelNonmembers, prefix, MaxUserSuggestions - filteredMembers.length, Constants.MENTION_NONMEMBERS);
             let filteredSpecialMentions = [];
             if (!pretext.startsWith('/msg')) {
                 filteredSpecialMentions = ['here', 'channel', 'all'].filter((item) => {
                     return item.startsWith(prefix);
                 }).map((name) => {
-                    return {username: name};
+                    return {username: name, type: Constants.MENTION_SPECIAL};
                 });
             }
 
@@ -173,16 +174,6 @@ export default class AtMentionProvider {
                 });
             });
 
-            filteredMembers.forEach((item) => {
-                item.type = Constants.MENTION_MEMBERS;
-            });
-            filteredNonmembers.forEach((item) => {
-                item.type = Constants.MENTION_NONMEMBERS;
-            });
-            filteredSpecialMentions.forEach((item) => {
-                item.type = Constants.MENTION_SPECIAL;
-            });
-
             const filtered = filteredMembers.concat(filteredSpecialMentions).concat(filteredNonmembers);
 
             const mentions = filtered.map((user) => '@' + user.username);
-- 
cgit v1.2.3-1-g7c22

