Skip to content

feat: use SDK thread notification APIs for improved notification handling #124

@Just-Insane

Description

@Just-Insane

Feature Request

Summary

The matrix-js-sdk provides dedicated thread-specific notification APIs that should be used to properly separate thread notifications from main timeline notifications. Currently, the thread implementation tracks unread status by comparing read receipts, but doesn't leverage the SDK's built-in notification counting.

Available SDK APIs

The matrix-js-sdk Room class provides several thread-specific notification methods:

  • room.getThreadUnreadNotificationCount(threadId?: string, type?: NotificationCountType) - Get unread notification count for a specific thread or all threads
  • room.hasThreadUnreadNotification(threadId?: string) - Check if thread has unread notifications
  • room.threadsAggregateNotificationType - Property indicating the aggregate notification type across all threads

These methods properly handle:

  • Distinction between mentions/highlights vs regular messages
  • Aggregate counts across all threads
  • Per-thread notification states
  • Integration with Matrix's notification rules

Current Implementation

The current thread implementation (PR #123) uses:

const readUpToId = thread.getEventReadUpTo(userId, false);
if (!readUpToId || readUpToId !== lastEventId) {
  unreadCount += 1;
}

This works for basic unread tracking but doesn't:

  • Distinguish between notification types (highlight vs regular)
  • Respect user notification preferences
  • Integrate with Matrix notification rules
  • Handle muted threads

Proposed Enhancement

  1. Replace read receipt comparison with room.getThreadUnreadNotificationCount() for badge counts
  2. Use room.hasThreadUnreadNotification() to determine badge visibility
  3. Consider room.threadsAggregateNotificationType for badge styling (red for mentions, gray for regular)
  4. Add support for per-thread notification muting using SDK methods

Benefits

  • More accurate notification counts respecting Matrix notification rules
  • Better UX with highlight distinction (mentions/keywords)
  • Consistency with how other Matrix clients handle thread notifications
  • Foundation for future features like per-thread notification settings

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions