diff options
author | enahum <nahumhbl@gmail.com> | 2017-02-27 17:41:12 -0300 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-02-27 15:41:12 -0500 |
commit | 48f97a5a2a0754bfc0e639db7cce03943e990e32 (patch) | |
tree | 74d6a48d467d245e62f1e3c526a9abf9413c71a9 /webapp | |
parent | 72de977c522465bc2ee044cd4a26baf666f299a3 (diff) | |
download | chat-48f97a5a2a0754bfc0e639db7cce03943e990e32.tar.gz chat-48f97a5a2a0754bfc0e639db7cce03943e990e32.tar.bz2 chat-48f97a5a2a0754bfc0e639db7cce03943e990e32.zip |
PLT-5653 Fix Create channel does not show in another device (#5548)
Diffstat (limited to 'webapp')
-rw-r--r-- | webapp/actions/channel_actions.jsx | 47 | ||||
-rw-r--r-- | webapp/actions/websocket_actions.jsx | 16 | ||||
-rw-r--r-- | webapp/utils/constants.jsx | 1 |
3 files changed, 43 insertions, 21 deletions
diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx index 3528b4480..5f41d127d 100644 --- a/webapp/actions/channel_actions.jsx +++ b/webapp/actions/channel_actions.jsx @@ -335,27 +335,34 @@ export function createChannel(channel, success, error) { Client.createChannel( channel, (data) => { - Client.getChannel( - data.id, - (data2) => { - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_CHANNEL, - channel: data2.channel, - member: data2.channel - }); - - if (success) { - success(data2); - } - }, - (err) => { - AsyncClient.dispatchError(err, 'getChannel'); - - if (error) { - error(err); - } + const existing = ChannelStore.getChannelById(data.id); + if (existing) { + if (success) { + success({channel: existing}); } - ); + } else { + Client.getChannel( + data.id, + (data2) => { + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_CHANNEL, + channel: data2.channel, + member: data2.channel + }); + + if (success) { + success(data2); + } + }, + (err) => { + AsyncClient.dispatchError(err, 'getChannel'); + + if (error) { + error(err); + } + } + ); + } }, (err) => { AsyncClient.dispatchError(err, 'createChannel'); diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx index 2e95c712c..e6403839d 100644 --- a/webapp/actions/websocket_actions.jsx +++ b/webapp/actions/websocket_actions.jsx @@ -6,6 +6,7 @@ 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 PreferenceStore from 'stores/preference_store.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import BrowserStore from 'stores/browser_store.jsx'; import ErrorStore from 'stores/error_store.jsx'; @@ -25,7 +26,7 @@ import {loadProfilesAndTeamMembersForDMSidebar} from 'actions/user_actions.jsx'; import {loadChannelsForCurrentUser} from 'actions/channel_actions.jsx'; import * as StatusActions from 'actions/status_actions.jsx'; -import {ActionTypes, Constants, SocketEvents, UserStatuses} from 'utils/constants.jsx'; +import {ActionTypes, Constants, Preferences, SocketEvents, UserStatuses} from 'utils/constants.jsx'; import {browserHistory} from 'react-router/es6'; @@ -137,6 +138,10 @@ function handleEvent(msg) { handleUserUpdatedEvent(msg); break; + case SocketEvents.CHANNEL_CREATED: + handleChannelCreatedEvent(msg); + break; + case SocketEvents.CHANNEL_DELETED: handleChannelDeletedEvent(msg); break; @@ -238,6 +243,7 @@ function handleUpdateTeamEvent(msg) { function handleDirectAddedEvent(msg) { AsyncClient.getChannel(msg.broadcast.channel_id); + PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, msg.data.teammate_id, 'true'); loadProfilesAndTeamMembersForDMSidebar(); } @@ -278,6 +284,14 @@ function handleUserUpdatedEvent(msg) { } } +function handleChannelCreatedEvent(msg) { + const channelId = msg.data.channel_id; + + if (!ChannelStore.getChannelById(channelId)) { + AsyncClient.getChannel(channelId); + } +} + function handleChannelDeletedEvent(msg) { if (ChannelStore.getCurrentId() === msg.data.channel_id) { const teamUrl = TeamStore.getCurrentTeamRelativeUrl(); diff --git a/webapp/utils/constants.jsx b/webapp/utils/constants.jsx index 68b6f2cc0..94fad3f35 100644 --- a/webapp/utils/constants.jsx +++ b/webapp/utils/constants.jsx @@ -203,6 +203,7 @@ export const SocketEvents = { POSTED: 'posted', POST_EDITED: 'post_edited', POST_DELETED: 'post_deleted', + CHANNEL_CREATED: 'channel_created', CHANNEL_DELETED: 'channel_deleted', CHANNEL_VIEWED: 'channel_viewed', DIRECT_ADDED: 'direct_added', |