Message overview
The Chat SDK defines the NCMessage class for message transport and management.
NCMessage model
The NCMessage class contains:
- Transport properties: sender user ID, channel identifier (channel type + channel ID), etc.
- Message content: the actual payload, either a regular message content (
NCMessageContent) or a media message content (NCMediaMessageContent). For example,NCTextMessageis a regular content type, whileNCImageMessageis a media content type.
Key NCMessage properties:
| Property | Type | Description |
|---|---|---|
channelIdentifier | NCChannelIdentifier | Channel identifier, containing channel type (channelType) and channel ID (channelId) |
messageType | NSString | Message type identifier string |
content | NCMessageContent | Message payload — a subclass of NCMessageContent or NCMediaMessageContent |
senderUserId | NSString | Sender's user ID |
clientId | int64_t | Local database unique ID (locally unique only) |
messageId | NSString | Server-assigned globally unique ID (only set after successful send/receive) |
direction | NCMessageDirection | Message direction: send or receive |
sentTime | int64_t | Server timestamp when sent (milliseconds) |
sentStatus | NCSentStatus | Sending status: sending, sent, failed, or cancelled |
receivedStatusInfo | NCMessageReceivedStatusInfo | Receiving status: read, listened, downloaded, etc. |
metadata | NSDictionary<NSString *, NSString *> | Message extension metadata (key-value pairs) |
hasChanged | BOOL | Whether the message has been modified |
needReceipt | BOOL | Whether a read receipt is required |
sentReceipt | BOOL | Whether the read receipt has been sent |
directedUserIds | NSArray<NSString *> | Targeted recipient user IDs (directed message recipients) |
disableNotification | BOOL | Whether remote push and local notifications are disabled |
disableUpdateLastMessage | BOOL | Whether updating the channel's last message is disabled |
isCounted | BOOL | Whether this message is counted toward the unread total |
isPersisted | BOOL | Whether this message is persisted locally |
isStatusMessage | BOOL | Whether this is a status (transient) message |
modifyInfo | NCMessageModifyInfo | Message modification details |
NCMessageContent
All message content types inherit from one of two base classes:
- NCMessageContent — regular messages (e.g.,
NCTextMessage) - NCMediaMessageContent — media messages with upload/download handling (e.g.,
NCImageMessage)
The SDK provides predefined cross-platform message types (text, voice, image, GIF, etc.). You can also create custom message types by subclassing these base classes.
Message storage policy
The NCMessagePersistent property controls how messages are stored locally and on the server, and whether they count toward unread message totals. Built-in message types have default storage policies. Custom message types must conform to the NCMessagePersistentCompatible protocol.