frontend: prevent accessing stores of channels that have not been loaded yet

This commit is contained in:
hippoz 2022-04-26 23:20:28 +03:00
parent 66bdd7e06f
commit d3dff302c5
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

@ -205,16 +205,27 @@ class MessagesStoreProvider {
// we currently don't care about our own messages // we currently don't care about our own messages
if (gateway.user && message.author_id === gateway.user.id) if (gateway.user && message.author_id === gateway.user.id)
return; 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) => { 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) => { 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) { getStore(channelId) {
if (!this.storeByChannel.get(channelId)) { if (!this.storeByChannel.get(channelId)) {
const store = new MessageStore(channelId); const store = new MessageStore(channelId);