diff options
Diffstat (limited to 'webapp/action_creators')
-rw-r--r-- | webapp/action_creators/global_actions.jsx | 113 | ||||
-rw-r--r-- | webapp/action_creators/websocket_actions.jsx | 19 |
2 files changed, 116 insertions, 16 deletions
diff --git a/webapp/action_creators/global_actions.jsx b/webapp/action_creators/global_actions.jsx index fd447ec93..5641246f9 100644 --- a/webapp/action_creators/global_actions.jsx +++ b/webapp/action_creators/global_actions.jsx @@ -4,11 +4,16 @@ import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import PostStore from 'stores/post_store.jsx'; +import UserStore from 'stores/user_store.jsx'; +import BrowserStore from 'stores/browser_store.jsx'; +import ErrorStore from 'stores/error_store.jsx'; +import TeamStore from 'stores/team_store.jsx'; +import PreferenceStore from 'stores/preference_store.jsx'; import SearchStore from 'stores/search_store.jsx'; import Constants from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; import * as AsyncClient from 'utils/async_client.jsx'; -import * as Client from 'utils/client.jsx'; +import Client from 'utils/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; import * as Websockets from './websocket_actions.jsx'; import * as I18n from 'i18n/i18n.jsx'; @@ -21,7 +26,6 @@ export function emitChannelClickEvent(channel) { function userVisitedFakeChannel(chan, success, fail) { const otherUserId = Utils.getUserIdFromChannelName(chan); Client.createDirectChannel( - chan, otherUserId, (data) => { success(data); @@ -61,6 +65,69 @@ export function emitChannelClickEvent(channel) { } } +export function emitInitialLoad(callback) { + Client.getInitialLoad( + (data) => { + global.window.mm_config = data.client_cfg; + global.window.mm_license = data.license_cfg; + + UserStore.setNoAccounts(data.no_accounts); + + if (data.user && data.user.id) { + global.window.mm_user = data.user; + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_ME, + me: data.user + }); + } + + if (data.preferences) { + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_PREFERENCES, + preferences: data.preferences + }); + } + + if (data.teams) { + var teams = {}; + data.teams.forEach((team) => { + teams[team.id] = team; + }); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_ALL_TEAMS, + teams + }); + } + + if (data.team_members) { + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_TEAM_MEMBERS, + team_members: data.team_members + }); + } + + if (data.direct_profiles) { + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_DIRECT_PROFILES, + profiles: data.direct_profiles + }); + } + + if (callback) { + callback(); + } + }, + (err) => { + AsyncClient.dispatchError(err, 'getInitialLoad'); + + if (callback) { + callback(); + } + } + ); +} + export function emitPostFocusEvent(postId) { AsyncClient.getChannels(true); Client.getPostById( @@ -80,6 +147,18 @@ export function emitPostFocusEvent(postId) { ); } +export function emitCloseRightHandSide() { + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_SEARCH, + results: null + }); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_POST_SELECTED, + postId: null + }); +} + export function emitPostFocusRightHandSideFromSearch(post, isMentionSearch) { Client.getPost( post.channel_id, @@ -133,21 +212,21 @@ export function emitLoadMorePostsFocusedBottomEvent() { AsyncClient.getPostsAfter(latestPostId, 0, Constants.POST_CHUNK_SIZE); } -export function emitPostRecievedEvent(post, websocketMessageProps) { +export function emitPostRecievedEvent(post, msg) { if (ChannelStore.getCurrentId() === post.channel_id) { if (window.isActive) { AsyncClient.updateLastViewedAt(); } else { AsyncClient.getChannel(post.channel_id); } - } else { + } else if (msg && TeamStore.getCurrentId() === msg.team_id) { AsyncClient.getChannel(post.channel_id); } AppDispatcher.handleServerAction({ type: ActionTypes.RECEIVED_POST, post, - websocketMessageProps + websocketMessageProps: msg.props }); } @@ -271,10 +350,6 @@ export function sendEphemeralPost(message, channelId) { emitPostRecievedEvent(post); } -export function loadTeamRequiredPage() { - AsyncClient.getAllTeams(); -} - export function newLocalizationSelected(locale) { if (locale === 'en') { AppDispatcher.handleServerAction({ @@ -311,8 +386,6 @@ export function loadBrowserLocale() { export function viewLoggedIn() { AsyncClient.getChannels(); AsyncClient.getChannelExtraInfo(); - AsyncClient.getMyTeam(); - AsyncClient.getMe(); // Clear pending posts (shouldn't have pending posts if we are loading) PostStore.clearPendingPosts(); @@ -335,3 +408,21 @@ export function emitRemoteUserTypingEvent(channelId, userId, postParentId) { postParentId }); } + +export function emitUserLoggedOutEvent(redirectTo) { + const rURL = (redirectTo && typeof redirectTo === 'string') ? redirectTo : '/'; + Client.logout( + () => { + BrowserStore.signalLogout(); + BrowserStore.clear(); + ErrorStore.clearLastError(); + PreferenceStore.clear(); + UserStore.clear(); + TeamStore.clear(); + browserHistory.push(rURL); + }, + () => { + browserHistory.push(rURL); + } + ); +} diff --git a/webapp/action_creators/websocket_actions.jsx b/webapp/action_creators/websocket_actions.jsx index a66d79d18..c4e9c63c2 100644 --- a/webapp/action_creators/websocket_actions.jsx +++ b/webapp/action_creators/websocket_actions.jsx @@ -3,12 +3,14 @@ import $ from 'jquery'; import UserStore from 'stores/user_store.jsx'; +import TeamStore from 'stores/team_store.jsx'; import PostStore from 'stores/post_store.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import BrowserStore from 'stores/browser_store.jsx'; import ErrorStore from 'stores/error_store.jsx'; import NotificationStore from 'stores/notification_store.jsx'; //eslint-disable-line no-unused-vars +import Client from 'utils/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; import * as GlobalActions from 'action_creators/global_actions.jsx'; @@ -31,7 +33,7 @@ export function initialize() { protocol = 'wss://'; } - const connUrl = protocol + location.host + ((/:\d+/).test(location.host) ? '' : Utils.getWebsocketPort(protocol)) + '/api/v1/websocket'; + const connUrl = protocol + location.host + ((/:\d+/).test(location.host) ? '' : Utils.getWebsocketPort(protocol)) + Client.getUsersRoute() + '/websocket'; if (connectFailCount === 0) { console.log('websocket connecting to ' + connUrl); //eslint-disable-line no-console @@ -145,6 +147,11 @@ function handleMessage(msg) { export function sendMessage(msg) { if (conn && conn.readyState === WebSocket.OPEN) { + var teamId = TeamStore.getCurrentId(); + if (teamId && teamId.length > 0) { + msg.team_id = teamId; + } + conn.send(JSON.stringify(msg)); } else if (!conn || conn.readyState === WebSocket.Closed) { conn = null; @@ -161,7 +168,7 @@ export function close() { function handleNewPostEvent(msg) { const post = JSON.parse(msg.props.post); - GlobalActions.emitPostRecievedEvent(post, msg.props); + GlobalActions.emitPostRecievedEvent(post, msg); } function handlePostEditEvent(msg) { @@ -193,7 +200,7 @@ function handleUserAddedEvent(msg) { AsyncClient.getChannelExtraInfo(); } - if (UserStore.getCurrentId() === msg.user_id) { + if (TeamStore.getCurrentId() === msg.team_id && UserStore.getCurrentId() === msg.user_id) { AsyncClient.getChannel(msg.channel_id); } } @@ -219,7 +226,7 @@ function handleUserRemovedEvent(msg) { function handleChannelViewedEvent(msg) { // Useful for when multiple devices have the app open to different channels - if (ChannelStore.getCurrentId() !== msg.channel_id && UserStore.getCurrentId() === msg.user_id) { + if (TeamStore.getCurrentId() === msg.team_id && ChannelStore.getCurrentId() !== msg.channel_id && UserStore.getCurrentId() === msg.user_id) { AsyncClient.getChannel(msg.channel_id); } } @@ -230,5 +237,7 @@ function handlePreferenceChangedEvent(msg) { } function handleUserTypingEvent(msg) { - GlobalActions.emitRemoteUserTypingEvent(msg.channel_id, msg.user_id, msg.props.parent_id); + if (TeamStore.getCurrentId() === msg.team_id) { + GlobalActions.emitRemoteUserTypingEvent(msg.channel_id, msg.user_id, msg.props.parent_id); + } } |