Message Introduction
The IMLib SDK defines the Message class for message transmission and management.
Message Model
The Message class encapsulates the following key data:
- Attributes for message transmission: Sender ID, recipient ID, conversation type, etc.
- Message content body: Encapsulates the specific content carried by a message, divided into regular message content bodies and media message content bodies. For example, text message content (TextMessage) belongs to regular message content bodies, while image message content (ImageMessage) belongs to media message content bodies. The type of message content body, often referred to as "message type," determines whether to use the interface for sending regular messages or media messages.
The term "message" appearing in the documentation, such as text messages, voice messages, etc., sometimes refers to the specific message content inherited from MessageContent or MediaMessageContent.
The table below describes the key attributes of the Message class. For a complete list of attributes, refer to the API documentation.
| Attribute Name | Type | Description |
|---|---|---|
| ObjectName | String | The identifier name of the message type, determined by the value in the io.rong.imlib.MessageTag annotation of the message content body. |
| Content | MessageContent | The specific content carried by the message, which must be a subclass object of MessageContent or MediaMessageContent, encapsulating the specific data fields of different message types. The IM service provides predefined message types and specifies cross-platform consistent message content body structures (see Message Type Overview), such as text, voice, images, GIFs, etc. You can also create custom message types by customizing the message content body. |
| ConversationType | ConversationType | Conversation type enumeration, such as one-to-one chat, group chat, chatroom, ultra group, system conversation, etc. Refer to Conversation Introduction. |
| SenderUserId | String | The user ID of the message sender. |
| TargetId | String | Conversation ID (or target ID), used to identify the conversation counterpart.
|
| ChannelId | String | Ultra group channel ID. |
| MessageId | int | Message ID, the unique ID of the message in local storage (database index unique value). |
| UId | String | Message UID, globally unique under the same App Key. Only successfully sent messages have a unique ID. |
| MessageDirection | MessageDirection | Message direction enumeration, divided into sent and received. |
| SentTime | long | Message sending time. The sending time is the server's local time when the message arrives at the server from the sending client. Uses UNIX timestamp in milliseconds. |
| ReceivedTime | long | Message receiving time. The receiving time is the client's local time when the message arrives at the receiving client. Uses UNIX timestamp in milliseconds. |
| SentStatus | SentStatus | The status of the sent message. Such as sending, sent successfully, failed to send, canceled sending. |
| ReceivedStatus | ReceivedStatus | The status of the received message, such as whether it has been read or downloaded. For details, see Message Receiving Status. |
| ReadReceiptInfo | ReadReceiptInfo | Group chat message read receipt information. For details, refer to Group Chat Message Receipt. |
| isCanIncludeExpansion | boolean | Whether message expansion is allowed. For details, refer to Message Expansion. |
| Expansion | Map<String, String> | Message extension information. For details, refer to Message Expansion. |
| Extra | String | Additional information of the message. This field is for local operations and will not be sent to the server. Differentiate from MessageContent.extra, which will be sent to the counterpart along with the message. |
| isOffline | boolean | Whether it is an offline message. Only valid in the callback method for receiving messages. If the message is an offline message, it is true; otherwise, it is false. This attribute is supported starting from SDK version 5.4.4. |
| disableUpdateLastMessage | boolean | Prohibits updating to the latest message in the conversation. Default is false (update); true (do not update). This attribute is supported starting from SDK version 5.12.2. |
| needReceipt | boolean | Message read receipt operation identifier. This attribute is supported starting from SDK version 5.20.0. For details, refer to Per-Message Read Receipt Function. |
| sentReceipt | boolean | Whether the read receipt has been sent. This attribute is supported starting from SDK version 5.20.0. For details, refer to Per-Message Read Receipt Function. |
| modifyInfo | MessageModifyInfo | Message modification information. This attribute is supported starting from SDK version 5.26.0. For details, refer to Message Modification. |
MessageContent
The Message class encapsulates the content attribute, representing the specific content carried by a message. The type of the message content body must inherit one of the following base classes:
- MessageContent - Regular message content body. For example, the built-in SDK message type text message content body (TextMessage) inherits from
MessageContent. - MediaMessageContent - Media message content body, inherits from the
MessageContentbase class and adds processing logic for media files. For example, the built-in SDK message type image message content body (ImageMessage) inherits fromMediaMessageContent. When sending and receiving messages, the SDK determines whether the message type is a media type message. If it is a media type, the upload or download process for media files is triggered.
The IM service provides predefined, cross-platform consistent message content body structures (see Message Type Overview), such as text, voice, images, GIFs, etc. If you need to implement custom messages, you can inherit from MessageContent or MediaMessageContent to create custom message content bodies.
Message Storage Strategy
The client SDK and IM server identify the message type, storage strategy on the local and server sides, and whether to count as unread messages through the message annotation (MessageTag). MessageTag is a comment added to the message content class based on Java annotation. Message-specific content inherited from MessageContent or MediaMessageContent must have the MessageTag annotation.
If sending messages of built-in SDK message types, the MessageTag is automatically added by default, and no additional action is required.
If you need to create custom message types, you need to learn how to correctly create message annotations. For details, refer to the following documents: