diff --git a/src/app/pages/client/BackgroundNotifications.tsx b/src/app/pages/client/BackgroundNotifications.tsx index 1109a9cc..9ca53b5c 100644 --- a/src/app/pages/client/BackgroundNotifications.tsx +++ b/src/app/pages/client/BackgroundNotifications.tsx @@ -297,8 +297,7 @@ export function BackgroundNotifications() { return; } - const userId = mx.getUserId(); - if (!isNotificationEvent(mEvent, room, userId)) { + if (!isNotificationEvent(mEvent)) { return; } diff --git a/src/app/state/room/roomToUnread.ts b/src/app/state/room/roomToUnread.ts index ff57a4d7..e70271d2 100644 --- a/src/app/state/room/roomToUnread.ts +++ b/src/app/state/room/roomToUnread.ts @@ -230,7 +230,7 @@ export const useBindRoomToUnreadAtom = (mx: MatrixClient, unreadAtom: typeof roo } // Handle live events (new messages arriving in real-time) - if (data.liveEvent && isNotificationEvent(mEvent, room, mx.getUserId())) { + if (data.liveEvent && isNotificationEvent(mEvent)) { if (mEvent.getSender() === mx.getUserId()) return; const unreadInfo = getUnreadInfo(room, { applyFixup: shouldApplyUnreadFixup(), mDirects }); setUnreadAtom({ diff --git a/src/app/utils/room.ts b/src/app/utils/room.ts index 9f588caa..21fa6e29 100644 --- a/src/app/utils/room.ts +++ b/src/app/utils/room.ts @@ -224,10 +224,10 @@ export const isNotificationEvent = (mEvent: MatrixEvent, room?: Room, userId?: s if (mEvent.isRedacted()) return false; const relation = mEvent.getRelation(); const relationType = relation?.rel_type; - + // Filter out edits - they shouldn't count as new notifications if (relationType === 'm.replace') return false; - + // For reactions: only count them if they're reactions to the current user's messages if (relationType === 'm.annotation') { if (!room || !userId || !relation) { @@ -237,12 +237,12 @@ export const isNotificationEvent = (mEvent: MatrixEvent, room?: Room, userId?: s // Get the event being reacted to const reactedToEventId = relation.event_id; if (!reactedToEventId) return false; - + const reactedToEvent = room.findEventById(reactedToEventId); // Only count as notification if the reacted-to message was sent by current user return reactedToEvent?.getSender() === userId; } - + return true; }; @@ -319,7 +319,9 @@ export const getUnreadInfo = (room: Room, options?: UnreadInfoOptions): UnreadIn .reverse() .find( (event) => - !event.isSending() && event.getSender() !== userId && isNotificationEvent(event, room, userId) + !event.isSending() && + event.getSender() !== userId && + isNotificationEvent(event, room, userId) ); const latestNotificationId = latestNotification?.getId(); if (latestNotificationId && room.hasUserReadEvent(userId, latestNotificationId)) {