Class Message

  • All Implemented Interfaces:

    
    public final class Message
    
                        

    Message envelope class.

    Contains general message properties (ID, sender, timestamp, etc.) and the message content body content.

    • General fields (ID, sender, timestamp, etc.) are stored in Message.

    • Specific content (text, image, etc.) is stored in content as a MessageContent subclass.

    val message: Message = ...
    when (val content = message.content) {
        is TextMessage -> println("Text: ${content.text}")
        is ImageMessage -> println("Image: ${content.remoteUrl}")
        is FileMessage -> println("File: ${content.name}")
    }
    • Constructor Detail

    • Method Detail

      • isCounted

         final Boolean isCounted()

        Whether this message is counted for unread count.

      • isPersisted

         final Boolean isPersisted()

        Whether this message is persisted in local storage.

      • isStatusMessage

         final Boolean isStatusMessage()

        Whether this is a status-only message (not stored or counted).

      • getClientId

         final Integer getClientId()

        Auto-increment ID in the local database message table (client-side local ID).

      • getSentTime

         final Long getSentTime()

        Message sent time (Unix timestamp in milliseconds, server time).

      • setSentTime

         final Unit setSentTime(Long sentTime)

        Message sent time (Unix timestamp in milliseconds, server time).

      • getMessageId

         final String getMessageId()

        Server-side unique message ID (globally unique within the same app).

      • getMetadata

         final Map<String, String> getMetadata()

        Message metadata in key-value format, supports remote sync.

      • setMetadata

         final Unit setMetadata(Map<String, String> metadata)

        Message metadata in key-value format, supports remote sync.

      • getHasChanged

         final Boolean getHasChanged()

        Whether the message has been modified (community channel messages only).

      • getNeedReceipt

         final Boolean getNeedReceipt()

        Whether this message requires a read receipt.

      • setNeedReceipt

         final Unit setNeedReceipt(Boolean needReceipt)

        Whether this message requires a read receipt.

      • getSentReceipt

         final Boolean getSentReceipt()

        Whether a read receipt has been sent for this message.

      • getDirectedUserIds

         final List<String> getDirectedUserIds()

        Directed user ID list (only effective for group / community channels; null for direct channels).

      • setDirectedUserIds

         final Unit setDirectedUserIds(List<String> directedUserIds)

        Directed user ID list (only effective for group / community channels; null for direct channels).

      • getDisableNotification

         final Boolean getDisableNotification()

        Whether push notification is disabled for this message.

      • getDisableUpdateLastMessage

         final Boolean getDisableUpdateLastMessage()

        Whether to prevent this message from updating the channel's latest message.

      • setDisableUpdateLastMessage

         final Unit setDisableUpdateLastMessage(Boolean disableUpdateLastMessage)

        Whether to prevent this message from updating the channel's latest message.

      • setReceivedStatusInfo

         final Unit setReceivedStatusInfo(MessageReceivedStatusInfo receivedStatusInfo, OperationHandler<Boolean> handler)

        Sets the received status of this message.

        Updates the message's received status in the local database.

        val status = ReceivedStatus()
        status.setRead()
        status.setListened()
        message.setReceivedStatusInfo(status) { success, error ->
            if (error == null) {
                // Status updated
            }
        }
        Parameters:
        handler - Callback returning true on success
      • setMetadata

         final Unit setMetadata(Map<String, String> metadata, ErrorHandler handler)

        Updates message metadata.

        Sets or updates key-value metadata for this message, with remote sync support.

        message.setMetadata(mapOf("read_count" to "10", "liked" to "true")) { error ->
            if (error == null) {
                // Updated successfully
            }
        }
        Parameters:
        metadata - Key-value pairs to update; existing keys will be overwritten
        handler - Operation result callback; error is null on success
      • deleteMetadata

         final Unit deleteMetadata(List<String> keys, ErrorHandler handler)

        Removes message metadata by keys.

        Deletes the specified keys from this message's metadata, with remote sync support.

        message.removeMetadata(listOf("read_count", "liked")) { error ->
            if (error == null) {
                // Removed successfully
            }
        }
        Parameters:
        keys - List of metadata keys to remove
        handler - Operation result callback; error is null on success
      • setSpeechToTextVisible

         final Unit setSpeechToTextVisible(Boolean isVisible, ErrorHandler handler)

        Sets the visibility of the speech-to-text result.

        Controls whether the speech-to-text result is displayed in the UI. The visibility state is persisted to the local database.

        message.setSpeechToTextVisible(true) { error ->
            if (error == null) {
                // Set successfully
            }
        }
        Parameters:
        isVisible - Whether the speech-to-text result should be visible
        handler - Operation result callback; error is null on success
      • downloadMedia

         final Unit downloadMedia(DownloadMediaMessageHandler handler)

        Downloads the media file attached to this message.

        Applies to media messages (image, voice, video, file, etc.). Download progress and result are delivered via DownloadMediaMessageHandler.

        message.downloadMedia(object : DownloadMediaMessageHandler {
            override fun onSuccess(message: Message) { /* Download succeeded */}
            override fun onProgress(message: Message, progress: Int) { /* Progress updated */}
            override fun onError(message: Message, error: NCError) { /* Download failed */}
            override fun onCanceled(message: Message) { /* Download cancelled */}
        })
        Parameters:
        handler - Download callback
      • cancelDownloadingMedia

         final Unit cancelDownloadingMedia(ErrorHandler handler)

        Cancels the ongoing media download for this message.

        message.cancelDownloadingMedia { error ->
            if (error == null) {
                // Cancelled successfully
            }
        }
        Parameters:
        handler - Operation result callback; error is null on success
      • pauseDownloadingMedia

         final Unit pauseDownloadingMedia(ErrorHandler handler)

        Pauses the ongoing media download for this message.

        message.pauseDownloadingMedia { error ->
            if (error == null) {
                // Paused successfully
            }
        }
        Parameters:
        handler - Operation result callback; error is null on success