From 7695cbd1b4a62b1cc7c31b16f70309a287296385 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 27 Apr 2016 16:05:39 -0400 Subject: Add websocket event and cache invalidation for deleting channels (#2807) --- webapp/action_creators/websocket_actions.jsx | 15 +++++++++++++++ webapp/stores/team_store.jsx | 20 +++++++------------- webapp/utils/constants.jsx | 1 + 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'webapp') diff --git a/webapp/action_creators/websocket_actions.jsx b/webapp/action_creators/websocket_actions.jsx index a1368ac99..83a000f6d 100644 --- a/webapp/action_creators/websocket_actions.jsx +++ b/webapp/action_creators/websocket_actions.jsx @@ -18,6 +18,8 @@ import * as GlobalActions from 'action_creators/global_actions.jsx'; import Constants from 'utils/constants.jsx'; const SocketEvents = Constants.SocketEvents; +import {browserHistory} from 'react-router'; + const MAX_WEBSOCKET_FAILS = 7; const WEBSOCKET_RETRY_TIME = 3000; @@ -135,6 +137,10 @@ function handleMessage(msg) { handleChannelViewedEvent(msg); break; + case SocketEvents.CHANNEL_DELETED: + handleChannelDeletedEvent(msg); + break; + case SocketEvents.PREFERENCE_CHANGED: handlePreferenceChangedEvent(msg); break; @@ -234,6 +240,15 @@ function handleChannelViewedEvent(msg) { } } +function handleChannelDeletedEvent(msg) { + if (ChannelStore.getCurrentId() === msg.channel_id) { + const teamUrl = TeamStore.getCurrentTeamRelativeUrl(); + browserHistory.push(teamUrl + '/channels/' + Constants.DEFAULT_CHANNEL); + } else { + AsyncClient.getChannels(); + } +} + function handlePreferenceChangedEvent(msg) { const preference = JSON.parse(msg.props.preference); GlobalActions.emitPreferenceChangedEvent(preference); diff --git a/webapp/stores/team_store.jsx b/webapp/stores/team_store.jsx index 356df7b07..29e832633 100644 --- a/webapp/stores/team_store.jsx +++ b/webapp/stores/team_store.jsx @@ -20,19 +20,6 @@ function getWindowLocationOrigin() { class TeamStoreClass extends EventEmitter { constructor() { super(); - - this.emitChange = this.emitChange.bind(this); - this.addChangeListener = this.addChangeListener.bind(this); - this.removeChangeListener = this.removeChangeListener.bind(this); - this.get = this.get.bind(this); - this.getByName = this.getByName.bind(this); - this.getAll = this.getAll.bind(this); - this.getCurrentId = this.getCurrentId.bind(this); - this.getCurrent = this.getCurrent.bind(this); - this.getCurrentTeamUrl = this.getCurrentTeamUrl.bind(this); - this.getCurrentInviteLink = this.getCurrentInviteLink.bind(this); - this.saveTeam = this.saveTeam.bind(this); - this.clear(); } @@ -104,6 +91,13 @@ class TeamStoreClass extends EventEmitter { return null; } + getCurrentTeamRelativeUrl() { + if (this.getCurrent()) { + return '/' + this.getCurrent().name; + } + return null; + } + getCurrentInviteLink() { const current = this.getCurrent(); diff --git a/webapp/utils/constants.jsx b/webapp/utils/constants.jsx index 9bdf348cd..3f8980bfa 100644 --- a/webapp/utils/constants.jsx +++ b/webapp/utils/constants.jsx @@ -147,6 +147,7 @@ export default { POSTED: 'posted', POST_EDITED: 'post_edited', POST_DELETED: 'post_deleted', + CHANNEL_DELETED: 'channel_deleted', CHANNEL_VIEWED: 'channel_viewed', NEW_USER: 'new_user', USER_ADDED: 'user_added', -- cgit v1.2.3-1-g7c22