Skip to content

Commit

Permalink
PLT-5653 Fix Create channel does not show in another device
Browse files Browse the repository at this point in the history
  • Loading branch information
enahum committed Feb 27, 2017
1 parent 71d010b commit 165db9a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
4 changes: 4 additions & 0 deletions app/channel.go
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions model/websocket_message.go
Expand Up @@ -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"
Expand Down
47 changes: 27 additions & 20 deletions webapp/actions/channel_actions.jsx
Expand Up @@ -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');
Expand Down
16 changes: 15 additions & 1 deletion webapp/actions/websocket_actions.jsx
Expand Up @@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -137,6 +138,10 @@ function handleEvent(msg) {
handleUserUpdatedEvent(msg);
break;

case SocketEvents.CHANNEL_CREATED:
handleChannelCreatedEvent(msg);
break;

case SocketEvents.CHANNEL_DELETED:
handleChannelDeletedEvent(msg);
break;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions webapp/utils/constants.jsx
Expand Up @@ -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',
Expand Down

0 comments on commit 165db9a

Please sign in to comment.