@@ -214,15 +214,36 @@ const NOTIFICATION_EVENT_TYPES = [
214214 'm.sticker' ,
215215 'm.reaction' ,
216216] ;
217- export const isNotificationEvent = ( mEvent : MatrixEvent ) => {
217+ export const isNotificationEvent = ( mEvent : MatrixEvent , room ?: Room , userId ?: string ) => {
218218 const eType = mEvent . getType ( ) ;
219219 if ( ! NOTIFICATION_EVENT_TYPES . includes ( eType ) ) {
220220 return false ;
221221 }
222222 if ( eType === 'm.room.member' ) return false ;
223223
224224 if ( mEvent . isRedacted ( ) ) return false ;
225- return mEvent . getRelation ( ) ?. rel_type !== 'm.replace' ;
225+ const relation = mEvent . getRelation ( ) ;
226+ const relationType = relation ?. rel_type ;
227+
228+ // Filter out edits - they shouldn't count as new notifications
229+ if ( relationType === 'm.replace' ) return false ;
230+
231+ // For reactions: only count them if they're reactions to the current user's messages
232+ if ( relationType === 'm.annotation' ) {
233+ if ( ! room || ! userId || ! relation ) {
234+ // If we don't have room/userId/relation context, filter out all reactions (safe default)
235+ return false ;
236+ }
237+ // Get the event being reacted to
238+ const reactedToEventId = relation . event_id ;
239+ if ( ! reactedToEventId ) return false ;
240+
241+ const reactedToEvent = room . findEventById ( reactedToEventId ) ;
242+ // Only count as notification if the reacted-to message was sent by current user
243+ return reactedToEvent ?. getSender ( ) === userId ;
244+ }
245+
246+ return true ;
226247} ;
227248
228249export const roomHaveNotification = ( room : Room ) : boolean => {
@@ -254,7 +275,7 @@ export const roomHaveUnread = (mx: MatrixClient, room: Room) => {
254275 if ( event . getId ( ) === readUpToId ) {
255276 return false ;
256277 }
257- if ( isNotificationEvent ( event ) ) {
278+ if ( isNotificationEvent ( event , room , userId ) ) {
258279 return true ;
259280 }
260281 }
@@ -298,7 +319,9 @@ export const getUnreadInfo = (room: Room, options?: UnreadInfoOptions): UnreadIn
298319 . reverse ( )
299320 . find (
300321 ( event ) =>
301- ! event . isSending ( ) && event . getSender ( ) !== userId && isNotificationEvent ( event )
322+ ! event . isSending ( ) &&
323+ event . getSender ( ) !== userId &&
324+ isNotificationEvent ( event , room , userId )
302325 ) ;
303326 const latestNotificationId = latestNotification ?. getId ( ) ;
304327 if ( latestNotificationId && room . hasUserReadEvent ( userId , latestNotificationId ) ) {
@@ -321,7 +344,7 @@ export const getUnreadInfo = (room: Room, options?: UnreadInfoOptions): UnreadIn
321344 const event = liveEvents [ i ] ;
322345 if ( ! event ) break ;
323346 if ( event . getId ( ) === readUpToId ) break ;
324- if ( isNotificationEvent ( event ) && event . getSender ( ) !== userId ) {
347+ if ( isNotificationEvent ( event , room , userId ) && event . getSender ( ) !== userId ) {
325348 fallbackTotal += 1 ;
326349 const pushActions = pushProcessor . actionsForEvent ( event ) ;
327350 if ( pushActions ?. tweaks ?. highlight ) fallbackHighlight += 1 ;
@@ -343,7 +366,7 @@ export const getUnreadInfo = (room: Room, options?: UnreadInfoOptions): UnreadIn
343366 const liveEvents = room . getLiveTimeline ( ) . getEvents ( ) ;
344367
345368 const hasActivity = liveEvents . some (
346- ( event ) => event . getSender ( ) !== userId && isNotificationEvent ( event )
369+ ( event ) => event . getSender ( ) !== userId && isNotificationEvent ( event , room , userId )
347370 ) ;
348371
349372 if ( hasActivity ) {
0 commit comments