Use room-specific listeners for message previews

This should be a bit faster (since we now only notify one tile instead of all
for each update). It also resolves the max listener warning.

Fixes https://github.com/vector-im/element-web/issues/15121
This commit is contained in:
J. Ryan Stinnett 2021-01-15 13:54:38 +00:00
parent 266162fa32
commit 729356394e
2 changed files with 26 additions and 6 deletions

View file

@ -30,7 +30,7 @@ import { UPDATE_EVENT } from "../AsyncStore";
// Emitted event for when a room's preview has changed. First argument will the room for which
// the change happened.
export const ROOM_PREVIEW_CHANGED = "room_preview_changed";
const ROOM_PREVIEW_CHANGED = "room_preview_changed";
const PREVIEWS = {
'm.room.message': {
@ -84,6 +84,10 @@ export class MessagePreviewStore extends AsyncStoreWithClient<IState> {
return MessagePreviewStore.internalInstance;
}
public static getPreviewChangedEventName(room: Room): string {
return `${ROOM_PREVIEW_CHANGED}:${room?.roomId}`;
}
/**
* Gets the pre-translated preview for a given room
* @param room The room to get the preview for.
@ -150,7 +154,7 @@ export class MessagePreviewStore extends AsyncStoreWithClient<IState> {
// We've muted the underlying Map, so just emit that we've changed.
this.previews.set(room.roomId, map);
this.emit(UPDATE_EVENT, this);
this.emit(ROOM_PREVIEW_CHANGED, room);
this.emit(MessagePreviewStore.getPreviewChangedEventName(room), room);
}
return; // we're done
}
@ -158,7 +162,7 @@ export class MessagePreviewStore extends AsyncStoreWithClient<IState> {
// At this point, we didn't generate a preview so clear it
this.previews.set(room.roomId, new Map<TagID|TAG_ANY, string|null>());
this.emit(UPDATE_EVENT, this);
this.emit(ROOM_PREVIEW_CHANGED, room);
this.emit(MessagePreviewStore.getPreviewChangedEventName(room), room);
}
protected async onAction(payload: ActionPayload) {