From 23ccfc845ca2350075f6027e16c6206fc7b71716 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 26 Jun 2017 08:16:57 -0400 Subject: Move remaining actions over to use redux and v4 endpoints (#6720) --- webapp/routes/route_team.jsx | 45 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'webapp/routes') diff --git a/webapp/routes/route_team.jsx b/webapp/routes/route_team.jsx index c7ccc5392..d048cb5c9 100644 --- a/webapp/routes/route_team.jsx +++ b/webapp/routes/route_team.jsx @@ -14,8 +14,6 @@ import {reconnect} from 'actions/websocket_actions.jsx'; import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import Constants from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; -import * as AsyncClient from 'utils/async_client.jsx'; -import Client from 'client/web_client.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import BrowserStore from 'stores/browser_store.jsx'; import * as Utils from 'utils/utils.jsx'; @@ -31,6 +29,8 @@ const dispatch = store.dispatch; const getState = store.getState; import {fetchMyChannelsAndMembers, joinChannel} from 'mattermost-redux/actions/channels'; +import {getMyTeamUnreads} from 'mattermost-redux/actions/teams'; +import {getUser, getUserByUsername, getUserByEmail} from 'mattermost-redux/actions/users'; function onChannelEnter(nextState, replace, callback) { doChannelChange(nextState, replace, callback); @@ -111,7 +111,7 @@ function preNeedsTeam(nextState, replace, callback) { if (nextState.location.pathname.indexOf('/channels/') > -1 || nextState.location.pathname.indexOf('/pl/') > -1 || nextState.location.pathname.indexOf('/messages/') > -1) { - AsyncClient.getMyTeamsUnread(); + getMyTeamUnreads()(dispatch, getState); fetchMyChannelsAndMembers(team.id)(dispatch, getState); } @@ -172,13 +172,14 @@ function onChannelByIdentifierEnter(state, replace, callback) { replace(`/${state.params.team}/messages/@${teammate.username}`); callback(); } else { - Client.getUser( - userId, + getUser(userId)(dispatch, getState).then( (profile) => { - replace(`/${state.params.team}/messages/@${profile.username}`); - callback(); - }, () => { - handleError(state, replace, callback); + if (profile) { + replace(`/${state.params.team}/messages/@${profile.username}`); + callback(); + } else if (profile == null) { + handleError(state, replace, callback); + } } ); } @@ -224,7 +225,16 @@ function onChannelByIdentifierEnter(state, replace, callback) { if (teammate) { directChannelToUser(teammate, state, replace, callback); } else { - Client.getByUsername(username, success, error); + getUserByUsername(username)(dispatch, getState).then( + (data) => { + if (data && success) { + success(data); + } else if (data == null && error) { + const serverError = getState().requests.users.getUserByUsername.error; + error({id: serverError.server_error_id, ...serverError}); + } + } + ); } } else if (identifier.indexOf('@') > 0) { // email identifier const email = identifier; @@ -232,7 +242,16 @@ function onChannelByIdentifierEnter(state, replace, callback) { if (teammate) { directChannelToUser(teammate, state, replace, callback); } else { - Client.getByEmail(email, success, error); + getUserByEmail(email)(dispatch, getState).then( + (data) => { + if (data && success) { + success(data); + } else if (data == null && error) { + const serverError = getState().requests.users.getUser.error; + error({id: serverError.server_error_id, ...serverError}); + } + } + ); } } } @@ -242,10 +261,6 @@ function directChannelToUser(profile, state, replace, callback) { openDirectChannelToUser( profile.id, (channel) => { - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_CHANNEL, - channel - }); GlobalActions.emitChannelClickEvent(channel); callback(); }, -- cgit v1.2.3-1-g7c22