summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-04-27 16:05:39 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2016-04-27 16:05:39 -0400
commit7695cbd1b4a62b1cc7c31b16f70309a287296385 (patch)
tree15a7f35bb56f0c72a9c13192380d795a48339d48 /webapp
parentada513a0146cfb570e3614f9b26c0465de3a1d94 (diff)
downloadchat-7695cbd1b4a62b1cc7c31b16f70309a287296385.tar.gz
chat-7695cbd1b4a62b1cc7c31b16f70309a287296385.tar.bz2
chat-7695cbd1b4a62b1cc7c31b16f70309a287296385.zip
Add websocket event and cache invalidation for deleting channels (#2807)
Diffstat (limited to 'webapp')
-rw-r--r--webapp/action_creators/websocket_actions.jsx15
-rw-r--r--webapp/stores/team_store.jsx20
-rw-r--r--webapp/utils/constants.jsx1
3 files changed, 23 insertions, 13 deletions
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',