Fix wrongly asserting that PushRule::conditions is non-null (#7973)
This commit is contained in:
parent
b80ea34805
commit
15cbc6c26c
3 changed files with 91 additions and 19 deletions
|
@ -61,17 +61,6 @@ export function aggregateNotificationCount(rooms: Room[]): {count: number, highl
|
|||
}, { count: 0, highlight: false });
|
||||
}
|
||||
|
||||
export function getRoomHasBadge(room: Room): boolean {
|
||||
const roomNotifState = getRoomNotifsState(room.roomId);
|
||||
const highlight = room.getUnreadNotificationCount(NotificationCountType.Highlight) > 0;
|
||||
const notificationCount = room.getUnreadNotificationCount();
|
||||
|
||||
const notifBadges = notificationCount > 0 && shouldShowNotifBadge(roomNotifState);
|
||||
const mentionBadges = highlight && shouldShowMentionBadge(roomNotifState);
|
||||
|
||||
return notifBadges || mentionBadges;
|
||||
}
|
||||
|
||||
export function getRoomNotifsState(roomId: string): RoomNotifState {
|
||||
if (MatrixClientPeg.get().isGuest()) return RoomNotifState.AllMessages;
|
||||
|
||||
|
@ -88,14 +77,14 @@ export function getRoomNotifsState(roomId: string): RoomNotifState {
|
|||
roomRule = MatrixClientPeg.get().getRoomPushRule('global', roomId);
|
||||
} catch (err) {
|
||||
// Possible that the client doesn't have pushRules yet. If so, it
|
||||
// hasn't started eiher, so indicate that this room is not notifying.
|
||||
// hasn't started either, so indicate that this room is not notifying.
|
||||
return null;
|
||||
}
|
||||
|
||||
// XXX: We have to assume the default is to notify for all messages
|
||||
// (in particular this will be 'wrong' for one to one rooms because
|
||||
// they will notify loudly for all messages)
|
||||
if (!roomRule || !roomRule.enabled) return RoomNotifState.AllMessages;
|
||||
if (!roomRule?.enabled) return RoomNotifState.AllMessages;
|
||||
|
||||
// a mute at the room level will still allow mentions
|
||||
// to notify
|
||||
|
@ -213,17 +202,15 @@ function findOverrideMuteRule(roomId: string): IPushRule {
|
|||
return null;
|
||||
}
|
||||
for (const rule of cli.pushRules.global.override) {
|
||||
if (isRuleForRoom(roomId, rule)) {
|
||||
if (isMuteRule(rule) && rule.enabled) {
|
||||
return rule;
|
||||
}
|
||||
if (rule.enabled && isRuleForRoom(roomId, rule) && isMuteRule(rule)) {
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isRuleForRoom(roomId: string, rule: IPushRule): boolean {
|
||||
if (rule.conditions.length !== 1) {
|
||||
if (rule.conditions?.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
const cond = rule.conditions[0];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue