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

Move hideSender logic into state so it causes re-render #7413

Merged
merged 5 commits into from
Dec 23, 2021
Merged
Changes from 1 commit
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
14 changes: 10 additions & 4 deletions src/components/structures/MessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ interface IProps {
interface IState {
ghostReadMarkers: string[];
showTypingNotifications: boolean;
hideSender: boolean;
}

interface IReadReceiptForUser {
Expand Down Expand Up @@ -254,8 +255,6 @@ 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 @@ -264,6 +263,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
// display 'ghost' read markers that are animating away
ghostReadMarkers: [],
showTypingNotifications: SettingsStore.getValue("showTypingNotifications"),
hideSender: this.hideSender,
};

// Cache hidden events setting on mount since Settings is expensive to
Expand Down Expand Up @@ -306,8 +306,14 @@ export default class MessagePanel extends React.Component<IProps, IState> {
}
}

private get hideSender(): boolean {
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
return this.props.room?.getInvitedAndJoinedMemberCount() <= 2 && this.props.layout === Layout.Bubble;
}

private calculateRoomMembersCount = (): void => {
this.membersCount = this.props.room?.getMembers().length || 0;
this.setState({
hideSender: this.hideSender,
});
};

private onShowTypingNotificationsChange = (): void => {
Expand Down Expand Up @@ -794,7 +800,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
enableFlair={this.props.enableFlair}
showReadReceipts={this.props.showReadReceipts}
callEventGrouper={callEventGrouper}
hideSender={this.membersCount <= 2 && this.props.layout === Layout.Bubble}
hideSender={this.state.hideSender}
timelineRenderingType={this.context.timelineRenderingType}
/>
</TileErrorBoundary>,
Expand Down