Fix soft crash around room view store metrics (#9190)

* Fix soft crash around room view store metrics

* Use awaitRoomDownSync utility
pull/28217/head
Michael Telatynski 2022-08-16 12:26:25 +01:00 committed by GitHub
parent 05e179f856
commit ba171f1fe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 14 deletions

View File

@ -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<ActionPayload> {
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<ActionPayload> {
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;
}