Skip to main content
Key Benefit: Maintain accurate unread counts and provide clear user feedback by intelligently marking messages as read when users interact with them, ensuring precise conversation state management.

Feature Overview

Message Read Status enables precise tracking of individual message reading states, allowing you to mark messages as read when users view them and maintain accurate unread counts across your chat application. This feature provides the foundation for reliable conversation state management and user engagement tracking.

Individual Message Tracking

Granular read state management
  • Mark specific messages as read
  • Real-time status updates

Unread Count Accuracy

Precise count management
  • Immediate count updates
  • Consistent state synchronization

Implementation Guide

  • Basic Message Read Tracking
Mark messages as read when users view themImplement fundamental read tracking to update message status and maintain accurate unread counts as users interact with conversations.

Core Read Operations

OperationPurposeWhen to Use
markRead()Mark a specific message as readUser views message content
Automatic DetectionMark messages read on viewMessage appears in viewport
Latest Message ReadMark newest message readChat screen opens

Code Examples

// Basic message read marking
func markMessageAsRead(message: AmityMessage) {
    message.markRead()
    print("Message \(message.messageId) marked as read")
}

// Mark messages as read in table view
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    guard let message = getMessage(for: indexPath) else { return }
    
    // Mark message as read when it appears on screen
    message.markRead()
}

// Mark latest message as read when entering chat
class ChatViewController: UIViewController {
    private var messageRepository: AmityMessageRepository!
    private var token: AmityNotificationToken?
    private var isFirstLoad = true
    
    override func viewDidLoad() {
        super.viewDidLoad()
        observeMessages()
    }
    
    private func observeMessages() {
        let messageQuery = AmityMessageQueryOptions(
            subChannelId: subChannelId,
            sortOption: .lastCreated
        )
        
        token = messageRepository.getMessages(options: messageQuery).observe { liveCollection, _, error in
            guard error == nil else { return }
            
            // Mark latest message as read on first load
            if self.isFirstLoad, let latestMessage = liveCollection.object(at: 0) {
                latestMessage.markRead()
                self.isFirstLoad = false
            }
            
            // Update UI with messages
            self.updateMessagesList(liveCollection)
        }
    }
    
    private func updateMessagesList(_ collection: AmityCollection<AmityMessage>) {
        // Update table view with new messages
        DispatchQueue.main.async {
            self.tableView.reloadData()
        }
    }
}

// Smart read tracking with visibility detection
func configureMessageCell(_ cell: MessageTableViewCell, with message: AmityMessage, at indexPath: IndexPath) {
    cell.configure(with: message)
    
    // Mark as read when cell becomes fully visible
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
        if self.tableView.indexPathsForVisibleRows?.contains(indexPath) == true {
            message.markRead()
        }
    }
}
Timing Considerations: Mark messages as read when they become visible to users, not just when they’re loaded. This provides more accurate engagement tracking and better user experience.

Read Tracking Strategies

Automatically mark messages as read when users see themImplement intelligent visibility detection to mark messages as read when they appear in the user’s viewport:
  • Intersection Observer: Use modern web APIs for efficient viewport tracking
  • Threshold Detection: Mark messages read when 70%+ visible for 2+ seconds
  • Scroll State Awareness: Process reads only when scrolling stops
  • Performance Optimization: Throttle read operations to prevent API spam
Visibility-based reading provides the most accurate representation of user engagement.
Mark messages as read based on user interactionsTrigger read status based on deliberate user actions for more intentional tracking:
  • Tap/Click Events: Mark read immediately on message interaction
  • Focus Events: Mark read when message receives keyboard focus
  • Context Menu: Provide manual “mark as read” options
  • Gesture Recognition: Use swipe or long-press gestures for read control
Interaction-based reading gives users explicit control over read status.
Use viewing duration to determine read statusImplement sophisticated timing logic to mark messages read after sufficient viewing time:
  • Dwell Time: Require minimum viewing duration (2-3 seconds)
  • Progressive Reading: Longer messages require longer viewing time
  • User Preferences: Allow users to customize read timing
  • Context Awareness: Adjust timing based on message type and importance
Time-based reading balances automatic detection with meaningful engagement.
Efficiently manage read status for multiple messagesProvide bulk read operations for better user experience and performance:
  • Mark All Read: Allow users to mark entire channels as read
  • Selective Reading: Enable multi-select for targeted read operations
  • Smart Batching: Group read operations to reduce API calls
  • Progress Feedback: Show progress for long-running bulk operations
Bulk operations help users manage large volumes of unread messages efficiently.

Best Practices

Create intuitive read tracking experiences
  • Mark messages as read when they become meaningfully visible to users
  • Provide immediate visual feedback when messages are marked as read
  • Allow users to control automatic read behavior through preferences
  • Use consistent read indicators across your entire application
Thoughtful UX design makes read tracking helpful rather than intrusive.
Optimize read tracking for scale and responsiveness
  • Throttle read operations to prevent excessive API calls during scrolling
  • Use efficient intersection observers instead of scroll event listeners
  • Batch multiple read operations when possible to reduce network overhead
  • Implement proper cleanup to prevent memory leaks in long-running sessions
Performance optimization ensures smooth operation even with high message volume.
Leverage read data for valuable insights
  • Track reading patterns to understand user engagement
  • Monitor read rates to identify popular content and communication effectiveness
  • Use read timing data to optimize message display and notification strategies
  • Provide read analytics to help users understand their communication patterns
Analytics integration transforms read data into actionable insights for both users and developers.
Implementation Strategy: Start with basic manual read tracking (mark on tap), then add visibility-based automatic detection. Focus on user control and clear feedback to build trust in your read tracking system.