Pin a conversation
Introduction
Pinning conversations refers to fixing one-on-one or group chat conversations at the top of the conversation list, preventing them from being pushed to the bottom by other non-pinned conversations, and making it easier for users to find them. When users pin a conversation through the client, the pinned status is stored on the server. Therefore, when users switch to another device, the pinned status will be synchronized to the current device.
ZIM supports users to pin conversations and query the pinned conversation list
- Pinned conversations are only supported in ZIM SDK version 2.8.0 or above.
- The maximum limit for pinned conversations is 100.
-
Pinned conversations are always placed before unpinned conversations.
NoteThis rule also applies to the conversation list fetched by calling the queryConversationListWithConfig interface. Developers can confirm whether a conversation is pinned by checking the isPinned field of the ZIMConversation in the fetched results.
-
After a user pins multiple conversations, the relative order between these conversations will remain unchanged.
Let's assume there are 5 conversations, and the existing order in the conversation list is: a, b, c, d, e.
If the user pins conversations b and d (regardless of the order in which they are pinned), the new order will be b, d, a, c, e. In other words, conversations b and d are placed at the front, and conversation b is still placed before conversation d.NoteThe above example assumes that the orderKey of the related conversations remains unchanged before and after pinning. If the orderKey changes, the order in the pinned conversation list will also change.
Pin a conversation
After the login, a user can pin or unpin a conversation in their conversation list by calling the updateConversationPinnedState interface.
// Pin a one-on-one conversation
bool isPinned = YES;
[[ZIM getInstance] updateConversationPinnedState:isPinned conversationID:@"conversationID" conversationType:ZIMConversationTypePeer callback:^(NSString * _Nonnull conversationID, ZIMConversationType conversationType, ZIMError * _Nonnull errorInfo) {
// Business logic
}];
Get the pinned conversation list
After the login, a user can use the queryConversationPinnedListWithConfig interface to get the full list of pinned conversations.
ZIMConversationQueryConfig *queryConfig = [[ZIMConversationQueryConfig alloc] init];
// The number of pinned conversations to retrieve each time
queryConfig.count = 20;
// No need to pass in for the first query
queryConfig.nextConversation = nil;
[[ZIM getInstance] queryConversationPinnedListWithConfig:queryConfig callback:^(NSArray<ZIMConversation *> * _Nonnull conversationList, ZIMError * _Nonnull errorInfo) {
if(errorInfo.code != ZIMErrorCodeSuccess){
NSLog(@"Please handle according to the actual error code and error message by referring to the error code table");
return;
}
NSLog(@"conversationList is the query result");
// Pass the last conversation in the previous query result to query subsequent content based on the previous query result
queryConfig.nextConversation = [conversationList lastObject];
}];