PLT-5660 Handle channel created WebSocket event (#306)

* Handle channel created WebSocket event

* increasing test timeout
This commit is contained in:
enahum 2017-02-27 19:51:04 -03:00 committed by GitHub
parent c121097974
commit b71052bd64
4 changed files with 46 additions and 8 deletions

View file

@ -61,18 +61,22 @@ export function createChannel(channel, userId) {
last_update_at: created.create_at
};
const actions = [];
const {channels, myMembers} = getState().entities.channels;
if (!channels[created.id]) {
actions.push({type: ChannelTypes.RECEIVED_CHANNEL, data: created});
}
if (!myMembers[created.id]) {
actions.push({type: ChannelTypes.RECEIVED_MY_CHANNEL_MEMBER, data: member});
}
dispatch(batchActions([
{
type: ChannelTypes.RECEIVED_CHANNEL,
data: created
},
...actions,
{
type: ChannelTypes.CREATE_CHANNEL_SUCCESS
},
{
type: ChannelTypes.RECEIVED_MY_CHANNEL_MEMBER,
data: member
},
{
type: ChannelTypes.CHANNEL_MEMBERS_SUCCESS
}

View file

@ -127,6 +127,9 @@ function handleEvent(msg, dispatch, getState) {
case WebsocketEvents.USER_UPDATED:
handleUserUpdatedEvent(msg, dispatch, getState);
break;
case WebsocketEvents.CHANNEL_CREATED:
handleChannelCreatedEvent(msg, dispatch, getState);
break;
case WebsocketEvents.CHANNEL_DELETED:
handleChannelDeletedEvent(msg, dispatch, getState);
break;
@ -303,6 +306,17 @@ function handleUserUpdatedEvent(msg, dispatch, getState) {
}
}
function handleChannelCreatedEvent(msg, dispatch, getState) {
const {channel_id: channelId, team_id: teamId} = msg.data;
const state = getState();
const {channels} = state.entities.channels;
const {currentId: currentTeamId} = state.entities.teams;
if (teamId === currentTeamId && !channels[channelId]) {
getChannel(teamId, channelId)(dispatch, getState);
}
}
function handleChannelDeletedEvent(msg, dispatch, getState) {
const entities = getState().entities;
const {channels, currentId} = entities.channels;

View file

@ -5,6 +5,7 @@ const WebsocketEvents = {
POSTED: 'posted',
POST_EDITED: 'post_edited',
POST_DELETED: 'post_deleted',
CHANNEL_CREATED: 'channel_created',
CHANNEL_DELETED: 'channel_deleted',
DIRECT_ADDED: 'direct_added',
LEAVE_TEAM: 'leave_team',

View file

@ -210,6 +210,25 @@ describe('Actions.Websocket', () => {
});
});
it('Websocket Handle Channel Created', (done) => {
async function test() {
await TeamActions.selectTeam(TestHelper.basicTeam)(store.dispatch, store.getState);
const channel = await Client.createChannel(TestHelper.fakeChannel(TestHelper.basicTeam.id));
setTimeout(() => {
const state = store.getState();
const entities = state.entities;
const {channels, myMembers} = entities.channels;
assert.ok(channels[channel.id]);
assert.ok(myMembers[channel.id]);
done();
}, 1000);
}
test();
});
it('Websocket Handle Channel Deleted', (done) => {
async function test() {
await TeamActions.selectTeam(TestHelper.basicTeam)(store.dispatch, store.getState);