Sync Phonebook Contact

Sync Contact#


It will be only applicable for mobile number registration and contact book synchronization.

If mobile number is used as a primary id for communication in chat sdk then there has to be sync between user and server. The following code block initiate the contact sync and let the user communicate with their contacts who uses the client app too.

Note : In order to sync mobile contacts need to enable ChatManager.enableMobileNumberLogin

IS_FIRST_TIMEbooleantrue for first time and false after when synchronising contacts

To observe contact sync events you can either implement or create a annonymous ProfileEventsListener interface and attach it to ChatEventsManager and detach the listener when no longer needed. To know more about other methods in ProfileEventsListener kindly visit Profile Events

public void onContactSyncComplete(boolean isSuccess) {
if (isSuccess) {
// Contact Sync Success Reload Contact list

To avoid unnecessay multiple contact sync calls observe the status of the contact sync beore calling syncContacts.

FlyCore.getContactSyncState().observe(getViewLifecycleOwner(), result -> {
if (result instanceof Result.Success) {}
else if (result instanceof Result.Error) {}
else if (result instanceof Result.InProgress) { }

The value of the contactSyncState can also be accessible by directly calling the get value method since it's a live data variable.

Result<Boolean> contactSyncStateResult = FlyCore.getContactSyncState().getValue();

Revoke Contact Sync#

If mobile number is used as a primary id for communication in chat sdk and contact sync have been completed then the following code block will delete user contacts and revoke the contact sync.

FlyCore.revokeContactSync((isSuccess, throwable, data) -> {
if (isSuccess) {
// Revoke Contact Sync Success Reload Contact list
} else {
CALLBACKFlyCallbackFlyCallback implemented as lambda expression