From d307162d1621a5c422f8da19d8ff94b16e80abf0 Mon Sep 17 00:00:00 2001 From: Harrison Healey 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 ++++-------------------------- webapp/actions/websocket_actions.jsx | 8 +++----- 2 files changed, 7 insertions(+), 31 deletions(-) (limited to 'webapp') 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); diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx index dec3edd12..82c9df617 100644 --- a/webapp/actions/websocket_actions.jsx +++ b/webapp/actions/websocket_actions.jsx @@ -15,7 +15,7 @@ import WebSocketClient from 'client/web_websocket_client.jsx'; import * as WebrtcActions from './webrtc_actions.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; -import {handleNewPost, loadProfilesForPosts} from 'actions/post_actions.jsx'; +import {handleNewPost} from 'actions/post_actions.jsx'; import {loadProfilesForSidebar} from 'actions/user_actions.jsx'; import {loadChannelsForCurrentUser} from 'actions/channel_actions.jsx'; import * as StatusActions from 'actions/status_actions.jsx'; @@ -34,7 +34,7 @@ import {getSiteURL} from 'utils/url.jsx'; import * as TeamActions from 'mattermost-redux/actions/teams'; import {viewChannel, getChannelAndMyMember, getChannelStats} from 'mattermost-redux/actions/channels'; -import {getPosts} from 'mattermost-redux/actions/posts'; +import {getPosts, getProfilesAndStatusesForPosts} from 'mattermost-redux/actions/posts'; import {setServerVersion} from 'mattermost-redux/actions/general'; import {ChannelTypes, TeamTypes, UserTypes, PostTypes, EmojiTypes} from 'mattermost-redux/action_types'; @@ -242,9 +242,7 @@ function handleNewPostEvent(msg) { const post = JSON.parse(msg.data.post); handleNewPost(post, msg); - const posts = {}; - posts[post.id] = post; - loadProfilesForPosts(posts); + getProfilesAndStatusesForPosts([post], dispatch, getState); if (post.user_id !== UserStore.getCurrentId()) { UserStore.setStatus(post.user_id, UserStatuses.ONLINE); -- cgit v1.2.3-1-g7c22