From fa807d8e436e87b8c1749ea54c293a15c67f7f29 Mon Sep 17 00:00:00 2001
From: Christopher Speller <crspeller@gmail.com>
Date: Wed, 27 Apr 2016 16:02:58 -0400
Subject: Fixing permalinks to channels your not a memeber of (#2805)

---
 webapp/action_creators/global_actions.jsx | 40 ++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 11 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 bf1d82aee..335c20219 100644
--- a/webapp/action_creators/global_actions.jsx
+++ b/webapp/action_creators/global_actions.jsx
@@ -128,21 +128,31 @@ export function emitInitialLoad(callback) {
         );
 }
 
+export function doFocusPost(channelId, postId, data) {
+    AppDispatcher.handleServerAction({
+        type: ActionTypes.RECEIVED_FOCUSED_POST,
+        postId,
+        post_list: data
+    });
+    AsyncClient.getChannels(true);
+    AsyncClient.getChannelExtraInfo(channelId);
+    AsyncClient.getPostsBefore(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS);
+    AsyncClient.getPostsAfter(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS);
+}
+
 export function emitPostFocusEvent(postId) {
     AsyncClient.getChannels(true);
-    Client.getPostById(
+    Client.getPermalinkTmp(
         postId,
         (data) => {
-            AppDispatcher.handleServerAction({
-                type: ActionTypes.RECEIVED_FOCUSED_POST,
-                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);
+            if (!data) {
+                return;
+            }
+            const channelId = data.posts[data.order[0]].channel_id;
+            doFocusPost(channelId, postId, data);
+        },
+        () => {
+            browserHistory.push('/error?message=' + encodeURIComponent(Utils.localizeMessage('permalink.error.access', 'Permalink belongs to a channel you do not have access to')));
         }
     );
 }
@@ -431,3 +441,11 @@ export function emitUserLoggedOutEvent(redirectTo) {
         }
     );
 }
+
+export function emitJoinChannelEvent(channel, success, failure) {
+    Client.joinChannel(
+        channel.id,
+        success,
+        failure,
+    );
+}
-- 
cgit v1.2.3-1-g7c22

