From dd42e87c3cb37ad5ef495048f32261eb4e1b14d1 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 3 Jun 2019 00:07:32 -0600 Subject: [PATCH] Add local echo on badges in breadcrumbs Fixes https://github.com/vector-im/riot-web/issues/9890 --- src/components/views/rooms/RoomBreadcrumbs.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/views/rooms/RoomBreadcrumbs.js b/src/components/views/rooms/RoomBreadcrumbs.js index 3e874c172e..107fbb49a5 100644 --- a/src/components/views/rooms/RoomBreadcrumbs.js +++ b/src/components/views/rooms/RoomBreadcrumbs.js @@ -96,6 +96,13 @@ export default class RoomBreadcrumbs extends React.Component { case 'view_room': this._appendRoomId(payload.room_id); break; + + // XXX: slight hack in order to zero the notification count when a room + // is read. Copied from RoomTile + case 'on_room_read': + const room = MatrixClientPeg.get().getRoom(payload.roomId); + this._calculateRoomBadges(room, /*zero=*/true); + break; } } @@ -164,7 +171,7 @@ export default class RoomBreadcrumbs extends React.Component { }); } - _calculateBadgesForRoom(room) { + _calculateBadgesForRoom(room, zero=false) { if (!room) return null; // Reset the notification variables for simplicity @@ -174,6 +181,8 @@ export default class RoomBreadcrumbs extends React.Component { showCount: false, }; + if (zero) return roomModel; + const notifState = RoomNotifs.getRoomNotifsState(room.roomId); if (RoomNotifs.MENTION_BADGE_STATES.includes(notifState)) { const highlightNotifs = RoomNotifs.getUnreadNotificationCount(room, 'highlight'); @@ -195,14 +204,14 @@ export default class RoomBreadcrumbs extends React.Component { return roomModel; } - _calculateRoomBadges(room) { + _calculateRoomBadges(room, zero=false) { if (!room) return; const rooms = this.state.rooms.slice(); const roomModel = rooms.find((r) => r.room.roomId === room.roomId); if (!roomModel) return; // No applicable room, so don't do math on it - const badges = this._calculateBadgesForRoom(room); + const badges = this._calculateBadgesForRoom(room, zero); if (!badges) return; // No badges for some reason Object.assign(roomModel, badges);