mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 17:11:17 -08:00
Fix muted rooms notifs (#750)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description <!-- Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change. --> Fixes muted rooms showing normal notification bubbles. #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. -->
This commit is contained in:
2 files changed
+28
-12
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Fix muted rooms appearing as standard unread rooms.
|
||||
+23
-12
@@ -15,12 +15,12 @@ import type {
|
||||
StateEvents,
|
||||
} from '$types/matrix-sdk';
|
||||
import {
|
||||
ConditionKind,
|
||||
EventTimeline,
|
||||
EventType,
|
||||
JoinRule,
|
||||
NotificationCountType,
|
||||
PushProcessor,
|
||||
PushRuleActionName,
|
||||
RelationType,
|
||||
MsgType,
|
||||
KnownMembership,
|
||||
@@ -178,15 +178,25 @@ export const getOrphanParents = (roomToParents: RoomToParents, roomId: string):
|
||||
return Array.from(parents).filter((parentRoomId) => !roomToParents.has(parentRoomId));
|
||||
};
|
||||
|
||||
export const isMutedRule = (rule: IPushRule) =>
|
||||
// Check for empty actions (new spec) or dont_notify (deprecated)
|
||||
(rule.actions.length === 0 || (rule.actions[0] as unknown as string) === 'dont_notify') &&
|
||||
rule.conditions?.[0]?.kind === ConditionKind.EventMatch;
|
||||
const hasNotifyPushAction = (actions: IPushRule['actions']): boolean =>
|
||||
actions.some((a) => typeof a === 'string' && a === PushRuleActionName.Notify);
|
||||
|
||||
export const findMutedRule = (overrideRules: IPushRule[], roomId: string) =>
|
||||
overrideRules.find((rule) => rule.rule_id === roomId && isMutedRule(rule));
|
||||
const findRoomMuteOverrideRule = (
|
||||
overrideRules: IPushRule[] | undefined,
|
||||
roomId: string
|
||||
): IPushRule | undefined =>
|
||||
overrideRules?.find(
|
||||
(rule) =>
|
||||
rule.rule_id === roomId && rule.rule_id.startsWith('!') && !hasNotifyPushAction(rule.actions)
|
||||
);
|
||||
|
||||
export const getNotificationType = (mx: MatrixClient, roomId: string): NotificationType => {
|
||||
const overrideRules = mx.getAccountData(EventType.PushRules)?.getContent<IPushRules>()
|
||||
?.global?.override;
|
||||
if (findRoomMuteOverrideRule(overrideRules, roomId)) {
|
||||
return NotificationType.Mute;
|
||||
}
|
||||
|
||||
let roomPushRule: IPushRule | undefined;
|
||||
try {
|
||||
roomPushRule = mx.getRoomPushRule('global', roomId);
|
||||
@@ -195,11 +205,7 @@ export const getNotificationType = (mx: MatrixClient, roomId: string): Notificat
|
||||
}
|
||||
|
||||
if (!roomPushRule) {
|
||||
const overrideRules = mx.getAccountData(EventType.PushRules)?.getContent<IPushRules>()
|
||||
?.global?.override;
|
||||
if (!overrideRules) return NotificationType.Default;
|
||||
|
||||
return findMutedRule(overrideRules, roomId) ? NotificationType.Mute : NotificationType.Default;
|
||||
return NotificationType.Default;
|
||||
}
|
||||
|
||||
if ((roomPushRule.actions[0] as string) === 'notify') return NotificationType.AllMessages;
|
||||
@@ -254,6 +260,7 @@ export const roomHaveNotification = (room: Room): boolean => {
|
||||
};
|
||||
|
||||
export const roomHaveUnread = (mx: MatrixClient, room: Room) => {
|
||||
if (getNotificationType(mx, room.roomId) === NotificationType.Mute) return false;
|
||||
const userId = mx.getUserId();
|
||||
if (!userId) return false;
|
||||
const readUpToId = room.getEventReadUpTo(userId);
|
||||
@@ -290,6 +297,10 @@ type UnreadInfoOptions = {
|
||||
const unreadInfoFixupInProgress = new WeakSet<Room>();
|
||||
|
||||
export const getUnreadInfo = (room: Room, options?: UnreadInfoOptions): UnreadInfo => {
|
||||
if (getNotificationType(room.client, room.roomId) === NotificationType.Mute) {
|
||||
return { roomId: room.roomId, highlight: 0, total: 0 };
|
||||
}
|
||||
|
||||
const userId = room.client.getUserId();
|
||||
if (userId && options?.applyFixup && !unreadInfoFixupInProgress.has(room)) {
|
||||
unreadInfoFixupInProgress.add(room);
|
||||
|
||||
Reference in new issue
Block a user