The SDK optimizes the messaging flow by instantly displaying sent messages before server delivery, providing seamless user experience with comprehensive state tracking and automatic synchronization.

Instant Display

Immediate feedback
  • Messages appear instantly in the UI
  • Optimistic rendering for smooth UX
  • Real-time state tracking
  • Visual delivery indicators

Robust Sync

Reliable delivery
  • Automatic retry mechanisms
  • Queue-based processing
  • Network interruption handling
  • Causal ordering maintenance

Supported Message Types

social.plus Chat supports multiple message types for diverse communication needs:

Message Synchronization

Immediate message creation and displayWhen you create a message, the SDK first creates it locally and displays it immediately in the UI. This provides instant feedback while the message is being synchronized with the server in the background.

Local Message Flow

  1. Instant Creation: Message appears immediately in live collections
  2. Queue Addition: Message is added to synchronization queue
  3. Background Sync: Server synchronization begins automatically
  4. State Updates: Real-time status updates via syncState property

Implementation Examples

// Observe live collection for real-time updates
let query = AmityMessageQueryOptions(subChannelId: "1234")
token = messageRepository.getMessages(options: query).observe({ liveCollection, _, error in
    let messages = liveCollection.allObjects()
    for message in messages {
        // Check message synchronization state
        let syncState = message.syncState
        updateUIForSyncState(message, syncState)
    }
})

// Create message with immediate local display
let options = AmityTextMessageCreateOptions(
    subChannelId: "1234", 
    text: "Hi Amity!", 
    tags: nil, 
    parentId: nil, 
    metadata: nil, 
    mentioneesBuilder: nil
)
do {
    let message = try await messageRepository.createTextMessage(options: options)
    // Message appears instantly in live collection
} catch {
    // Handle creation errors
}
Sync State Monitoring: Use live collections to observe real-time sync state changes and provide appropriate UI feedback to users.

Error Handling & Recovery

Built-in retry mechanisms for failed messagesThe SDK automatically handles network interruptions and server errors with intelligent retry logic.

Retry Strategy

Retry Parameters
  • Maximum Attempts: 3 automatic retries
  • Retry Interval: ~5 seconds between attempts
  • Exponential Backoff: Increasing delays for subsequent retries
  • Final State: Message marked as failed after max retries

Error Handling Examples

// Handle message creation with error recovery
let options = AmityTextMessageCreateOptions(
    subChannelId: "1234", 
    text: "Hi Amity!", 
    tags: nil, 
    parentId: nil, 
    metadata: nil, 
    mentioneesBuilder: nil
)

do {
    let message = try await messageRepository.createTextMessage(options: options)
    // Message created successfully
} catch let error {
    // Handle specific error types
    if error.isAmityErrorCode(.banWordFound) {
        let nsError = error as NSError
        
        // Remove message containing banned words
        if let localMessageId = nsError.userInfo["messageId"] as? String {
            try? await messageRepository.softDeleteMessage(withId: localMessageId)
        }
        
        showBannedWordError()
    } else {
        // Handle other error types
        handleGeneralError(error)
    }
}

Best Practices

Implementation Strategy: Start with basic text message sending, implement proper sync state UI feedback, then add robust error handling and recovery mechanisms. Focus on user experience by providing immediate feedback and clear status indicators.