From f4dc7ae8b18c0106a9dac1672c9dc393977ae2db Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 28 Mar 2017 10:38:57 +0100 Subject: [PATCH 1/2] Improve zeroing of RoomList notification badges Use an action and force an update when zeroing the number of notifications in a room. This is better than waiting for a `render` to happen at some point. This will hopefully fix https://github.com/vector-im/riot-web/issues/3257 --- src/components/structures/TimelinePanel.js | 7 ++++--- src/components/views/rooms/RoomList.js | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/structures/TimelinePanel.js b/src/components/structures/TimelinePanel.js index 8ef0e7631f..cc14bd7c02 100644 --- a/src/components/structures/TimelinePanel.js +++ b/src/components/structures/TimelinePanel.js @@ -476,9 +476,10 @@ var TimelinePanel = React.createClass({ // if we are scrolled to the bottom, do a quick-reset of our unreadNotificationCount // to avoid having to wait from the remote echo from the homeserver. if (this.isAtEndOfLiveTimeline()) { - this.props.timelineSet.room.setUnreadNotificationCount('total', 0); - this.props.timelineSet.room.setUnreadNotificationCount('highlight', 0); - // XXX: i'm a bit surprised we don't have to emit an event or dispatch to get this picked up + dis.dispatch({ + action: 'on_room_read', + room: this.props.timelineSet.room, + }); } var currentReadUpToEventId = this._getCurrentReadReceipt(true); diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index 51811f672a..1ec3c152e4 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -96,6 +96,12 @@ module.exports = React.createClass({ }); } break; + case 'on_room_read': + payload.room.setUnreadNotificationCount('total', 0); + payload.room.setUnreadNotificationCount('highlight', 0); + // Force an update because this state is too deep to cause an update + this.forceUpdate(); + break; } }, From 4a0988f83e4ae4f76dea12ac4e6555dd867bb164 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 28 Mar 2017 11:26:40 +0100 Subject: [PATCH 2/2] Do not send the room with action By not sending the room with the action, we prevent its state from being updated by registered views listening for on_room_read --- src/components/structures/TimelinePanel.js | 3 ++- src/components/views/rooms/RoomList.js | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/structures/TimelinePanel.js b/src/components/structures/TimelinePanel.js index cc14bd7c02..7fe515b958 100644 --- a/src/components/structures/TimelinePanel.js +++ b/src/components/structures/TimelinePanel.js @@ -476,9 +476,10 @@ var TimelinePanel = React.createClass({ // if we are scrolled to the bottom, do a quick-reset of our unreadNotificationCount // to avoid having to wait from the remote echo from the homeserver. if (this.isAtEndOfLiveTimeline()) { + this.props.timelineSet.room.setUnreadNotificationCount('total', 0); + this.props.timelineSet.room.setUnreadNotificationCount('highlight', 0); dis.dispatch({ action: 'on_room_read', - room: this.props.timelineSet.room, }); } diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index 1ec3c152e4..59346d5f4d 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -97,9 +97,9 @@ module.exports = React.createClass({ } break; case 'on_room_read': - payload.room.setUnreadNotificationCount('total', 0); - payload.room.setUnreadNotificationCount('highlight', 0); - // Force an update because this state is too deep to cause an update + // Force an update because the notif count state is too deep to cause + // an update. This forces the local echo of reading notifs to be + // reflected by the RoomTiles. this.forceUpdate(); break; }