Mesibo Contact Management and Synchronization APIs

Estimated reading time: 5 minutes

An app can have millions of users. However, each user of the app is only communicating with a set of users. Even within this set, only a few users with whom the user may be interested in receiving or sharing updates. Also, there are users with whom the user does not want to communicate at all.

The contact management APIs allow you to achieve that - defining relations between two users and which information flows between them (visibility). Once you define it, mesibo APIs will start synchronizing profile information between users. For example, when user A updates their profile, user B will get a notification instantly in real-time, etc.

Relationship between Two Users

You can define the following relationship between two users:

Contact

User A can mark user B as a contact. This gives a special privilege to user B to view the profile information of user A depending on the privacy and visibility settings of user A. For example, if user A makes the profile only available to contacts, user B can view the profile of user A. However, user C who is not the contact of user A, can not view it.

Subscriber

User A can subscribe to the profile updates of user B. Depending on the privacy and visibility settings of user B, whenever user B updates their profile, user A will be informed in real-time.

Favorite

A subset of contacts. The usage is application dependent.

Paired

If restricted communication is enabled for user A, user A can only communicate with user B if they are paired. The pairing cannot be set by the user and can only be set by the backend APIs. Refer to Restricted Communication APIs for more details.

Blocked

If user A blocks user B, they can not communicate with each other.

Visibility

The visibility allows users to choose different privacy settings for a different set of users. For example, user A can decide which information (name, picture, status, etc.) to share with user B which may be different than the set of information shared with user C. User A can also decide which information to be shared with all contacts and which for non-contacts.

Using Contact Management APIs

mesibo profile APIs makes it easy to define contact relashinship and visibility, and to keep them synchronized. You only need to access the profile of the remote user by calling getProfile and then call required functions. For example,

MesiboProfile profile = Mesibo.getProfile("remote_user");
profile.setContact(true);
profile.subscribe(true);
profile.save();

That’s it! remote_user is now added as a contact and also subscribed to. Your app will start getting updates whenever the user updates their profile. Similarly, the remote user will also start getting updates about your profile.

Bulk Contact Synchronization

If you are creating a messenger app like WhatsApp or Telegram which uploads your entire phone book as contacts so that your contacts can view your name, image, status, etc., and can find other apps users. In such cases, using the above profile API will be quite slow and instead, you should use bulk contact synchronization APIs syncContacts.

void syncContacts(String[] addresses, boolean addContact, boolean subscribe, int visibility, boolean, syncNow);
void syncContact(String address, boolean addContact, boolean subscribe, int visibility, boolean, syncNow);
void syncContacts();

syncContacts takes the following parameters:

Parameter Description
addresses Array of User addresses to be synced
addContact Pass true to add the user as a contact, false otherwise
subscribe Pass true to be notified when the user profiles are updated, false otherwise
visibility how your profile is visible to these addresses
syncNow Sync immediately or keep adding to the sync queue. Once you are done retrieving contacts, you may complete sync in one shot, by passing an empty addresses array and passing true to syncNow. mesibo will handle all this in the background for you

Once you call syncContacts, mesibo will start synchronizing and will also match the list of addresses with all other users of the app. Your app will then receive the profiles of matching users through the listener [Mesibo_onProfileUpdated].

Example,

String[] contacts = {"18005550001", "18005550002", "18005550003"};
Mesibo.syncContacts(contacts, true, true, 0, true);

If you have queued contacts and would like to sync all these contacts you can call it as follows,

Mesibo.syncContacts();

To sync a single contact, you can use the syncContact method as follows:

Mesibo.syncContact(address, true, true, 0, true);

You can refer to the Mesibo Messenger Apps source code to learn how bulk contact sync APIs are used.

Automatic Contact Synchronization

Mesibo automatically subscribes and synchronizes profiles when you receive a message from other users. If the profile does not exist or is not up to date, mesibo API will ask the server to send the latest profile.

Automatic Contact Synchronization is enabled by default. It is recommended to keep Automatic Contact Synchronization enabled. However, depending on your app requirement, you can disable it by calling enableAutoSyncContacts

Mesibo.enableAutoSyncContacts(false);

Adding Non-existing users as contacts

In addition to existing users, contact management APIs allow you to subscribe to non-existing users and add them as a contact for the future. This allows you to be notified automatically when those contacts join the app (for example, in the WhatsApp or Telegram app, you are notified when one of your contacts joins the app).

contact management, contact synchronization