From d3dff302c545f8251cd6d6876e361f9fc7bd5fde Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Tue, 26 Apr 2022 23:20:28 +0300 Subject: [PATCH] frontend: prevent accessing stores of channels that have not been loaded yet --- frontend/src/stores.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/src/stores.js b/frontend/src/stores.js index 7372201..d97feec 100644 --- a/frontend/src/stores.js +++ b/frontend/src/stores.js @@ -205,16 +205,27 @@ class MessagesStoreProvider { // we currently don't care about our own messages if (gateway.user && message.author_id === gateway.user.id) return; - this.getStore(message.channel_id).addMessage(message); + + const store = this.getStoreOrNull(message.channel_id); + if (store) + store.addMessage(message); }); gateway.subscribe(GatewayEventType.MessageUpdate, (message) => { - this.getStore(message.channel_id).updateMessage(message); + const store = this.getStoreOrNull(message.channel_id); + if (store) + store.updateMessage(message); }); gateway.subscribe(GatewayEventType.MessageDelete, (message) => { - this.getStore(message.channel_id).deleteMessage(message); + const store = this.getStoreOrNull(message.channel_id); + if (store) + store.deleteMessage(message); }); } + getStoreOrNull(channelId) { + return this.storeByChannel.get(channelId); + } + getStore(channelId) { if (!this.storeByChannel.get(channelId)) { const store = new MessageStore(channelId);