From 48f97a5a2a0754bfc0e639db7cce03943e990e32 Mon Sep 17 00:00:00 2001 From: enahum Date: Mon, 27 Feb 2017 17:41:12 -0300 Subject: PLT-5653 Fix Create channel does not show in another device (#5548) --- app/channel.go | 4 +++ model/websocket_message.go | 1 + webapp/actions/channel_actions.jsx | 47 +++++++++++++++++++++--------------- webapp/actions/websocket_actions.jsx | 16 +++++++++++- webapp/utils/constants.jsx | 1 + 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/app/channel.go b/app/channel.go index cff9564b5..71e8cee2c 100644 --- a/app/channel.go +++ b/app/channel.go @@ -105,6 +105,10 @@ func CreateChannelWithUser(channel *model.Channel, userId string) (*model.Channe return nil, err } + message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_CREATED, "", "", userId, nil) + message.Add("channel_id", channel.Id) + Publish(message) + return rchannel, nil } diff --git a/model/websocket_message.go b/model/websocket_message.go index cfbc51ed9..491998ebb 100644 --- a/model/websocket_message.go +++ b/model/websocket_message.go @@ -14,6 +14,7 @@ const ( WEBSOCKET_EVENT_POST_EDITED = "post_edited" WEBSOCKET_EVENT_POST_DELETED = "post_deleted" WEBSOCKET_EVENT_CHANNEL_DELETED = "channel_deleted" + WEBSOCKET_EVENT_CHANNEL_CREATED = "channel_created" WEBSOCKET_EVENT_DIRECT_ADDED = "direct_added" WEBSOCKET_EVENT_NEW_USER = "new_user" WEBSOCKET_EVENT_LEAVE_TEAM = "leave_team" 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', -- cgit v1.2.3-1-g7c22