Skip to main content

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.
tip

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 NameTypeDescription
ObjectNameStringThe identifier name of the message type, determined by the value in the io.rong.imlib.MessageTag annotation of the message content body.
ContentMessageContentThe 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.
ConversationTypeConversationTypeConversation type enumeration, such as one-to-one chat, group chat, chatroom, ultra group, system conversation, etc. Refer to Conversation Introduction.
SenderUserIdStringThe user ID of the message sender.
TargetIdStringConversation ID (or target ID), used to identify the conversation counterpart.
  1. For one-to-one conversations, the counterpart user's ID is used as the Target ID. Therefore, the Target ID of all sent and received messages must be the counterpart user's ID. Note: The Target ID stored in the local message data for messages received by the current user is not the current user's ID but the counterpart user's (message sender's) ID.
  2. For group, chatroom, and ultra group conversations, the Target ID is the corresponding group, chatroom, or ultra group ID.
  3. For system conversations, since client users cannot reply to system conversation messages, no Target ID is needed.
ChannelIdStringUltra group channel ID.
MessageIdintMessage ID, the unique ID of the message in local storage (database index unique value).
UIdStringMessage UID, globally unique under the same App Key. Only successfully sent messages have a unique ID.
MessageDirectionMessageDirectionMessage direction enumeration, divided into sent and received.
SentTimelongMessage 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.
ReceivedTimelongMessage receiving time. The receiving time is the client's local time when the message arrives at the receiving client. Uses UNIX timestamp in milliseconds.
SentStatusSentStatusThe status of the sent message. Such as sending, sent successfully, failed to send, canceled sending.
ReceivedStatusReceivedStatusThe status of the received message, such as whether it has been read or downloaded. For details, see Message Receiving Status.
ReadReceiptInfoReadReceiptInfoGroup chat message read receipt information. For details, refer to Group Chat Message Receipt.
isCanIncludeExpansionbooleanWhether message expansion is allowed. For details, refer to Message Expansion.
ExpansionMap<String, String>Message extension information. For details, refer to Message Expansion.
ExtraStringAdditional 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.
isOfflinebooleanWhether 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.
disableUpdateLastMessagebooleanProhibits 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.
needReceiptbooleanMessage read receipt operation identifier. This attribute is supported starting from SDK version 5.20.0. For details, refer to Per-Message Read Receipt Function.
sentReceiptbooleanWhether 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.
modifyInfoMessageModifyInfoMessage 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 MessageContent base class and adds processing logic for media files. For example, the built-in SDK message type image message content body (ImageMessage) inherits from MediaMessageContent. 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: