From 1b141681ae6a169272003fa83fb83ba245dbafc7 Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Thu, 3 Nov 2016 11:23:57 -0400
Subject: Add status listeners back to user list modals (#4428)

---
 webapp/components/channel_members_modal.jsx | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

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

diff --git a/webapp/components/channel_members_modal.jsx b/webapp/components/channel_members_modal.jsx
index 76ce535ad..75810cf05 100644
--- a/webapp/components/channel_members_modal.jsx
+++ b/webapp/components/channel_members_modal.jsx
@@ -27,6 +27,7 @@ export default class ChannelMembersModal extends React.Component {
         super(props);
 
         this.onChange = this.onChange.bind(this);
+        this.onStatusChange = this.onStatusChange.bind(this);
         this.handleRemove = this.handleRemove.bind(this);
         this.createRemoveMemberButton = this.createRemoveMemberButton.bind(this);
         this.search = this.search.bind(this);
@@ -40,7 +41,8 @@ export default class ChannelMembersModal extends React.Component {
             users: [],
             total: stats.member_count,
             showInviteModal: false,
-            search: false
+            search: false,
+            statusChange: false
         };
     }
 
@@ -48,17 +50,25 @@ export default class ChannelMembersModal extends React.Component {
         if (!this.props.show && nextProps.show) {
             ChannelStore.addStatsChangeListener(this.onChange);
             UserStore.addInChannelChangeListener(this.onChange);
+            UserStore.addStatusesChangeListener(this.onStatusChange);
 
             this.onChange();
             AsyncClient.getProfilesInChannel(this.props.channel.id, 0);
         } else if (this.props.show && !nextProps.show) {
             ChannelStore.removeStatsChangeListener(this.onChange);
             UserStore.removeInChannelChangeListener(this.onChange);
+            UserStore.removeStatusesChangeListener(this.onStatusChange);
         }
     }
 
-    onChange() {
-        if (this.state.search) {
+    componentWillUnmount() {
+        ChannelStore.removeStatsChangeListener(this.onChange);
+        UserStore.removeInChannelChangeListener(this.onChange);
+        UserStore.removeStatusesChangeListener(this.onStatusChange);
+    }
+
+    onChange(force) {
+        if (this.state.search && !force) {
             this.search(this.term);
             return;
         }
@@ -70,6 +80,13 @@ export default class ChannelMembersModal extends React.Component {
         });
     }
 
+    onStatusChange() {
+        // Initiate a render to pick up on new statuses
+        this.setState({
+            statusChange: !this.state.statusChange
+        });
+    }
+
     handleRemove(user) {
         const userId = user.id;
 
@@ -110,7 +127,8 @@ export default class ChannelMembersModal extends React.Component {
         this.term = term;
 
         if (term === '') {
-            this.setState({users: UserStore.getProfileListInChannel(this.props.channel.id), search: false});
+            this.onChange(true);
+            this.setState({search: false});
             return;
         }
 
-- 
cgit v1.2.3-1-g7c22

