From bb69e98631b2541954b6ae465b8ba5f788b9dc49 Mon Sep 17 00:00:00 2001
From: Yi EungJun <semtlenori@gmail.com>
Date: Tue, 20 Sep 2016 06:41:19 +0900
Subject: PLT-4182 Fix incorrect listing for at-mention in comment (#4031)

* Add missing eol

* PLT-4182 Fix incorrect listing for at-mention in comment

Suggestion box for at-mention listed users for the center channel even
if the current textbox is for reply for a post which belongs to a
different channel.
---
 webapp/components/textbox.jsx | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

(limited to 'webapp/components/textbox.jsx')

diff --git a/webapp/components/textbox.jsx b/webapp/components/textbox.jsx
index 5c1d823b5..22738ffa3 100644
--- a/webapp/components/textbox.jsx
+++ b/webapp/components/textbox.jsx
@@ -36,7 +36,11 @@ export default class Textbox extends React.Component {
             connection: ''
         };
 
-        this.suggestionProviders = [new AtMentionProvider(), new ChannelMentionProvider(), new EmoticonProvider()];
+        this.suggestionProviders = [
+            new AtMentionProvider(this.props.channelId),
+            new ChannelMentionProvider(),
+            new EmoticonProvider()
+        ];
         if (props.supportsCommands) {
             this.suggestionProviders.push(new CommandProvider());
         }
@@ -104,6 +108,18 @@ export default class Textbox extends React.Component {
         this.setState({preview: !this.state.preview});
     }
 
+    componentWillReceiveProps(nextProps) {
+        if (nextProps.channelId !== this.channelId) {
+            // Update channel id for AtMentionProvider.
+            const providers = this.suggestionProviders;
+            for (let i = 0; i < providers.length; i++) {
+                if (providers[i] instanceof AtMentionProvider) {
+                    providers[i] = new AtMentionProvider(nextProps.channelId);
+                }
+            }
+        }
+    }
+
     render() {
         const hasText = this.props.messageText.length > 0;
 
-- 
cgit v1.2.3-1-g7c22

