Callback listeners

FlyCallback#

FlyCallback is used as a base callback method for most io operations. It's written as a single medthod inteface so that developers can make use of lambda in java and kotlin.

public interface FlyCallback {
void flyResponse(boolean isSuccess, @Nullable Throwable throwable, @NotNull HashMap<String, Object> data);
}

Observe Chat Connection#

To observe the chat connection status you can either implement or create a annonymous ChatConnectionListener interface and attach it to ChatConnectionManager.

ChatConnectionListener chatConnectionListener = new ChatConnectionListener() {
@Override
public void onConnected() {
//Connected to Chat Server
}
@Override
public void onDisconnected() {
// Disconnected from Chat server
}
@Override
public void onConnectionFailed(@NonNull FlyException e) {
// Connection Not authorized or Unable to establish connection with server
}
@Override
public void onReconnecting() {
// Automatic reconnection enabled
}
};
ChatManager.setConnectionListener(chatConnectionListener);

Observe Profile Events#

To observe profile related events you can either implement or create a annonymous ProfileEventsListener interface and attach it to ChatEventsManager and detach the listener when no longer needed.

Example:

ProfileEventsListener profileEventsListener = new ProfileEventsListener() {
@Override
public void usersProfilesFetched() {}
@Override
public void userBlockedMe(@NotNull String jid) {}
@Override
public void userUnBlockedMe(@NotNull String jid) {}
@Override
public void userUpdatedHisProfile(@NotNull String jid){}
@Override
public void userDeletedHisProfile(@NotNull String jid){}
@Override
public void myProfileUpdated(boolean isSuccess) {}
@Override
public void userCameOnline(@NotNull String jid) {}
@Override
public void userWentOffline(@NotNull String jid) {}
@Override
public void usersWhoBlockedMeListFetched(@NotNull List<String> jidList) {}
@Override
public void usersIBlockedListFetched(@NotNull List<String> jidList) {}
@Override
public void userProfileFetched(@NotNull ProfileDetails profileDetails) {}
@Override
public void blockedThisUser(@NotNull String jid) {}
@Override
public void unblockedThisUser(@NotNull String jid) {}
@Override
public void loggedOut() {}
@Override
public void onContactSyncComplete(boolean isSuccess) {}
@Override
public void onAdminBlockedUser(@NotNull String jid, boolean status) {}
@Override
public void onAdminBlockedOtherUser(@NotNull String jid, @NotNull String type, boolean status) {}
};

Attach/Detach ProfileEventsListener#

Properly attach and detach the listeners whenever necessary.

ChatEventsManager.attachProfileEventsListener(PROFILE_EVENTS_LISTENER);
ChatEventsManager.detachProfileEventsListener(PROFILE_EVENTS_LISTENER);
ArgumentTypeDescription
PROFILE_EVENTS_LISTENERProfileEventsListenerProfileEventsListener anonytmous inner class object or a class reference that implements ProfileEventsListener

Note: Only one listener will be attached at any given time.

Contacts Profiles Fetched.#

If the client application has mobile number as the primary identifier of the user and enabled contact sync they can fetch their contacts data and its completion is triggered in the following callbacks.

ContactManager.getRoster() //Start fetching the users data asynchronously
@Override
public void usersProfilesFetched() {
// User Profiles Fetching done Update the UI
}

User blocked you#

If a user blocked you then the following method will be triggered in the profileEventsListener.

@Override
public void userBlockedMe(@NotNull String jid) {
//jid will be user's Jid who blocked you
}

User unblocked you#

If a user unblocked you then the following method will be triggered in the profileEventsListener.

@Override
public void userUnBlockedMe(@NotNull String jid) {
//jid will be user's Jid who unblocked you
}

User Updated his profile#

If a user updated his profile then the following method will be triggered in the profileEventsListener.

@Override
public void userUpdatedHisProfile(@NotNull String jid) {
//jid will be user's Jid who updated his profile
}

User Deleted his profile#

If a user deleted his profile then the following method will be triggered in the profileEventsListener.

@Override
public void userDeletedHisProfile(@NotNull String jid) {
//jid will be user's Jid who deleted his profile
}

My Profile update status#

Once you initiated the update for your profile its status will be triggered by the following method in the profileEventsListener.

@Override
public void userUpdatedHisProfile(boolean isSuccess) {
//if true profile update is succes else profile update failed
}

User came online#

If a user came online then the following method will be triggered in the profileEventsListener.

@Override
public void userCameOnline(@NotNull String jid) {
//jid will be user's Jid who just came online
}

User went offine#

If a user went offline then the following method will be triggered in the profileEventsListener.

@Override
public void userWentOffline(@NotNull String jid) {
//jid will be user's Jid who just went offline
}

Users blocked me list callback#

When called to get the users who blocked me then the following method will be triggered in the profileEventsListener.

@Override
public void usersWhoBlockedMeListFetched(@NotNull List<String> jidList) {
//jidList will be list of user's Jid who blocked you
}

Users i blocked list callback#

When called to get the users who i blocked then the following method will be triggered in the profileEventsListener.

@Override
public void usersIBlockedListFetched(@NotNull List<String> jidList) {
//jidList will be list of user's Jid who i blocked
}

User profile fetched#

When called to get the profile detatil of a user from the server then the following method will be triggered in the profileEventsListener.

@Override
public void userProfileFetched(@NotNull ProfileDetails profileDetails) {
//profileDetails will be the ProfileDetails object of the requested user
}

Block a user#

When called to block a user then the following method will be triggered in the profileEventsListener.

@Override
public void blockedThisUser(@NotNull String jid) {
//jid will be user's Jid who i blocked just now
}

UnBlock a user#

When called to unblock a user then the following method will be triggered in the profileEventsListener.

@Override
public void unblockedThisUser(@NotNull String jid) {
//jid will be user's Jid who i unblocked just now
}

Logged out#

When logout called then the following method will be triggered in the profileEventsListener.

@Override
public void loggedOut() {
//You logged out of chat sdk update the UI
}

Observe Group Events#

To observe group related events you can either implement or create a annonymous GroupEventsListener class and attach it to ChatEventsManager and detach the listener when no longer needed.

Example:

GroupEventsListener groupEventsListener = new GroupEventsListener() {
@Override
public void onGroupDeletedLocally(@NotNull String groupJid) {
}
@Override
public void onGroupNotificationMessage(@NonNull Message message) {
}
@Override
public void onLeftFromGroup(@NonNull String groupJid, @NonNull String leftUserJid) {
}
@Override
public void onMemberRemovedAsAdmin(@NonNull String groupJid, @NonNull String removedAdminMemberJid, @NonNull String removedByMemberJid) {
}
@Override
public void onMemberMadeAsAdmin(@NonNull String groupJid, @NonNull String newAdminMemberJid, @NonNull String madeByMemberJid) {
}
@Override
public void onFetchingGroupListCompleted(@NonNull int noOfGroups) {
}
@Override
public void onFetchingGroupMembersCompleted(@NonNull String groupJid) {
}
@Override
public void onMemberRemovedFromGroup(@NonNull String groupJid, @NonNull String removedMemberJid, @NonNull String removedByMemberJid) {
}
@Override
public void onNewMemberAddedToGroup(@NonNull String groupJid, @NonNull String newMemberJid, @NonNull String addedByMemberJid) {
}
@Override
public void onGroupProfileUpdated(@NonNull String groupJid) {
}
@Override
public void onNewGroupCreated(@NonNull String groupJid) {
}
@Override
public void onGroupProfileFetched(@NotNull String groupJid) {
}
}

Attach/Detach GroupEventsListener#

Properly attach and detach the listeners whenever necessary.

ChatEventsManager.attachGroupEventsListener(GROUP_EVENTS_LISTENER);
ChatEventsManager.detachProfileEventsListener(GROUP_EVENTS_LISTENER);
ArgumentTypeDescription
GROUP_EVENTS_LISTENERGroupEventsListenerGroupEventsListener anonytmous inner class object or a class reference that implements GroupEventsListener

Note: Only one listener will be attached at any given time.

Group Profile Fetched#

When the request for fetching a group profile is completed successfully this callback will be triggered.

@Override
public void groupProfileFetched(@NotNull String groupJid) {
//Group profile data fetched successfully
}

Group notification message received#

When events like new member added or member removed a notification message will be generated locally and inserted in the local database. After insertion this callback will be triggered.

@Override
public void onGroupNotificationMessage(@NotNull Message message) {
//Group Notification message received
}

New group created#

When a new group was created like when someone added you to a group this callback will be triggered.

@Override
public void onNewGroupCreated(@NotNull String groupJid) {
//New group created
}

Group profile updated#

When a group profile is updated this callback will be triggered.

@Override
public void onGroupProfileUpdated(@NotNull String groupJid) {
//Group profile updated
}

New member added to group#

When a new member is added to the group this callback will be triggered.

@Override
public void onNewMemberAddedToGroup(@NonNull String groupJid, @NonNull String newMemberJid, @NonNull String addedByMemberJid) {
//New member added to a group successfully
}

Member removed from group#

When a member is removed from the group this callback will be triggered.

@Override
public void onMemberRemovedFromGroup(@NonNull String groupJid, @NonNull String removedMemberJid, @NonNull String removedByMemberJid) {
// A group member was removed
}

Fetching group members#

When a group is created, members of that group will be fetched once sucessfully fetched this callback will be triggered.

@Override
public void onFetchingGroupMembersCompleted(@NonNull String groupJid){
// Members of a group fetched successfully
}

Group member became an admin#

When a group member became an admin this callback will be triggered.

@Override
public void onMemberMadeAsAdmin(@NonNull String groupJid, @NonNull String newAdminMemberJid, @NonNull String madeByMemberJid) {
// A group member was made an admin
}

Admin access revoked#

When a group member's admin access is revoked this callback will be triggered.

@Override
public void onMemberRemovedAsAdmin(@NonNull String groupJid, @NonNull String removedAdminMemberJid, @NonNull String removedByMemberJid) {
// A group admin access was revoked
}

Member left from the group#

When a member left the group this callback will be triggered.

@Override
public void onLeftFromGroup(@NonNull String groupJid, @NonNull String leftUserJid) {
// A group member left from the group
}

Group deleted locally#

When the current user delete a group locally this callback will be triggered.

@Override
public void onGroupDeletedLocally(@NotNull String groupJid) {
// A group was deleted locally
}

Observing the message events#

You need to register the observer to observe all the message related events, so that you can update the UI immediately based on the message events.Once you have sent the message via sdk, you will get the callbacks for message status events.you can register your own listener by using the below method. This is common for both single chat and groups.

tip

There can be only one message listener at a time, if you set multiple times using the below method it will replace the old listener always.

ChatEventsManager.setupMessageEventListener(new MessageEventsListener() {
@Override
public void onMessageReceived(@NotNull ChatMessage message) {
//called when the new message is received
}
@Override
public void onMessageStatusUpdated(@NotNull String messageId) {
//called when the message status is updated
//find the index of message object in list using messageId
//then fetch message object from db using `FlyMessenger.getMessageOfId(messageId)` and notify the item in list
}
@Override
public void onMediaStatusUpdated(@NotNull ChatMessage message) {
//called when the message status is updated
//find the index of message object in list using messageId
//then fetch message object from db using `FlyMessenger.getMessageOfId(messageId)` and notify the item in list
}
@Override
public void onUploadDownloadProgressChanged(@NotNull String messageId, int progressPercentage) {
//called when the media message progress is updated
}
@Override
public void onMessagesClearedOrDeleted(@NotNull ArrayList<String> messageIds) {
//called when the message is deleted
}
@Override
public void showOrUpdateOrCancelNotification(String jid, ChatMessage chatMessage) {
//Called whenever a notification needed to be shown or updated or cancelled
}
@Override
public void updateArchiveUnArchiveChats(String toUser, Boolean archiveStatus) {
// Called whenever archive chats updated
}
@Override
public void updateArchivedSettings(Boolean archivedSettingsStatus) {
// Called whenever unarchive chats updated
}
@Override
public void updateGroupReplyNotificationForArchivedSettingsEnabled(ChatMessage chatMessage) {
// Code will added on Overridden Place
}
});
info

For group, message status will be updated only if all the participants sent the delivery/seen status.

Observing the Archive Chats events#

When the Recent Chat Archive/UnArchive by user this callback will be triggered.

@Override
public void updateArchiveUnArchiveChats(@NotNull String toUser, Boolean archiveStatus) {
//called when the Chat is Archive/UnArchive updated
}

When a user click on Archive Settings option this callback will be triggered.

@Override
public void updateArchivedSettings(Boolean archivedSettingsStatus) {
//called when the archive settings enable or disable status updated
}