Viewing Profile Information and Images

As explained before, a user can publish a profile about themselves that other users can view. Groups can also publish profile information that members can view. This section explains how users can access and view those profiles.

Getting the Profile of another User or a Group

You can get the profile of any user or group by calling getProfile API.

profile = Mesibo.getProfile(userAddress);

Or,

profile = Mesibo.getProfile(groupId);

If the profile already exists locally, the getProfile() function will instantly return it. If not, it will return an empty profile and request the profile from the mesibo (or your on-premise) server.

The server will send back whatever profile information the user is allowed to access, based on profile privacy settings explained in the previous section. So you may get a full profile, partial profile, or empty profile depending on the access level set by that user. When the profile is received from the server, mesibo will notify your app using a listener callback covered later.

A user may receive a blank profile if they don't have access to view it based on the profile owner's privacy settings. However, the user can still subscribe and wait in case the owner changes settings later to allow access.

After getting the profile object, you can call the following functions to access all the profile information.

Getting Profile Information

As mentioned before, mesibo stores profile information as name-value pairs. You can use these functions to access them:

String profile.getString(name, defaultValue); // get a string value 
int profile.getInt(name, defaultValue); // get an integer value
long profile.getLong(name, defaultValue); // get a long integer value
double profile.getDouble(name, defaultValue);  // get a real value
boolean profile.getBoolean(name, defaultValue); // get a boolean true or false value

If the value does not exist, these functions return the defaultValue set in the second parameter.

For example,

String status = profile.getString("status", "");
String city = profile.getString("city", "");
int zip = profile.getInt("zip", 0);

Getting Profile Name

Since the name is commonly used, mesibo has dedicated functions.

String name = profile.getName();
String firstname = profile.getFirstName();
String name = profile.getNameOrAddress();

Getting Profile Images

As mentioned before, a mesibo profile can have multiple images. You can access them using the index value that was used when originally setting that image:

MesiboProfileImage image = profile.getImage(0); // image at index 0

Once you obtain an image object, you can use various functions on it:

Bitmap bmp = image.getImage(); // get full image
Bitmap tn = image.getThumbnail(); // get thumbnail
String url = image.getUrl(); // get image URL
String path = image.getImagePath(); // get image path on the device (not available in Javascript)

You can also access an image object without passing any index. In that case, it will return the first available image object:

MesiboProfileImage image = profile.getImage(); // first available image

Iterating through Profile Images

Once you have an image object, you can iterate using the getNext() and getPrevious() functions:

To get the next image if the profile has multiple images,

MesiboProfileImage nextImage = image.getNext(); 

To get the previous image,

MesiboProfileImage prevImage = image.getPrevious(); 

mesibo automatically synchronizes all profile images in the background. However, to optimize bandwidth usage based on network conditions, mesibo may defer downloading some images until those specific profile images are accessed. This avoids unnecessarily downloading images the user may not need.

Once an image is accessed and the download is complete, mesibo will notify the app via a listener callback that the profile has been updated with that new image. At that point, the app can display the newly downloaded image(s).

The app can also force mesibo to download a specific image right away using getImage(), but this is usually not necessary since the image will be fetched automatically when accessed anyway.

Overriding Profile Information (Local Override)

A user cannot change another user's published profile. But they can override it locally by calling set methods explained in the previous section. For example:

profile.setName("New Name");

This won't affect the global published profile. It only changes locally what your app sees.

You can also save local overrides:

profile.setName("New Name");
profile.save(); // save local changes to the database

To restore an original value, set the property back to null or use profile.removeValue(name).

To fully reset the profile object, use profile.reset() or profile.removeLocalProfile(). This will undo all local overrides.