From ba171f1fe5814a1b9ee88f792afaf05ce5aa507b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 16 Aug 2022 12:26:25 +0100 Subject: [PATCH] Fix soft crash around room view store metrics (#9190) * Fix soft crash around room view store metrics * Use awaitRoomDownSync utility --- src/stores/RoomViewStore.tsx | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/stores/RoomViewStore.tsx b/src/stores/RoomViewStore.tsx index ea2b7e93ad..4f0e7d5b13 100644 --- a/src/stores/RoomViewStore.tsx +++ b/src/stores/RoomViewStore.tsx @@ -24,7 +24,6 @@ import { ViewRoom as ViewRoomEvent } from "@matrix-org/analytics-events/types/ty import { JoinedRoom as JoinedRoomEvent } from "@matrix-org/analytics-events/types/typescript/JoinedRoom"; import { JoinRule } from "matrix-js-sdk/src/@types/partials"; import { Room } from "matrix-js-sdk/src/models/room"; -import { ClientEvent } from "matrix-js-sdk/src/client"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { Optional } from "matrix-events-sdk"; @@ -48,6 +47,7 @@ import { JoinRoomErrorPayload } from "../dispatcher/payloads/JoinRoomErrorPayloa import { ViewRoomErrorPayload } from "../dispatcher/payloads/ViewRoomErrorPayload"; import ErrorDialog from "../components/views/dialogs/ErrorDialog"; import { ActiveRoomChangedPayload } from "../dispatcher/payloads/ActiveRoomChangedPayload"; +import { awaitRoomDownSync } from "../utils/RoomUpgrade"; const NUM_JOIN_RETRY = 5; @@ -209,10 +209,7 @@ export class RoomViewStore extends Store { this.setState({ shouldPeek: false }); } - const cli = MatrixClientPeg.get(); - - const updateMetrics = () => { - const room = cli.getRoom(payload.roomId); + awaitRoomDownSync(MatrixClientPeg.get(), payload.roomId).then(room => { const numMembers = room.getJoinedMemberCount(); const roomSize = numMembers > 1000 ? "MoreThanAThousand" : numMembers > 100 ? "OneHundredAndOneToAThousand" @@ -228,15 +225,7 @@ export class RoomViewStore extends Store { isDM: !!DMRoomMap.shared().getUserIdForRoomId(room.roomId), isSpace: room.isSpaceRoom(), }); - - cli.off(ClientEvent.Room, updateMetrics); - }; - - if (cli.getRoom(payload.roomId)) { - updateMetrics(); - } else { - cli.on(ClientEvent.Room, updateMetrics); - } + }); break; }