Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix soft crash around room view store metrics #9190

Merged
merged 2 commits into from
Aug 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions src/stores/RoomViewStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;

Expand Down Expand Up @@ -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"
Expand All @@ -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;
}
Expand Down