Conversation
is the logic automatically established by the ZIM SDK for users sending one-to-one or group messages(only text message ore rich media messages, excluding custom messages).
ZIM supports users to listen for conversation changes and get a conversation list from the local database. It also supports developers to retrieve the complete conversation list of a specific user from the ZIM server.
You can obtain and display the one-on-one and group chat conversation lists in scenarios such as chats, gaming communities, and online consulting.
Before getting the conversation list, make sure that the following conditions are met:
Before logging in, users should call the on
method to listen for the callback conversationChanged
. After login, the users will receive notifications of conversation changes when the following events happen:
Category | Event | Event Value | ZIMConversation Property |
---|---|---|---|
Basic Conversation Properties |
Change conversation name. |
Updated |
,|
Change conversation avatar URL. |
conversationAvatarUrl |
||
|
conversationAlias |
||
Change unread message count. |
unreadMessageCount |
||
Additional Conversation Properties |
User sets/cancels a conversation as pinned. |
isPinned |
|
User sets notification status for a conversation. |
notificationStatus |
||
User saves a conversation draft. |
draft |
||
User is mentioned in a conversation. |
mentionedInfoList |
||
Last Message in Conversation Changes |
User receives a new message. |
lastMessage |
|
User sends a new message. |
|||
Last message status or content changes. |
|||
Conversation Status Changes |
User has a new conversation. |
Added |
- |
User voluntarily leaves/is kicked out of a group conversation.
This assumes that the group conversation already exists (i.e., there are messages in the conversation). |
Disabled |
- |
|
Group conversation is dissolved.
This assumes that the group conversation already exists (i.e., there are messages in the conversation).
|
|||
Recipient user does not exist when sending a one-on-one message. |
|||
User sends a message to a group they have not joined. |
|||
User deletes a conversation. |
Deleted |
- |
At this time, you can get the conversation list based on your demands.
Currently, the callback conversationChanged
only supports notification of incremental changes of the conversation list in the local database and the conversation list on the ZIM server.
You need to maintain the array of conversation lists retrieved from the queryConversationList
method, and based on current conversation updates, perform property changes, inserts, and sorted displays .
zim.on('conversationChanged', function(zim, { infoList }){
console.log('conversationChanged', infoList)
})
ZIM supports developers to call SDK interfaces to retrieve the current user's conversation list from the local database. It also supports making requests to the ZIM server to retrieve the complete conversation list of a specific user.
After fetching the conversation list, developers can use it to customize the UI display of the conversation list.
After login, if users want to know what conversations they have joined, they can call the queryConversationList
method to query the conversation list.
To avoid the problem of pulling too many conversations at the same time, which takes a long time and causes slow loading of the conversation interface, you can customize the number of conversations by setting the ZIMConversationQueryConfig
object for paging query when pulling conversations.
var config = {
// The conversation flag. If it is set to `null`, the flag is the latest conversation.
nextConversation: null,
// The number of conversations queried per page.
count: 20
};
// Pull the conversation list.
zim.queryConversationList(config)
.then(function({ conversationList }){
// Query succeeded. You need to store and maintain the conversation objects in the array.
})
.catch(function(err){
// Query failed.
})
You can get a user's conversation list by calling the server API. For more details, please refer to the server API documentation Query conversation list.