summaryrefslogtreecommitdiffstats
path: root/webapp/stores
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-10-28 09:36:41 -0400
committerGitHub <noreply@github.com>2016-10-28 09:36:41 -0400
commit87a3daf9a6469b666437b56bd32b06f5a70e0ce8 (patch)
treeae969dd2790fc7e36f778f367400df2a1d6cb892 /webapp/stores
parent35ceedf968ce5c3e9f1b548e9d5fe9123c68bbe6 (diff)
downloadchat-87a3daf9a6469b666437b56bd32b06f5a70e0ce8.tar.gz
chat-87a3daf9a6469b666437b56bd32b06f5a70e0ce8.tar.bz2
chat-87a3daf9a6469b666437b56bd32b06f5a70e0ce8.zip
Remove order dependency on channels and channel members plus logging (#4370)
Diffstat (limited to 'webapp/stores')
-rw-r--r--webapp/stores/channel_store.jsx25
1 files changed, 21 insertions, 4 deletions
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;