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

Use cached value to read member count #6429

Merged
merged 3 commits into from
Jul 21, 2021
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
12 changes: 10 additions & 2 deletions src/components/structures/MessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ export default class MessagePanel extends React.Component<IProps, IState> {
// A map of <callId, CallEventGrouper>
private callEventGroupers = new Map<string, CallEventGrouper>();

private membersCount = 0;

constructor(props, context) {
super(props, context);

Expand All @@ -256,11 +258,14 @@ export default class MessagePanel extends React.Component<IProps, IState> {
}

componentDidMount() {
this.calculateRoomMembersCount();
this.props.room?.on("RoomState.members", this.calculateRoomMembersCount);
this.isMounted = true;
}

componentWillUnmount() {
this.isMounted = false;
this.props.room?.off("RoomState.members", this.calculateRoomMembersCount);
SettingsStore.unwatchSetting(this.showTypingNotificationsWatcherRef);
}

Expand All @@ -274,6 +279,10 @@ export default class MessagePanel extends React.Component<IProps, IState> {
}
}

private calculateRoomMembersCount = (): void => {
this.membersCount = this.props.room?.getMembers().length || 0;
};
Comment on lines +282 to +284
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't setState so will have a very jarring update behaviour, it'll take effect the render after this fires, weirdly laggy. I don't think this is the right solution and think it does not whatsoever match what I accepted in review. @gsouquet


private onShowTypingNotificationsChange = (): void => {
this.setState({
showTypingNotifications: SettingsStore.getValue("showTypingNotifications"),
Expand Down Expand Up @@ -711,7 +720,6 @@ export default class MessagePanel extends React.Component<IProps, IState> {
isLastSuccessful = isLastSuccessful && mxEv.getSender() === MatrixClientPeg.get().getUserId();

const callEventGrouper = this.callEventGroupers.get(mxEv.getContent().call_id);

// use txnId as key if available so that we don't remount during sending
ret.push(
<TileErrorBoundary key={mxEv.getTxnId() || eventId} mxEvent={mxEv}>
Expand Down Expand Up @@ -743,7 +751,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
enableFlair={this.props.enableFlair}
showReadReceipts={this.props.showReadReceipts}
callEventGrouper={callEventGrouper}
hideSender={this.props.room?.getMembers().length <= 2 && this.props.layout === Layout.Bubble}
hideSender={this.membersCount <= 2 && this.props.layout === Layout.Bubble}
/>
</TileErrorBoundary>,
);
Expand Down