After logging in to Chat, users can start adding contacts and chatting with each other. They can also manage these contacts, for example, by adding, retrieving and removing contacts. They can also add the specified user to the block list to stop receiving messages from that user.
This page shows how to use the Chat SDK to implement contact management.
The Chat SDK uses
ContactManager to add, remove and manage contacts. Followings are the core methods:
addContact: Adds a contact.
acceptInvitation: Accepts the contact invitation.
declineInvitation: Declines the contact invitation.
deleteContact: Deletes a contact.
getAllContactsFromServer: Retrieves a list of contacts from the server.
addUserToBlackList: Adds the specified user to the block list.
removeUserFromBlackList: Removes the specified user from the block list.
getBlackListFromServer: Retrieves a list of blocked users from the server.
Before proceeding, ensure that you meet the following requirements:
- You have integrated the Chat SDK, initialized the SDK and implemented the functionality of registering accounts and login. For details, see Chat SDK quickstart.
- You understand the API call frequency limits as described in Limitations.
This section shows how to manage contacts with the methods provided by the Chat SDK.
Use this section to understand how to send a contact invitation, listen for contact events, and accept or decline the contact invitation.
addContact to add the specified user as a contact:
ContactListener to add the following callback events. When a user receives a contact invitation, you can accept or decline the invitation.
declineInvitation to accept or decline the invitation.
deleteContact to delete the specified contact. The deleted user receives the
To get the contact list, you can call
getAllContactsFromServer to retrieve contacts from the server. After that, you can also call
getContactsFromLocal to retrieve contacts from the local database.
You can add a specified user to your block list. Once you do that, you can still send chat messages to that user, but you cannot receive messages from them.
addUserToBlackList to add the specified user to the block list.
To remove the specified user from the block list, call
To get the block list, call
getBlackListFromServer to retrieve a list of blocked users from the server.
After retrieving the block list from the server, you can also call
getBlackListUserNames to retrieve the block list from the local database.