From 5ce1a4368bafbd2ed50b1953658fca285cfd349b Mon Sep 17 00:00:00 2001
From: Christopher Speller <crspeller@gmail.com>
Date: Thu, 24 Mar 2016 20:04:40 -0400
Subject: Refactoring center panel away. Moving tutorial to a route. Fixing a
 bunch of bugs.

---
 webapp/action_creators/global_actions.jsx | 56 +++++++++++++++++++++++++------
 1 file changed, 46 insertions(+), 10 deletions(-)

(limited to 'webapp/action_creators/global_actions.jsx')

diff --git a/webapp/action_creators/global_actions.jsx b/webapp/action_creators/global_actions.jsx
index 7322f1150..9c38d8955 100644
--- a/webapp/action_creators/global_actions.jsx
+++ b/webapp/action_creators/global_actions.jsx
@@ -13,23 +13,56 @@ import * as Utils from 'utils/utils.jsx';
 import * as Websockets from './websocket_actions.jsx';
 import * as I18n from 'i18n/i18n.jsx';
 
+import {browserHistory} from 'react-router';
+
 import en from 'i18n/en.json';
 
 export function emitChannelClickEvent(channel) {
-    AsyncClient.getChannels(true);
-    AsyncClient.getChannelExtraInfo(channel.id);
-    AsyncClient.updateLastViewedAt(channel.id);
-    AsyncClient.getPosts(channel.id);
+    function userVisitedFakeChannel(chan, success, fail) {
+        const otherUserId = Utils.getUserIdFromChannelName(chan);
+        Client.createDirectChannel(
+            chan,
+            otherUserId,
+            (data) => {
+                success(data);
+            },
+            () => {
+                fail();
+            }
+        );
+    }
+    function switchToChannel(chan) {
+        AsyncClient.getChannels(true);
+        AsyncClient.getChannelExtraInfo(chan.id);
+        AsyncClient.updateLastViewedAt(chan.id);
+        AsyncClient.getPosts(chan.id);
+        Client.trackPage();
+
+        AppDispatcher.handleViewAction({
+            type: ActionTypes.CLICK_CHANNEL,
+            name: chan.name,
+            id: chan.id,
+            prev: ChannelStore.getCurrentId()
+        });
+    }
 
-    AppDispatcher.handleViewAction({
-        type: ActionTypes.CLICK_CHANNEL,
-        name: channel.name,
-        id: channel.id,
-        prev: ChannelStore.getCurrentId()
-    });
+    if (channel.fake) {
+        userVisitedFakeChannel(
+            channel,
+            (data) => {
+                switchToChannel(data);
+            },
+            () => {
+                browserHistory.push('/' + this.state.currentTeam.name);
+            }
+        );
+    } else {
+        switchToChannel(channel);
+    }
 }
 
 export function emitPostFocusEvent(postId) {
+    AsyncClient.getChannels(true);
     Client.getPostById(
         postId,
         (data) => {
@@ -39,6 +72,8 @@ export function emitPostFocusEvent(postId) {
                 post_list: data
             });
 
+            AsyncClient.getChannelExtraInfo(data.channel_id);
+
             AsyncClient.getPostsBefore(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS);
             AsyncClient.getPostsAfter(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS);
         }
@@ -300,3 +335,4 @@ export function emitRemoteUserTypingEvent(channelId, userId, postParentId) {
         postParentId
     });
 }
+
-- 
cgit v1.2.3-1-g7c22

