diff options
author | enahum <nahumhbl@gmail.com> | 2016-10-27 12:24:30 -0300 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2016-10-27 11:24:30 -0400 |
commit | f82667f3b86202dafff3a2a4ea56aec74c80316d (patch) | |
tree | 3785d9502505be528706e41b993a834c7bc00338 /webapp/stores/channel_store.jsx | |
parent | 14ce471311fee2830be3cbd3a90179015f513719 (diff) | |
download | chat-f82667f3b86202dafff3a2a4ea56aec74c80316d.tar.gz chat-f82667f3b86202dafff3a2a4ea56aec74c80316d.tar.bz2 chat-f82667f3b86202dafff3a2a4ea56aec74c80316d.zip |
PLT-4430 improve slow channel switching (#4331)
* PLT-4430 improve slow channel switching
* Update client side unit tests
* Convert getChannelsUnread to getMyChannelMembers and address other feedback
* Pull channel members on websocket reconnect
Diffstat (limited to 'webapp/stores/channel_store.jsx')
-rw-r--r-- | webapp/stores/channel_store.jsx | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/webapp/stores/channel_store.jsx b/webapp/stores/channel_store.jsx index 20e7c966f..2ca01fc6e 100644 --- a/webapp/stores/channel_store.jsx +++ b/webapp/stores/channel_store.jsx @@ -156,7 +156,7 @@ class ChannelStoreClass extends EventEmitter { if (c) { cm[cmid].msg_count = this.get(id).total_msg_count; cm[cmid].mention_count = 0; - this.setUnreadCount(id); + this.setUnreadCountByChannel(id); } break; } @@ -250,6 +250,12 @@ class ChannelStoreClass extends EventEmitter { this.myChannelMembers = channelMembers; } + storeMyChannelMembersList(channelMembers) { + channelMembers.forEach((m) => { + this.myChannelMembers[m.channel_id] = m; + }); + } + getMyMembers() { return this.myChannelMembers; } @@ -278,7 +284,13 @@ class ChannelStoreClass extends EventEmitter { return this.postMode; } - setUnreadCount(id) { + setUnreadCountsByMembers(members) { + members.forEach((m) => { + this.setUnreadCountByChannel(m.channel_id); + }); + } + + setUnreadCountByChannel(id) { const ch = this.get(id); const chMember = this.getMyMember(id); @@ -292,13 +304,6 @@ class ChannelStoreClass extends EventEmitter { this.unreadCounts[id] = {msgs: chUnreadCount, mentions: chMentionCount}; } - setUnreadCounts() { - const channels = this.getAll(); - channels.forEach((ch) => { - this.setUnreadCount(ch.id); - }); - } - getUnreadCount(id) { return this.unreadCounts[id] || {msgs: 0, mentions: 0}; } @@ -362,12 +367,6 @@ ChannelStore.dispatchToken = AppDispatcher.register((payload) => { case ActionTypes.RECEIVED_CHANNELS: ChannelStore.storeChannels(action.channels); - ChannelStore.storeMyChannelMembers(action.members); - currentId = ChannelStore.getCurrentId(); - if (currentId && window.isActive) { - ChannelStore.resetCounts(currentId); - } - ChannelStore.setUnreadCounts(); ChannelStore.emitChange(); break; @@ -380,10 +379,18 @@ ChannelStore.dispatchToken = AppDispatcher.register((payload) => { if (currentId && window.isActive) { ChannelStore.resetCounts(currentId); } - ChannelStore.setUnreadCount(action.channel.id); + ChannelStore.setUnreadCountByChannel(action.channel.id); ChannelStore.emitChange(); break; + case ActionTypes.RECEIVED_MY_CHANNEL_MEMBERS: + ChannelStore.storeMyChannelMembersList(action.members); + currentId = ChannelStore.getCurrentId(); + if (currentId && window.isActive) { + ChannelStore.resetCounts(currentId); + } + ChannelStore.setUnreadCountsByMembers(action.members); + break; case ActionTypes.RECEIVED_MORE_CHANNELS: ChannelStore.storeMoreChannels(action.channels); ChannelStore.emitMoreChange(); |