Class CustomMediaMessageContent

  • All Implemented Interfaces:

    
    public abstract class CustomMediaMessageContent
    extends MediaMessageContent
                        

    Base class for custom media message content.

    Extend this class to define custom message types that require file uploads (e.g., custom images, custom files). The SDK handles registration, sending (including file upload), and decoding automatically — no internal SDK types are needed.

    Compared to CustomMessageContent:

    • Inherits from MediaMessageContent, which provides localPath, remoteUrl, name, and other media properties

    • The SDK automatically handles file uploads when sending

    Subclasses must:

    Usage example:

    class CustomFileMessage : CustomMediaMessageContent() {
        var fileType: String = ""
        var fileSize: Long = 0L
    
        override fun messageType(): String = "app:customfile"
    
        override fun persistentFlag(): Int = MessagePersistent.COUNT
    
        override fun encodeFields(): Map<String, Any?> = mapOf(
            "fileType" to fileType,
            "fileSize" to fileSize
        )
    
        override fun decodeFields(fields: Map<String, Any?>) {
            fileType = fields["fileType"] as? String ?: ""
            fileSize = (fields["fileSize"] as? Number)?.toLong() ?: 0L
        }
    }
    
    NCEngine.registerCustomMessages(listOf(CustomFileMessage::class.java))
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract String messageType() Message type identifier.
      abstract Integer persistentFlag() Message storage policy flag.
      abstract Map<String, Object> encodeFields() Encodes the message content into serializable key-value pairs.
      abstract Unit decodeFields(Map<String, Object> fields) Decodes the message content from field data.
      List<String> searchableWords() Returns a list of keywords to be indexed for message search.
      • Methods inherited from class ai.nexconn.chat.message.MediaMessageContent

        getLocalPath, getName, getRemoteUrl, setLocalPath, setName, setRemoteUrl, toString
      • Methods inherited from class ai.nexconn.chat.message.MessageContent

        getDestructTime, getExtra, getMentionedInfo, isDestruct, setDestruct, setDestructTime, setExtra, setMentionedInfo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CustomMediaMessageContent

        CustomMediaMessageContent()
    • Method Detail

      • messageType

         abstract String messageType()

        Message type identifier.

        Must not start with "RC:" (reserved prefix). Must be consistent across all platforms (Android / iOS / Web).

        Examples: "app:customfile", "app:customimage"

      • encodeFields

         abstract Map<String, Object> encodeFields()

        Encodes the message content into serializable key-value pairs.

        Called when sending a message. Note: localPath and remoteUrl are handled automatically by the SDK and should not be included here. Only encode your custom business fields.

        Returns:

        a map of field names to their serializable values

      • decodeFields

         abstract Unit decodeFields(Map<String, Object> fields)

        Decodes the message content from field data.

        Called when receiving a message. Note: localPath and remoteUrl are restored automatically by the SDK and should not be decoded here. Only decode your custom business fields.

        Parameters:
        fields - the deserialized JSON field data of the message
      • searchableWords

         List<String> searchableWords()

        Returns a list of keywords to be indexed for message search.

        Defaults to an empty list.

        Returns:

        a list of searchable keywords