From 87a3daf9a6469b666437b56bd32b06f5a70e0ce8 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 28 Oct 2016 09:36:41 -0400 Subject: Remove order dependency on channels and channel members plus logging (#4370) --- webapp/stores/channel_store.jsx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'webapp/stores') diff --git a/webapp/stores/channel_store.jsx b/webapp/stores/channel_store.jsx index 2ca01fc6e..16a094c7b 100644 --- a/webapp/stores/channel_store.jsx +++ b/webapp/stores/channel_store.jsx @@ -150,11 +150,11 @@ class ChannelStoreClass extends EventEmitter { resetCounts(id) { const cm = this.myChannelMembers; - for (var cmid in cm) { + for (const cmid in cm) { if (cm[cmid].channel_id === id) { - var c = this.get(id); - if (c) { - cm[cmid].msg_count = this.get(id).total_msg_count; + const channel = this.get(id); + if (channel) { + cm[cmid].msg_count = channel.total_msg_count; cm[cmid].mention_count = 0; this.setUnreadCountByChannel(id); } @@ -290,10 +290,26 @@ class ChannelStoreClass extends EventEmitter { }); } + setUnreadCountsByChannels(channels) { + channels.forEach((c) => { + this.setUnreadCountByChannel(c.id); + }); + } + setUnreadCountByChannel(id) { const ch = this.get(id); const chMember = this.getMyMember(id); + if (ch == null) { + console.log('setUnreadCountByChannel: missing channel id ' + id); //eslint-disable-line no-console + return; + } + + if (chMember == null) { + console.log('setUnreadCountByChannel: missing channel member for channel id ' + id); //eslint-disable-line no-console + return; + } + const chMentionCount = chMember.mention_count; let chUnreadCount = ch.total_msg_count - chMember.msg_count; @@ -367,6 +383,7 @@ ChannelStore.dispatchToken = AppDispatcher.register((payload) => { case ActionTypes.RECEIVED_CHANNELS: ChannelStore.storeChannels(action.channels); + ChannelStore.setUnreadCountsByChannels(action.channels); ChannelStore.emitChange(); break; -- cgit v1.2.3-1-g7c22