Live Data Objects: Message retrieval returns live objects that automatically update when message content changes, ensuring your UI always displays the most current information without manual refresh operations.

Message Retrieval Overview

Retrieve and display message content using live data objects that provide real-time updates and comprehensive content handling for all message types including text, images, videos, files, and custom messages.

Live Objects

Real-time updates
  • Automatic content synchronization
  • Live data object observation
  • Real-time change notifications
  • Seamless UI updates

All Content Types

Comprehensive support
  • Text message handling
  • Image and video processing
  • File attachment management
  • Custom message structures

Implementation Guide

Retrieve individual messages by IDGet specific messages using their unique identifiers with live data observation for real-time updates.

Required Parameters

ParameterTypeDescription
messageIdStringUnique identifier of the message to retrieve

Return Value

TypeDescription
LiveObject<AmityMessage>Live data object with automatic updates

Code Examples

// Get single message with live updates
func observeMessage(messageId: String) {
    let messageObject = messageRepository.getMessage(messageId)
    
    // Observe message changes
    token = messageObject.observe { [weak self] messageObject, error in
        if let error = error {
            self?.handleError(error)
            return
        }
        
        guard let message = messageObject.object else {
            print("Message not found or deleted")
            return
        }
        
        // Update UI with message content
        self?.displayMessage(message)
        
        // Handle different message types
        self?.processMessageContent(message)
    }
}
Live Data Benefits: Live objects automatically update when message content changes, eliminating the need for manual refresh calls and ensuring your UI always displays current information.

Message State Management

Implementation Priority: Start with basic text and image message display, then progressively add support for other content types. Always implement proper error handling and loading states for the best user experience.