Only shift message when messages were fetched at least one time

This commit is contained in:
Jannis Mattheis 2018-04-15 16:39:30 +02:00 committed by Jannis Mattheis
parent eeadd0505c
commit 26f36442fd
1 changed files with 8 additions and 12 deletions

View File

@ -56,12 +56,14 @@ class MessageStore extends EventEmitter {
this.loading = false; this.loading = false;
this.emit('change'); this.emit('change');
} else if (data.type === 'ONE_MESSAGE') { } else if (data.type === 'ONE_MESSAGE') {
this.createIfNotExist(payload.appid); if (this.exists(payload.appid)) {
this.createIfNotExist(-1); this.appToMessages[payload.appid].messages.unshift(payload);
this.appToMessages[payload.appid].messages.unshift(payload); this.reset = 0;
this.appToMessages[-1].messages.unshift(payload); }
this.reset = 0; if (this.exists(-1)) {
this.resetOnAll = 0; this.appToMessages[-1].messages.unshift(payload);
this.resetOnAll = 0;
}
this.updateApps(); this.updateApps();
this.emit('change'); this.emit('change');
} else if (data.type === 'DELETE_MESSAGE') { } else if (data.type === 'DELETE_MESSAGE') {
@ -100,12 +102,6 @@ class MessageStore extends EventEmitter {
appMessages.messages.forEach((message) => message.image = appToUrl[message.appid]); appMessages.messages.forEach((message) => message.image = appToUrl[message.appid]);
}); });
}; };
createIfNotExist(id) {
if (!(id in this.appToMessages)) {
this.appToMessages[id] = this.get(id);
}
}
} }
const store = new MessageStore(); const store = new MessageStore();