Remove order dependency on channels and channel members plus logging (#4370)

This commit is contained in:
Joram Wilander
2016-10-28 09:36:41 -04:00
committed by GitHub
parent 35ceedf968
commit 87a3daf9a6

View File

@@ -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;