From 250a344d04d8e682a98760bdc378d1a5c46f31e6 Mon Sep 17 00:00:00 2001
From: Harrison Healey <harrisonmhealey@gmail.com>
Date: Fri, 7 Jul 2017 20:23:58 -0400
Subject: PLT-7039 Use loadProfilesAndStatusesForPosts from the redux library
 (#6881)

---
 webapp/actions/post_actions.jsx | 30 ++++--------------------------
 1 file changed, 4 insertions(+), 26 deletions(-)

(limited to 'webapp/actions/post_actions.jsx')

diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
index 43204a543..ae9f069f5 100644
--- a/webapp/actions/post_actions.jsx
+++ b/webapp/actions/post_actions.jsx
@@ -19,7 +19,6 @@ import store from 'stores/redux_store.jsx';
 const dispatch = store.dispatch;
 const getState = store.getState;
 
-import {getProfilesByIds} from 'mattermost-redux/actions/users';
 import * as PostActions from 'mattermost-redux/actions/posts';
 import {getMyChannelMember} from 'mattermost-redux/actions/channels';
 
@@ -55,7 +54,7 @@ function completePostReceive(post, websocketMessageProps) {
         PostActions.getPostThread(post.root_id)(dispatch, getState).then(
             (data) => {
                 dispatchPostActions(post, websocketMessageProps);
-                loadProfilesForPosts(data.posts);
+                PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
             }
         );
 
@@ -123,7 +122,7 @@ export function getFlaggedPosts() {
                 is_pinned_posts: false
             });
 
-            loadProfilesForPosts(data.posts);
+            PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
         }
     ).catch(
         () => {} //eslint-disable-line no-empty-function
@@ -147,34 +146,13 @@ export function getPinnedPosts(channelId = ChannelStore.getCurrentId()) {
                 is_pinned_posts: true
             });
 
-            loadProfilesForPosts(data.posts);
+            PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
         }
     ).catch(
         () => {} //eslint-disable-line no-empty-function
     );
 }
 
-export function loadProfilesForPosts(posts) {
-    const profilesToLoad = {};
-    for (const pid in posts) {
-        if (!posts.hasOwnProperty(pid)) {
-            continue;
-        }
-
-        const post = posts[pid];
-        if (!UserStore.hasProfile(post.user_id)) {
-            profilesToLoad[post.user_id] = true;
-        }
-    }
-
-    const list = Object.keys(profilesToLoad);
-    if (list.length === 0) {
-        return;
-    }
-
-    getProfilesByIds(list)(dispatch, getState);
-}
-
 export function addReaction(channelId, postId, emojiName) {
     PostActions.addReaction(postId, emojiName)(dispatch, getState);
 }
@@ -252,7 +230,7 @@ export function performSearch(terms, isMentionSearch, success, error) {
                 is_mention_search: isMentionSearch
             });
 
-            loadProfilesForPosts(data.posts);
+            PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
 
             if (success) {
                 success(data);
-- 
cgit v1.2.3-1-g7c22


From 4956a7198b16630e394e93e69a571df3638f3a99 Mon Sep 17 00:00:00 2001
From: Saturnino Abril <saturnino.abril@gmail.com>
Date: Sun, 9 Jul 2017 06:36:30 +0800
Subject: Revert "PLT-7039 Use loadProfilesAndStatusesForPosts from the redux
 library (#6881)" (#6882)

This reverts commit 250a344d04d8e682a98760bdc378d1a5c46f31e6.
---
 webapp/actions/post_actions.jsx | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

(limited to 'webapp/actions/post_actions.jsx')

diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
index ae9f069f5..43204a543 100644
--- a/webapp/actions/post_actions.jsx
+++ b/webapp/actions/post_actions.jsx
@@ -19,6 +19,7 @@ import store from 'stores/redux_store.jsx';
 const dispatch = store.dispatch;
 const getState = store.getState;
 
+import {getProfilesByIds} from 'mattermost-redux/actions/users';
 import * as PostActions from 'mattermost-redux/actions/posts';
 import {getMyChannelMember} from 'mattermost-redux/actions/channels';
 
@@ -54,7 +55,7 @@ function completePostReceive(post, websocketMessageProps) {
         PostActions.getPostThread(post.root_id)(dispatch, getState).then(
             (data) => {
                 dispatchPostActions(post, websocketMessageProps);
-                PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
+                loadProfilesForPosts(data.posts);
             }
         );
 
@@ -122,7 +123,7 @@ export function getFlaggedPosts() {
                 is_pinned_posts: false
             });
 
-            PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
+            loadProfilesForPosts(data.posts);
         }
     ).catch(
         () => {} //eslint-disable-line no-empty-function
@@ -146,13 +147,34 @@ export function getPinnedPosts(channelId = ChannelStore.getCurrentId()) {
                 is_pinned_posts: true
             });
 
-            PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
+            loadProfilesForPosts(data.posts);
         }
     ).catch(
         () => {} //eslint-disable-line no-empty-function
     );
 }
 
+export function loadProfilesForPosts(posts) {
+    const profilesToLoad = {};
+    for (const pid in posts) {
+        if (!posts.hasOwnProperty(pid)) {
+            continue;
+        }
+
+        const post = posts[pid];
+        if (!UserStore.hasProfile(post.user_id)) {
+            profilesToLoad[post.user_id] = true;
+        }
+    }
+
+    const list = Object.keys(profilesToLoad);
+    if (list.length === 0) {
+        return;
+    }
+
+    getProfilesByIds(list)(dispatch, getState);
+}
+
 export function addReaction(channelId, postId, emojiName) {
     PostActions.addReaction(postId, emojiName)(dispatch, getState);
 }
@@ -230,7 +252,7 @@ export function performSearch(terms, isMentionSearch, success, error) {
                 is_mention_search: isMentionSearch
             });
 
-            PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
+            loadProfilesForPosts(data.posts);
 
             if (success) {
                 success(data);
-- 
cgit v1.2.3-1-g7c22


From 1e7022ff6d04b5f341c13530105d9dcf08c88ca8 Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Mon, 10 Jul 2017 14:51:31 -0400
Subject: Deleting the focused post now sends user to normal channel view
 (#6890)

---
 webapp/actions/post_actions.jsx | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'webapp/actions/post_actions.jsx')

diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
index 43204a543..87d9ed739 100644
--- a/webapp/actions/post_actions.jsx
+++ b/webapp/actions/post_actions.jsx
@@ -14,6 +14,8 @@ import {sendDesktopNotification} from 'actions/notification_actions.jsx';
 import Constants from 'utils/constants.jsx';
 const ActionTypes = Constants.ActionTypes;
 
+import {browserHistory} from 'react-router/es6';
+
 // Redux actions
 import store from 'stores/redux_store.jsx';
 const dispatch = store.dispatch;
@@ -236,6 +238,12 @@ export function deletePost(channelId, post, success) {
                 data: post
             });
 
+            const {focusedPostId} = getState().views.channel;
+            const channel = getState().entities.channels.channels[post.channel_id];
+            if (post.id === focusedPostId && channel) {
+                browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + channel.name);
+            }
+
             if (success) {
                 success();
             }
-- 
cgit v1.2.3-1-g7c22


From 0c910cc8c5a5487a129663431c6cd4d52640bd66 Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Mon, 10 Jul 2017 17:35:50 -0400
Subject: Fix multiple pinned post issues (#6887)

---
 webapp/actions/post_actions.jsx | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

(limited to 'webapp/actions/post_actions.jsx')

diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
index 87d9ed739..a32fee616 100644
--- a/webapp/actions/post_actions.jsx
+++ b/webapp/actions/post_actions.jsx
@@ -329,3 +329,23 @@ export function searchForTerm(term) {
         do_search: true
     });
 }
+
+export function pinPost(postId) {
+    return async (doDispatch, doGetState) => {
+        await PostActions.pinPost(postId)(doDispatch, doGetState);
+
+        AppDispatcher.handleServerAction({
+            type: ActionTypes.RECEIVED_POST_PINNED
+        });
+    };
+}
+
+export function unpinPost(postId) {
+    return async (doDispatch, doGetState) => {
+        await PostActions.unpinPost(postId)(doDispatch, doGetState);
+
+        AppDispatcher.handleServerAction({
+            type: ActionTypes.RECEIVED_POST_UNPINNED
+        });
+    };
+}
-- 
cgit v1.2.3-1-g7c22


From d307162d1621a5c422f8da19d8ff94b16e80abf0 Mon Sep 17 00:00:00 2001
From: Harrison Healey <harrisonmhealey@gmail.com>
Date: Mon, 10 Jul 2017 17:36:26 -0400
Subject: PLT-7039 Use loadProfilesAndStatusesForPosts from the redux library
 (Resubmit) (#6892)

* PLT-7039 Use loadProfilesAndStatusesForPosts from the redux library

* Switched mattermost-redux to webapp-4.0 branch
---
 webapp/actions/post_actions.jsx | 30 ++++--------------------------
 1 file changed, 4 insertions(+), 26 deletions(-)

(limited to 'webapp/actions/post_actions.jsx')

diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
index a32fee616..f319d59e3 100644
--- a/webapp/actions/post_actions.jsx
+++ b/webapp/actions/post_actions.jsx
@@ -21,7 +21,6 @@ import store from 'stores/redux_store.jsx';
 const dispatch = store.dispatch;
 const getState = store.getState;
 
-import {getProfilesByIds} from 'mattermost-redux/actions/users';
 import * as PostActions from 'mattermost-redux/actions/posts';
 import {getMyChannelMember} from 'mattermost-redux/actions/channels';
 
@@ -57,7 +56,7 @@ function completePostReceive(post, websocketMessageProps) {
         PostActions.getPostThread(post.root_id)(dispatch, getState).then(
             (data) => {
                 dispatchPostActions(post, websocketMessageProps);
-                loadProfilesForPosts(data.posts);
+                PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
             }
         );
 
@@ -125,7 +124,7 @@ export function getFlaggedPosts() {
                 is_pinned_posts: false
             });
 
-            loadProfilesForPosts(data.posts);
+            PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
         }
     ).catch(
         () => {} //eslint-disable-line no-empty-function
@@ -149,34 +148,13 @@ export function getPinnedPosts(channelId = ChannelStore.getCurrentId()) {
                 is_pinned_posts: true
             });
 
-            loadProfilesForPosts(data.posts);
+            PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
         }
     ).catch(
         () => {} //eslint-disable-line no-empty-function
     );
 }
 
-export function loadProfilesForPosts(posts) {
-    const profilesToLoad = {};
-    for (const pid in posts) {
-        if (!posts.hasOwnProperty(pid)) {
-            continue;
-        }
-
-        const post = posts[pid];
-        if (!UserStore.hasProfile(post.user_id)) {
-            profilesToLoad[post.user_id] = true;
-        }
-    }
-
-    const list = Object.keys(profilesToLoad);
-    if (list.length === 0) {
-        return;
-    }
-
-    getProfilesByIds(list)(dispatch, getState);
-}
-
 export function addReaction(channelId, postId, emojiName) {
     PostActions.addReaction(postId, emojiName)(dispatch, getState);
 }
@@ -260,7 +238,7 @@ export function performSearch(terms, isMentionSearch, success, error) {
                 is_mention_search: isMentionSearch
             });
 
-            loadProfilesForPosts(data.posts);
+            PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
 
             if (success) {
                 success(data);
-- 
cgit v1.2.3-1-g7c22


From 8395981d2b3a02e2b61458cd19872632a45c2849 Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Wed, 12 Jul 2017 12:38:07 -0400
Subject: Properly updated pinned/flagged posts on deletion (#6920)

---
 webapp/actions/post_actions.jsx | 6 ++++++
 1 file changed, 6 insertions(+)

(limited to 'webapp/actions/post_actions.jsx')

diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
index f319d59e3..836d3e380 100644
--- a/webapp/actions/post_actions.jsx
+++ b/webapp/actions/post_actions.jsx
@@ -216,6 +216,12 @@ export function deletePost(channelId, post, success) {
                 data: post
             });
 
+            // Needed for search store
+            AppDispatcher.handleViewAction({
+                type: Constants.ActionTypes.REMOVE_POST,
+                post
+            });
+
             const {focusedPostId} = getState().views.channel;
             const channel = getState().entities.channels.channels[post.channel_id];
             if (post.id === focusedPostId && channel) {
-- 
cgit v1.2.3-1-g7c22


From 3ad3aa653f1bba0b8051782bf7a7bb03a7519c82 Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Fri, 14 Jul 2017 13:12:52 -0400
Subject: Add back blue bar error for editing post after time limit (#6939)

---
 webapp/actions/post_actions.jsx | 7 +++++++
 1 file changed, 7 insertions(+)

(limited to 'webapp/actions/post_actions.jsx')

diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
index 836d3e380..09cc14e40 100644
--- a/webapp/actions/post_actions.jsx
+++ b/webapp/actions/post_actions.jsx
@@ -182,6 +182,13 @@ export function updatePost(post, success) {
         (data) => {
             if (data && success) {
                 success();
+            } else {
+                const serverError = getState().requests.posts.editPost.error;
+                AppDispatcher.handleServerAction({
+                    type: ActionTypes.RECEIVED_ERROR,
+                    err: {id: serverError.server_error_id, ...serverError},
+                    method: 'editPost'
+                });
             }
         }
     );
-- 
cgit v1.2.3-1-g7c22

