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

Этот коммит содержится в:
Joram Wilander
2016-10-28 09:36:41 -04:00
коммит произвёл GitHub
родитель 35ceedf968
Коммит 87a3daf9a6

Просмотреть файл

@@ -150,11 +150,11 @@ class ChannelStoreClass extends EventEmitter {
resetCounts(id) { resetCounts(id) {
const cm = this.myChannelMembers; const cm = this.myChannelMembers;
for (var cmid in cm) { for (const cmid in cm) {
if (cm[cmid].channel_id === id) { if (cm[cmid].channel_id === id) {
var c = this.get(id); const channel = this.get(id);
if (c) { if (channel) {
cm[cmid].msg_count = this.get(id).total_msg_count; cm[cmid].msg_count = channel.total_msg_count;
cm[cmid].mention_count = 0; cm[cmid].mention_count = 0;
this.setUnreadCountByChannel(id); this.setUnreadCountByChannel(id);
} }
@@ -290,10 +290,26 @@ class ChannelStoreClass extends EventEmitter {
}); });
} }
setUnreadCountsByChannels(channels) {
channels.forEach((c) => {
this.setUnreadCountByChannel(c.id);
});
}
setUnreadCountByChannel(id) { setUnreadCountByChannel(id) {
const ch = this.get(id); const ch = this.get(id);
const chMember = this.getMyMember(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; const chMentionCount = chMember.mention_count;
let chUnreadCount = ch.total_msg_count - chMember.msg_count; let chUnreadCount = ch.total_msg_count - chMember.msg_count;
@@ -367,6 +383,7 @@ ChannelStore.dispatchToken = AppDispatcher.register((payload) => {
case ActionTypes.RECEIVED_CHANNELS: case ActionTypes.RECEIVED_CHANNELS:
ChannelStore.storeChannels(action.channels); ChannelStore.storeChannels(action.channels);
ChannelStore.setUnreadCountsByChannels(action.channels);
ChannelStore.emitChange(); ChannelStore.emitChange();
break; break;