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

Commit

Permalink
Move hideSender logic into state so it causes re-render (#7413)
Browse files Browse the repository at this point in the history
* Move hideSender logic into state so it causes re-render

* change method signature
  • Loading branch information
t3chguy committed Dec 23, 2021
1 parent fb74f9a commit 13028d3
Showing 1 changed file with 10 additions and 4 deletions.
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.shouldHideSender(),
};

// 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 shouldHideSender(): boolean {
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.shouldHideSender(),
});
};

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

0 comments on commit 13028d3

Please sign in to comment.