fix typing of MessageController

pull/1381/head
Audric Ackermann 4 years ago
parent 4c0a988fe5
commit 9fe87ca8c3
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -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<string, any>;
private readonly messageLookup: Map<string, MessageControllerEntry>;
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

Loading…
Cancel
Save