Skip to main content
Key Benefit: Provide users with clear visibility into unread messages across individual channels and in aggregate, enabling efficient conversation prioritization and engagement tracking.

Feature Overview

Channel Unread Count enables tracking of unread messages at both individual channel and aggregate levels. This feature provides essential data for chat list interfaces, notification badges, and user engagement analytics.

Individual Channel Tracking

Per-channel unread visibility
  • Real-time unread count updates
  • Channel-specific mention indicators
  • Unread count support detection
  • Live object synchronization

Aggregate Tracking

Cross-channel analytics
  • Total unread count across all channels
  • Global mention status tracking
  • Cached channel aggregation
  • User engagement insights

Implementation Guide

  • Individual Channel Unread Count
  • Total Unread Count
Track unread messages for specific channelsAccess unread count data directly from channel objects to display in chat lists, navigation badges, and conversation headers.

Channel Unread Properties

PropertyTypeDescription
unreadCountNumberNumber of unread messages in the channel
isUnreadCountSupportedBooleanWhether the channel supports unread count tracking
isMentionedBooleanWhether the current user is mentioned in unread messages

Code Examples

// Get unread count from channel object
func displayChannelUnreadCount(channel: AmityChannel) {
    let unreadCount = channel.unreadCount
    print("Channel unread count = \(unreadCount)")
    
    // Update UI with unread count
    updateChannelBadge(count: unreadCount)
    
    // Check if channel supports unread count
    if channel.isUnreadCountSupported {
        showUnreadIndicator(count: unreadCount)
    } else {
        hideUnreadIndicator()
    }
}

// Observe channel for real-time unread updates
func observeChannelUnreadCount(channelId: String) {
    token = channelRepository.getChannel(channelId).observe { liveObject, error in
        guard let channel = liveObject.snapshot else { return }
        
        let unreadCount = channel.unreadCount
        let isMentioned = channel.isMentioned
        
        // Update UI with latest unread data
        DispatchQueue.main.async {
            self.updateUnreadBadge(
                count: unreadCount,
                highlighted: isMentioned
            )
        }
    }
}

// Check unread count support
func checkUnreadSupport(channel: AmityChannel) -> Bool {
    return channel.isUnreadCountSupported
}
Real-time Updates: Channel unread counts are automatically updated through live objects. Subscribe to channel observations to receive instant updates when new messages arrive.

Best Practices

Create intuitive unread count experiences
  • Use consistent badge styling across your entire application
  • Implement smooth animations for count changes to avoid jarring updates
  • Provide clear visual distinction between regular unread and mention notifications
  • Consider accessibility requirements for users with visual impairments
Thoughtful UX design makes unread counts helpful rather than overwhelming.
Optimize unread count operations
  • Use efficient data structures for tracking multiple channel states
  • Implement debouncing for rapid unread count changes
  • Monitor memory usage when observing many channels simultaneously
Performance optimization ensures smooth operation even with high message volume.
Handle unread count edge cases gracefully
  • Provide fallback indicators when unread counts are unavailable
  • Handle network disconnections without breaking unread tracking
  • Implement retry logic for failed unread count requests
  • Show appropriate loading states during unread data retrieval
Robust error handling maintains user trust even when data is temporarily unavailable.
Implementation Strategy: Start with individual channel unread counts in your chat list, then add total unread aggregation for app-level indicators. Always check unread count support before implementing unread-dependent features.