diff --git a/ui/src/stores/MessageStore.js b/ui/src/stores/MessageStore.js index 59cdbbb..e6a75bb 100644 --- a/ui/src/stores/MessageStore.js +++ b/ui/src/stores/MessageStore.js @@ -1,11 +1,13 @@ import {EventEmitter} from 'events'; import dispatcher from './dispatcher'; +import AppStore from './AppStore'; class MessageStore extends EventEmitter { constructor() { super(); this.messages = []; this.messagesForApp = []; + AppStore.on('change', this.updateApps); } get() { @@ -30,16 +32,25 @@ class MessageStore extends EventEmitter { this.createIfNotExist(message.appid); this.messagesForApp[message.appid].push(message); }.bind(this)); + this.updateApps(); this.emit('change'); } else if (data.type === 'ONE_MESSAGE') { const {payload} = data; this.createIfNotExist(payload.appid); this.messagesForApp[payload.appid].unshift(payload); this.messages.unshift(payload); + this.updateApps(); this.emit('change'); } } + updateApps = () => { + const appToUrl = {}; + AppStore.get().forEach((app) => appToUrl[app.id] = app.image); + this.messages.forEach((msg) => msg.image = appToUrl[msg.appid]); + this.messagesForApp.forEach((forApp) => forApp.forEach((msg) => msg.image = appToUrl[msg.appid])); + }; + createIfNotExist(id) { if (!(id in this.messagesForApp)) { this.messagesForApp[id] = [];