From c57d93702a1f55328a2cc0ff17753d15dbfb4270 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 19 Jun 2019 11:46:24 +0100 Subject: [PATCH 1/3] De-duplicate notif badge code We had two different places we were deciding whether to show a badge. Let's just have one. --- src/RoomNotifs.js | 12 ++++++------ src/components/views/rooms/RoomTile.js | 12 ++---------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/RoomNotifs.js b/src/RoomNotifs.js index 39384b5bea..5690817da5 100644 --- a/src/RoomNotifs.js +++ b/src/RoomNotifs.js @@ -26,12 +26,12 @@ export const MUTE = 'mute'; export const BADGE_STATES = [ALL_MESSAGES, ALL_MESSAGES_LOUD]; export const MENTION_BADGE_STATES = [...BADGE_STATES, MENTIONS_ONLY]; -function _shouldShowNotifBadge(roomNotifState) { +export function shouldShowNotifBadge(roomNotifState) { const showBadgeInStates = [ALL_MESSAGES, ALL_MESSAGES_LOUD]; return showBadgeInStates.indexOf(roomNotifState) > -1; } -function _shouldShowMentionBadge(roomNotifState) { +export function shouldShowMentionBadge(roomNotifState) { return roomNotifState !== MUTE; } @@ -41,8 +41,8 @@ export function aggregateNotificationCount(rooms) { const highlight = room.getUnreadNotificationCount('highlight') > 0; const notificationCount = room.getUnreadNotificationCount(); - const notifBadges = notificationCount > 0 && _shouldShowNotifBadge(roomNotifState); - const mentionBadges = highlight && _shouldShowMentionBadge(roomNotifState); + const notifBadges = notificationCount > 0 && shouldShowNotifBadge(roomNotifState); + const mentionBadges = highlight && shouldShowMentionBadge(roomNotifState); const badges = notifBadges || mentionBadges; if (badges) { @@ -60,8 +60,8 @@ export function getRoomHasBadge(room) { const highlight = room.getUnreadNotificationCount('highlight') > 0; const notificationCount = room.getUnreadNotificationCount(); - const notifBadges = notificationCount > 0 && _shouldShowNotifBadge(roomNotifState); - const mentionBadges = highlight && _shouldShowMentionBadge(roomNotifState); + const notifBadges = notificationCount > 0 && shouldShowNotifBadge(roomNotifState); + const mentionBadges = highlight && shouldShowMentionBadge(roomNotifState); return notifBadges || mentionBadges; } diff --git a/src/components/views/rooms/RoomTile.js b/src/components/views/rooms/RoomTile.js index e1b9567ebd..c4bd2adf2c 100644 --- a/src/components/views/rooms/RoomTile.js +++ b/src/components/views/rooms/RoomTile.js @@ -67,14 +67,6 @@ module.exports = React.createClass({ }); }, - _shouldShowNotifBadge: function() { - return RoomNotifs.BADGE_STATES.includes(this.state.notifState); - }, - - _shouldShowMentionBadge: function() { - return RoomNotifs.MENTION_BADGE_STATES.includes(this.state.notifState); - }, - _isDirectMessageRoom: function(roomId) { const dmRooms = DMRoomMap.shared().getUserIdForRoomId(roomId); return Boolean(dmRooms); @@ -301,8 +293,8 @@ module.exports = React.createClass({ const notificationCount = this.props.notificationCount; // var highlightCount = this.props.room.getUnreadNotificationCount("highlight"); - const notifBadges = notificationCount > 0 && this._shouldShowNotifBadge(); - const mentionBadges = this.props.highlight && this._shouldShowMentionBadge(); + const notifBadges = notificationCount > 0 && RoomNotifs.shouldShowNotifBadge(this.state.notifState); + const mentionBadges = this.props.highlight && RoomNotifs.shouldShowMentionBadge(this.state.notifState); const badges = notifBadges || mentionBadges; let subtext = null; From 0e6f401b62bee23bd2a60fcae014717a7b4aac08 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 19 Jun 2019 11:48:47 +0100 Subject: [PATCH 2/3] copyright --- src/RoomNotifs.js | 1 + src/components/views/rooms/RoomTile.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/RoomNotifs.js b/src/RoomNotifs.js index 5690817da5..5d3444b0f6 100644 --- a/src/RoomNotifs.js +++ b/src/RoomNotifs.js @@ -1,5 +1,6 @@ /* Copyright 2016 OpenMarket Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/components/views/rooms/RoomTile.js b/src/components/views/rooms/RoomTile.js index c4bd2adf2c..be73985d16 100644 --- a/src/components/views/rooms/RoomTile.js +++ b/src/components/views/rooms/RoomTile.js @@ -2,6 +2,7 @@ Copyright 2015, 2016 OpenMarket Ltd Copyright 2017 New Vector Ltd Copyright 2018 Michael Telatynski <7t3chguy@gmail.com> +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 23b29ce3f5bf1860f425ebd0a52a8629537b407a Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 19 Jun 2019 12:12:19 +0100 Subject: [PATCH 3/3] Use the variables we just defined above --- src/RoomNotifs.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/RoomNotifs.js b/src/RoomNotifs.js index 5d3444b0f6..f62eeeec41 100644 --- a/src/RoomNotifs.js +++ b/src/RoomNotifs.js @@ -28,12 +28,11 @@ export const BADGE_STATES = [ALL_MESSAGES, ALL_MESSAGES_LOUD]; export const MENTION_BADGE_STATES = [...BADGE_STATES, MENTIONS_ONLY]; export function shouldShowNotifBadge(roomNotifState) { - const showBadgeInStates = [ALL_MESSAGES, ALL_MESSAGES_LOUD]; - return showBadgeInStates.indexOf(roomNotifState) > -1; + return BADGE_STATES.includes(roomNotifState); } export function shouldShowMentionBadge(roomNotifState) { - return roomNotifState !== MUTE; + return MENTION_BADGE_STATES.includes(roomNotifState); } export function aggregateNotificationCount(rooms) {