From b9f80b49ad9742f34dcbe09a9273c3b2057523a2 Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Thu, 15 Apr 2021 16:33:49 +0100 Subject: [PATCH] Set correct initial state for notification on room --- src/components/views/rooms/RoomTile.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/views/rooms/RoomTile.tsx b/src/components/views/rooms/RoomTile.tsx index ad923138df..b2a07d7e06 100644 --- a/src/components/views/rooms/RoomTile.tsx +++ b/src/components/views/rooms/RoomTile.tsx @@ -97,6 +97,8 @@ export default class RoomTile extends React.PureComponent { // generatePreview() will return nothing if the user has previews disabled messagePreview: this.generatePreview(), }; + this.notificationState = RoomNotificationStateStore.instance.getRoomState(this.props.room); + this.roomProps = EchoChamber.forRoom(this.props.room); } private onRoomNameUpdate = (room) => { @@ -158,9 +160,7 @@ export default class RoomTile extends React.PureComponent { MessagePreviewStore.getPreviewChangedEventName(this.props.room), this.onRoomPreviewChanged, ); - this.notificationState = RoomNotificationStateStore.instance.getRoomState(this.props.room); this.notificationState.on(NOTIFICATION_STATE_UPDATE, this.onNotificationUpdate); - this.roomProps = EchoChamber.forRoom(this.props.room); this.roomProps.on(PROPERTY_UPDATED, this.onRoomPropertyUpdate); this.roomProps.on("Room.name", this.onRoomNameUpdate); CommunityPrototypeStore.instance.on( @@ -378,7 +378,7 @@ export default class RoomTile extends React.PureComponent { return null; } - const state = this.roomProps?.notificationVolume; + const state = this.roomProps.notificationVolume; let contextMenu = null; if (this.state.notificationsMenuPosition) { @@ -583,7 +583,7 @@ export default class RoomTile extends React.PureComponent { const nameClasses = classNames({ "mx_RoomTile_name": true, "mx_RoomTile_nameWithPreview": !!messagePreview, - "mx_RoomTile_nameHasUnreadEvents": this.notificationState?.isUnread, + "mx_RoomTile_nameHasUnreadEvents": this.notificationState.isUnread, }); let nameContainer = ( @@ -600,15 +600,15 @@ export default class RoomTile extends React.PureComponent { // The following labels are written in such a fashion to increase screen reader efficiency (speed). if (this.props.tag === DefaultTagID.Invite) { // append nothing - } else if (this.notificationState?.hasMentions) { + } else if (this.notificationState.hasMentions) { ariaLabel += " " + _t("%(count)s unread messages including mentions.", { count: this.notificationState.count, }); - } else if (this.notificationState?.hasUnreadCount) { + } else if (this.notificationState.hasUnreadCount) { ariaLabel += " " + _t("%(count)s unread messages.", { count: this.notificationState.count, }); - } else if (this.notificationState?.isUnread) { + } else if (this.notificationState.isUnread) { ariaLabel += " " + _t("Unread messages."); }