Get Unread Messages in a Conversation
The IMLib SDK supports retrieving unread messages from specified conversations, enabling apps to jump to the first unread message or display all unread @ mentions.
Get the First Unread Message in a Conversation
You can use getFirstUnreadMessage: to obtain the earliest unread message in a conversation.
Method Signature
- (void)getFirstUnreadMessage:(RCConversationType)conversationType
targetId:(NSString *)targetId
completion:(nullable void(^)(RCMessage *_Nullable message))completion;
Parameters
| Parameter | Type | Description |
|---|---|---|
| conversationType | RCConversationType | Conversation type. Use ConversationType_PRIVATE for one-to-one chats |
| targetId | NSString | Target ID of the conversation |
| completion | Block | Callback that returns an RCMessage object. |
Example
[[RCCoreClient sharedCoreClient] getFirstUnreadMessage:ConversationType_PRIVATE targetId:@"targetId" completion:^(RCMessage * _Nullable message) {
}];
Get Unread @ Mentions in a Conversation
tip
- Versions below 5.2.5 only provide the
getUnreadMentionedMessagesmethod withoutcountanddescparameters, returning a maximum of 10 messages per call. - Starting from version 5.2.5,
getUnreadMentionedMessagessupportscountanddescparameters. This method is only available inRCCoreClient. - Starting from version 5.3.0, it's recommended to use the asynchronous interface below, while the original synchronous interface is deprecated.
Retrieves the earliest or latest unread @ mentions in a conversation, with a maximum of 100 messages returned.
Method Signature
- (void)getUnreadMentionedMessages:(RCConversationType)conversationType
targetId:(NSString *)targetId
completion:(nullable void(^)(NSArray<RCMessage *> *_Nullable messages))completion;
Parameters
| Parameter | Type | Description |
|---|---|---|
| conversationType | RCConversationType | Conversation type |
| targetId | NSString | Conversation ID |
| count | int | Number of messages (max 100) |
| desc | BOOL | YES: Fetch the latest count messages. NO: Fetch the earliest count messages. |
| completion | Block | Async callback that returns a list of message objects (RCMessage). |
Example Code
[[RCCoreClient sharedRCCoreClient]
getUnreadMentionedMessages:ConversationType_PRIVATE
targetId:@"targetId"
count:count
desc: NO
completion:completion:^(RCMessage * _Nullable message) {
}];