Merge pull request #3120 from matrix-org/dbkr/badges_remove_dupe_code
De-duplicate notif badge code
This commit is contained in:
commit
86081c3c8f
2 changed files with 12 additions and 19 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2016 OpenMarket Ltd
|
Copyright 2016 OpenMarket Ltd
|
||||||
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -26,13 +27,12 @@ export const MUTE = 'mute';
|
||||||
export const BADGE_STATES = [ALL_MESSAGES, ALL_MESSAGES_LOUD];
|
export const BADGE_STATES = [ALL_MESSAGES, ALL_MESSAGES_LOUD];
|
||||||
export const MENTION_BADGE_STATES = [...BADGE_STATES, MENTIONS_ONLY];
|
export const MENTION_BADGE_STATES = [...BADGE_STATES, MENTIONS_ONLY];
|
||||||
|
|
||||||
function _shouldShowNotifBadge(roomNotifState) {
|
export function shouldShowNotifBadge(roomNotifState) {
|
||||||
const showBadgeInStates = [ALL_MESSAGES, ALL_MESSAGES_LOUD];
|
return BADGE_STATES.includes(roomNotifState);
|
||||||
return showBadgeInStates.indexOf(roomNotifState) > -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _shouldShowMentionBadge(roomNotifState) {
|
export function shouldShowMentionBadge(roomNotifState) {
|
||||||
return roomNotifState !== MUTE;
|
return MENTION_BADGE_STATES.includes(roomNotifState);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function countRoomsWithNotif(rooms) {
|
export function countRoomsWithNotif(rooms) {
|
||||||
|
@ -62,8 +62,8 @@ export function aggregateNotificationCount(rooms) {
|
||||||
const highlight = room.getUnreadNotificationCount('highlight') > 0;
|
const highlight = room.getUnreadNotificationCount('highlight') > 0;
|
||||||
const notificationCount = room.getUnreadNotificationCount();
|
const notificationCount = room.getUnreadNotificationCount();
|
||||||
|
|
||||||
const notifBadges = notificationCount > 0 && _shouldShowNotifBadge(roomNotifState);
|
const notifBadges = notificationCount > 0 && shouldShowNotifBadge(roomNotifState);
|
||||||
const mentionBadges = highlight && _shouldShowMentionBadge(roomNotifState);
|
const mentionBadges = highlight && shouldShowMentionBadge(roomNotifState);
|
||||||
const badges = notifBadges || mentionBadges;
|
const badges = notifBadges || mentionBadges;
|
||||||
|
|
||||||
if (badges) {
|
if (badges) {
|
||||||
|
@ -81,8 +81,8 @@ export function getRoomHasBadge(room) {
|
||||||
const highlight = room.getUnreadNotificationCount('highlight') > 0;
|
const highlight = room.getUnreadNotificationCount('highlight') > 0;
|
||||||
const notificationCount = room.getUnreadNotificationCount();
|
const notificationCount = room.getUnreadNotificationCount();
|
||||||
|
|
||||||
const notifBadges = notificationCount > 0 && _shouldShowNotifBadge(roomNotifState);
|
const notifBadges = notificationCount > 0 && shouldShowNotifBadge(roomNotifState);
|
||||||
const mentionBadges = highlight && _shouldShowMentionBadge(roomNotifState);
|
const mentionBadges = highlight && shouldShowMentionBadge(roomNotifState);
|
||||||
|
|
||||||
return notifBadges || mentionBadges;
|
return notifBadges || mentionBadges;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
Copyright 2015, 2016 OpenMarket Ltd
|
||||||
Copyright 2017 New Vector Ltd
|
Copyright 2017 New Vector Ltd
|
||||||
Copyright 2018 Michael Telatynski <7t3chguy@gmail.com>
|
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");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -67,14 +68,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) {
|
_isDirectMessageRoom: function(roomId) {
|
||||||
const dmRooms = DMRoomMap.shared().getUserIdForRoomId(roomId);
|
const dmRooms = DMRoomMap.shared().getUserIdForRoomId(roomId);
|
||||||
return Boolean(dmRooms);
|
return Boolean(dmRooms);
|
||||||
|
@ -301,8 +294,8 @@ module.exports = React.createClass({
|
||||||
const notificationCount = this.props.notificationCount;
|
const notificationCount = this.props.notificationCount;
|
||||||
// var highlightCount = this.props.room.getUnreadNotificationCount("highlight");
|
// var highlightCount = this.props.room.getUnreadNotificationCount("highlight");
|
||||||
|
|
||||||
const notifBadges = notificationCount > 0 && this._shouldShowNotifBadge();
|
const notifBadges = notificationCount > 0 && RoomNotifs.shouldShowNotifBadge(this.state.notifState);
|
||||||
const mentionBadges = this.props.highlight && this._shouldShowMentionBadge();
|
const mentionBadges = this.props.highlight && RoomNotifs.shouldShowMentionBadge(this.state.notifState);
|
||||||
const badges = notifBadges || mentionBadges;
|
const badges = notifBadges || mentionBadges;
|
||||||
|
|
||||||
let subtext = null;
|
let subtext = null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue