Prefer RoomStateEvent.Update where possible as it fires far less (#7878)
This commit is contained in:
parent
36ae0ea49d
commit
c257bc3f7a
40 changed files with 223 additions and 190 deletions
|
@ -23,7 +23,6 @@ import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
|||
import { Relations } from "matrix-js-sdk/src/models/relations";
|
||||
import { logger } from 'matrix-js-sdk/src/logger';
|
||||
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
||||
import { throttle } from "lodash";
|
||||
|
||||
import shouldHideEvent from '../../shouldHideEvent';
|
||||
import { wantsDateSeparator } from '../../DateUtils';
|
||||
|
@ -277,13 +276,13 @@ export default class MessagePanel extends React.Component<IProps, IState> {
|
|||
|
||||
componentDidMount() {
|
||||
this.calculateRoomMembersCount();
|
||||
this.props.room?.currentState.on(RoomStateEvent.Members, this.onRoomMembers);
|
||||
this.props.room?.currentState.on(RoomStateEvent.Update, this.calculateRoomMembersCount);
|
||||
this.isMounted = true;
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.isMounted = false;
|
||||
this.props.room?.currentState.off(RoomStateEvent.Members, this.onRoomMembers);
|
||||
this.props.room?.currentState.off(RoomStateEvent.Update, this.calculateRoomMembersCount);
|
||||
SettingsStore.unwatchSetting(this.showTypingNotificationsWatcherRef);
|
||||
}
|
||||
|
||||
|
@ -314,16 +313,11 @@ export default class MessagePanel extends React.Component<IProps, IState> {
|
|||
return this.props.room?.getInvitedAndJoinedMemberCount() <= 2 && this.props.layout === Layout.Bubble;
|
||||
}
|
||||
|
||||
private onRoomMembers = (event: MatrixEvent): void => {
|
||||
if (this.props.room && event.getRoomId() !== this.props.room.roomId) return; // different room
|
||||
this.calculateRoomMembersCount();
|
||||
};
|
||||
|
||||
private calculateRoomMembersCount = throttle((): void => {
|
||||
private calculateRoomMembersCount = (): void => {
|
||||
this.setState({
|
||||
hideSender: this.shouldHideSender(),
|
||||
});
|
||||
}, 200, { leading: true, trailing: true });
|
||||
};
|
||||
|
||||
private onShowTypingNotificationsChange = (): void => {
|
||||
this.setState({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue