From 9fe87ca8c320103a50f854cfce94f4033e0e0c11 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 2 Dec 2020 16:23:58 +1100 Subject: [PATCH] fix typing of MessageController --- ts/session/messages/MessageController.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ts/session/messages/MessageController.ts b/ts/session/messages/MessageController.ts index 994bfcdb6..18a21d109 100644 --- a/ts/session/messages/MessageController.ts +++ b/ts/session/messages/MessageController.ts @@ -1,9 +1,17 @@ // You can see MessageController for in memory registered messages. // Ee register messages to it everytime we send one, so that when an event happens we can find which message it was based on this id. + +import { MessageModel } from '../../../js/models/messages'; + +type MessageControllerEntry = { + message: MessageModel; + timestamp: number; +}; + // It's not only data from the db which is stored on the MessageController entries, we could fetch this again. What we cannot fetch from the db and which is stored here is all listeners a particular messages is linked to for instance. We will be able to get rid of this once we don't use backbone models at all export class MessageController { private static instance: MessageController | null; - private readonly messageLookup: Map; + private readonly messageLookup: Map; private constructor() { this.messageLookup = new Map(); @@ -19,7 +27,7 @@ export class MessageController { return MessageController.instance; } - public register(id: string, message: any) { + public register(id: string, message: MessageModel) { const existing = this.messageLookup.get(id); if (existing) { this.messageLookup.set(id, { @@ -43,12 +51,10 @@ export class MessageController { public cleanup() { window.log.warn('Cleaning up getMessageController() oldest messages...'); - const messages = Object.values(this.messageLookup); const now = Date.now(); - // tslint:disable-next-line: one-variable-per-declaration - for (let i = 0, max = messages.length; i < max; i += 1) { - const { message, timestamp } = messages[i]; + this.messageLookup.forEach(messageEntry => { + const { message, timestamp } = messageEntry; const conversation = message.getConversation(); if ( @@ -57,7 +63,7 @@ export class MessageController { ) { this.unregister(message.id); } - } + }); } // tslint:disable-next-line: function-name