From ed31538893ad2790de46ace7eeac5c1aa015a7f1 Mon Sep 17 00:00:00 2001
From: hmhealey <harrisonmhealey@gmail.com>
Date: Fri, 2 Oct 2015 14:25:55 -0400
Subject: Changed direct messages channels so users can show/hide them

---
 web/react/components/more_direct_channels.jsx | 32 +++++++++++++++++++--------
 1 file changed, 23 insertions(+), 9 deletions(-)

(limited to 'web/react/components/more_direct_channels.jsx')

diff --git a/web/react/components/more_direct_channels.jsx b/web/react/components/more_direct_channels.jsx
index 31ecb4c5d..fc720e928 100644
--- a/web/react/components/more_direct_channels.jsx
+++ b/web/react/components/more_direct_channels.jsx
@@ -1,10 +1,10 @@
 // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
 // See License.txt for license information.
 
-var ChannelStore = require('../stores/channel_store.jsx');
 var TeamStore = require('../stores/team_store.jsx');
 var Client = require('../utils/client.jsx');
 var AsyncClient = require('../utils/async_client.jsx');
+var PreferenceStore = require('../stores/preference_store.jsx');
 var utils = require('../utils/utils.jsx');
 
 export default class MoreDirectChannels extends React.Component {
@@ -22,16 +22,32 @@ export default class MoreDirectChannels extends React.Component {
         });
     }
 
+    handleJoinDirectChannel(channel) {
+        const preference = PreferenceStore.setPreferenceWithAltId('direct_channels', 'show_hide', channel.teammate_id, 'true');
+        AsyncClient.setPreferences([preference]);
+    }
+
     render() {
         var self = this;
 
-        var directMessageItems = this.state.channels.map(function mapActivityToChannel(channel, index) {
+        var directMessageItems = this.state.channels.map((channel, index) => {
             var badge = '';
             var titleClass = '';
-            var active = '';
             var handleClick = null;
 
-            if (channel.fake) {
+            if (!channel.fake) {
+                if (channel.unread) {
+                    badge = <span className='badge pull-right small'>{channel.unread}</span>;
+                    titleClass = 'unread-title';
+                }
+
+                handleClick = (e) => {
+                    e.preventDefault();
+                    this.handleJoinDirectChannel(channel);
+                    utils.switchChannel(channel);
+                    $(React.findDOMNode(self.refs.modal)).modal('hide');
+                };
+            } else {
                 // It's a direct message channel that doesn't exist yet so let's create it now
                 var otherUserId = utils.getUserIdFromChannelName(channel);
 
@@ -45,9 +61,10 @@ export default class MoreDirectChannels extends React.Component {
                 }
 
                 if (self.state.loadingDMChannel === -1) {
-                    handleClick = function clickHandler(e) {
+                    handleClick = (e) => {
                         e.preventDefault();
                         self.setState({loadingDMChannel: index});
+                        this.handleJoinDirectChannel(channel);
 
                         Client.createDirectChannel(channel, otherUserId,
                             function success(data) {
@@ -81,10 +98,7 @@ export default class MoreDirectChannels extends React.Component {
             }
 
             return (
-                <li
-                    key={channel.name}
-                    className={active}
-                >
+                <li key={channel.name}>
                     <a
                         className={'sidebar-channel ' + titleClass}
                         href='#'
-- 
cgit v1.2.3-1-g7c22


From 599644fb2fa75d1760420806c8c821959fc6b645 Mon Sep 17 00:00:00 2001
From: hmhealey <harrisonmhealey@gmail.com>
Date: Mon, 5 Oct 2015 12:03:27 -0400
Subject: Renamed show_hide preference to show

---
 web/react/components/more_direct_channels.jsx | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

(limited to 'web/react/components/more_direct_channels.jsx')

diff --git a/web/react/components/more_direct_channels.jsx b/web/react/components/more_direct_channels.jsx
index fc720e928..ed9c6fc58 100644
--- a/web/react/components/more_direct_channels.jsx
+++ b/web/react/components/more_direct_channels.jsx
@@ -3,6 +3,7 @@
 
 var TeamStore = require('../stores/team_store.jsx');
 var Client = require('../utils/client.jsx');
+var Constants = require('../utils/constants.jsx');
 var AsyncClient = require('../utils/async_client.jsx');
 var PreferenceStore = require('../stores/preference_store.jsx');
 var utils = require('../utils/utils.jsx');
@@ -23,7 +24,8 @@ export default class MoreDirectChannels extends React.Component {
     }
 
     handleJoinDirectChannel(channel) {
-        const preference = PreferenceStore.setPreferenceWithAltId('direct_channels', 'show_hide', channel.teammate_id, 'true');
+        const preference = PreferenceStore.setPreferenceWithAltId(Constants.Preferences.CATEGORY_DIRECT_CHANNELS,
+            Constants.Preferences.NAME_SHOW, channel.teammate_id, 'true');
         AsyncClient.setPreferences([preference]);
     }
 
-- 
cgit v1.2.3-1-g7c22


From 097d236f437b0c5af167cd383c6ee4c3ee45f495 Mon Sep 17 00:00:00 2001
From: hmhealey <harrisonmhealey@gmail.com>
Date: Wed, 7 Oct 2015 11:34:29 -0400
Subject: Fixed edge cases with leaving a direct channel while viewing that
 channel

---
 web/react/components/more_direct_channels.jsx | 15 ---------------
 1 file changed, 15 deletions(-)

(limited to 'web/react/components/more_direct_channels.jsx')

diff --git a/web/react/components/more_direct_channels.jsx b/web/react/components/more_direct_channels.jsx
index ed9c6fc58..96c08c441 100644
--- a/web/react/components/more_direct_channels.jsx
+++ b/web/react/components/more_direct_channels.jsx
@@ -82,21 +82,6 @@ export default class MoreDirectChannels extends React.Component {
                         );
                     };
                 }
-            } else {
-                if (channel.id === ChannelStore.getCurrentId()) {
-                    active = 'active';
-                }
-
-                if (channel.unread) {
-                    badge = <span className='badge pull-right small'>{channel.unread}</span>;
-                    titleClass = 'unread-title';
-                }
-
-                handleClick = function clickHandler(e) {
-                    e.preventDefault();
-                    utils.switchChannel(channel);
-                    $(React.findDOMNode(self.refs.modal)).modal('hide');
-                };
             }
 
             return (
-- 
cgit v1.2.3-1-g7c22


From a2517ee991df84803ca508b556910e543c535c1d Mon Sep 17 00:00:00 2001
From: hmhealey <harrisonmhealey@gmail.com>
Date: Wed, 7 Oct 2015 13:07:59 -0400
Subject: Cleaned up JSX errors

---
 web/react/components/more_direct_channels.jsx | 57 +++++++++++++--------------
 1 file changed, 27 insertions(+), 30 deletions(-)

(limited to 'web/react/components/more_direct_channels.jsx')

diff --git a/web/react/components/more_direct_channels.jsx b/web/react/components/more_direct_channels.jsx
index 96c08c441..0fbd90096 100644
--- a/web/react/components/more_direct_channels.jsx
+++ b/web/react/components/more_direct_channels.jsx
@@ -16,10 +16,9 @@ export default class MoreDirectChannels extends React.Component {
     }
 
     componentDidMount() {
-        var self = this;
-        $(React.findDOMNode(this.refs.modal)).on('show.bs.modal', function showModal(e) {
+        $(React.findDOMNode(this.refs.modal)).on('show.bs.modal', (e) => {
             var button = e.relatedTarget;
-            self.setState({channels: $(button).data('channels')});
+            this.setState({channels: $(button).data('channels')}); // eslint-disable-line react/no-did-mount-set-state
         });
     }
 
@@ -30,30 +29,16 @@ export default class MoreDirectChannels extends React.Component {
     }
 
     render() {
-        var self = this;
-
         var directMessageItems = this.state.channels.map((channel, index) => {
             var badge = '';
             var titleClass = '';
             var handleClick = null;
 
-            if (!channel.fake) {
-                if (channel.unread) {
-                    badge = <span className='badge pull-right small'>{channel.unread}</span>;
-                    titleClass = 'unread-title';
-                }
-
-                handleClick = (e) => {
-                    e.preventDefault();
-                    this.handleJoinDirectChannel(channel);
-                    utils.switchChannel(channel);
-                    $(React.findDOMNode(self.refs.modal)).modal('hide');
-                };
-            } else {
+            if (channel.fake) {
                 // It's a direct message channel that doesn't exist yet so let's create it now
                 var otherUserId = utils.getUserIdFromChannelName(channel);
 
-                if (self.state.loadingDMChannel === index) {
+                if (this.state.loadingDMChannel === index) {
                     badge = (
                         <img
                             className='channel-loading-gif pull-right'
@@ -62,26 +47,38 @@ export default class MoreDirectChannels extends React.Component {
                     );
                 }
 
-                if (self.state.loadingDMChannel === -1) {
+                if (this.state.loadingDMChannel === -1) {
                     handleClick = (e) => {
                         e.preventDefault();
-                        self.setState({loadingDMChannel: index});
+                        this.setState({loadingDMChannel: index});
                         this.handleJoinDirectChannel(channel);
 
                         Client.createDirectChannel(channel, otherUserId,
-                            function success(data) {
-                                $(React.findDOMNode(self.refs.modal)).modal('hide');
-                                self.setState({loadingDMChannel: -1});
+                            (data) => {
+                                $(React.findDOMNode(this.refs.modal)).modal('hide');
+                                this.setState({loadingDMChannel: -1});
                                 AsyncClient.getChannel(data.id);
                                 utils.switchChannel(data);
                             },
-                            function error() {
-                                self.setState({loadingDMChannel: -1});
+                            () => {
+                                this.setState({loadingDMChannel: -1});
                                 window.location.href = TeamStore.getCurrentTeamUrl() + '/channels/' + channel.name;
                             }
                         );
                     };
                 }
+            } else {
+                if (channel.unread) {
+                    badge = <span className='badge pull-right small'>{channel.unread}</span>;
+                    titleClass = 'unread-title';
+                }
+
+                handleClick = (e) => {
+                    e.preventDefault();
+                    this.handleJoinDirectChannel(channel);
+                    utils.switchChannel(channel);
+                    $(React.findDOMNode(this.refs.modal)).modal('hide');
+                };
             }
 
             return (
@@ -112,10 +109,10 @@ export default class MoreDirectChannels extends React.Component {
                                 className='close'
                                 data-dismiss='modal'
                             >
-                                <span aria-hidden='true'>&times;</span>
-                                <span className='sr-only'>Close</span>
+                                <span aria-hidden='true'>{'×'}</span>
+                                <span className='sr-only'>{'Close'}</span>
                             </button>
-                            <h4 className='modal-title'>More Direct Messages</h4>
+                            <h4 className='modal-title'>{'More Direct Messages'}</h4>
                         </div>
                         <div className='modal-body'>
                             <ul className='nav nav-pills nav-stacked'>
@@ -127,7 +124,7 @@ export default class MoreDirectChannels extends React.Component {
                                 type='button'
                                 className='btn btn-default'
                                 data-dismiss='modal'
-                            >Close</button>
+                            >{'Close'}</button>
                         </div>
                     </div>
                 </div>
-- 
cgit v1.2.3-1-g7c22


From 2a39e8dbfab8506b09d0d030f87cac4c079b975a Mon Sep 17 00:00:00 2001
From: hmhealey <harrisonmhealey@gmail.com>
Date: Tue, 13 Oct 2015 11:52:17 -0400
Subject: Removed Preference.AltId

---
 web/react/components/more_direct_channels.jsx | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

(limited to 'web/react/components/more_direct_channels.jsx')

diff --git a/web/react/components/more_direct_channels.jsx b/web/react/components/more_direct_channels.jsx
index 0fbd90096..bc610cd60 100644
--- a/web/react/components/more_direct_channels.jsx
+++ b/web/react/components/more_direct_channels.jsx
@@ -23,9 +23,8 @@ export default class MoreDirectChannels extends React.Component {
     }
 
     handleJoinDirectChannel(channel) {
-        const preference = PreferenceStore.setPreferenceWithAltId(Constants.Preferences.CATEGORY_DIRECT_CHANNELS,
-            Constants.Preferences.NAME_SHOW, channel.teammate_id, 'true');
-        AsyncClient.setPreferences([preference]);
+        const preference = PreferenceStore.setPreference(Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, channel.teammate_id, 'true');
+        AsyncClient.savePreferences([preference]);
     }
 
     render() {
-- 
cgit v1.2.3-1-g7c22

