When users need to focus on a conversation or can not deal with a conversation at the moment, you can mark the conversation for later processing, such as "starring a conversation," "collapsing a conversation," "hiding a conversation," "marking a conversation as unread," etc. You can achieve this by calling the setConversationMark
interface.
When a user marks a conversation, the SDK simply records the mark value of the conversation without changing the underlying logic of the conversation.
Before marking conversations, make sure:
ZIM supports you in implementing conversation marking operations using either client API or server API.
After logging into the ZIM SDK, users need to call the on method to listen for the conversationChanged event to receive notifications of changes to conversation marks.
Once the conversation marks are changed, all of the user's online devices will receive a conversationChanged event notification. From this notification, the current marks of the conversation can be obtained from the marks
field of the conversation
object.
// Register the SDK event notification callback
zim.on('conversationChanged', function (zim, { infoList }) {
infoList.forEach((info) => {
console.log(info.conversation.marks);
});
});
You simply need to call the setConversationMark interface to set or cancel marks for up to 100 conversations (only supports one-on-one chats or group chats). Each conversation can have up to 20 marks.
// Taking setting a mark with 1 for a one-on-one conversation and a group chat conversation as an example
var markType = 1;
var enable = true;
var convList = [
{ conversationID: 'One-to-one conversation', conversationType: 0 },
{ conversationID: 'Group conversation', conversationType: 2 },
];
zim.setConversationMark(markType, enable, convList)
.then((res) => {
// Operation successful. The conversations that failed are returned through res.failedConversationInfos.
})
.catch((err) => {
// Operation failed
});
Developers can set or cancel conversation marks for multiple users in batches by calling the server-side API. For details, please refer to the server API documentation Mark Conversations.
When calling the queryConversationList interface, pass in a mark list by ZIMConversationFilterOption.marks, and you can use the marks as filters to get a conversation list.
Additionally, if you need to consider whether there are unread messages in the conversation during the query, simply pass isOnlyUnreadConversation
as YES when calling the queryConversationList interface.
// For example, querying the list of group and one-to-one conversations that have a mark of 1 and contain unread messages
var config = { count: 10 };
var option = {
marks: [1],
conversationTypes: [],
isOnlyUnreadConversation: true,
};
zim.queryConversationList(config, option)
.then((res) => {
// Operation successful
})
.catch((err) => {
// Operation failed
});
Call the queryConversationTotalUnreadMessageCount interface and pass in the conversation mark list through ZIMConversationTotalUnreadMessageCountQueryConfig.marks to query the total number of unread messages for conversations marked accordingly.
// For example, querying the total number of unread messages for one-to-one and group conversations marked with 1
var config = {
marks: [1],
conversationTypes: [],
};
zim.queryConversationTotalUnreadMessageCount(config)
.then((res) => {
// Operation successful
})
.catch((err) => {
// Operation failed
});