Callback listeners

Observe Profile Events#

To observe profile related events, refer the below listeners where ever needed

Example:

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.

FlyChat.getRoster() //Start fetching the users data asynchronously
FlyChat.usersProfilesFetched.listen(result){
//jid will be user's Jid who blocked you
};

User blocked you#

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

FlyChat.userBlockedMe.listen(result){
//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.

FlyChat.userUnBlockedMe.listen(result){
//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.

FlyChat.userUpdatedHisProfile.listen(onMessageReceived){
//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.

FlyChat.userDeletedHisProfile.listen(onMessageReceived){
//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.

``java
FlyChat.myProfileUpdated.listen(result){
//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.

FlyChat.userCameOnline.listen(onMessageReceived){
//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.

FlyChat.userWentOffline.listen(onMessageReceived){
//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.

FlyChat.usersWhoBlockedMeListFetched.listen(onMessageReceived){
//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.

FlyChat.usersIBlockedListFetched.listen(onMessageReceived){
//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.

FlyChat.userProfileFetched.listen(onMessageReceived){
//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.

FlyChat.blockedThisUser.listen(onMessageReceived){
//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.

FlyChat.unblockedThisUser.listen(onMessageReceived){
//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.

FlyChat.loggedOut.listen(onMessageReceived){
//You logged out of chat sdk update the UI
};

Admin blocked#

When Admin blocked then the following method will be triggered

FlyChat.onAdminBlockedUser.listen(result){
//You logged out of chat sdk update the UI
};

Admin blocked others#

When Admin blocked then the following method will be triggered

FlyChat.onAdminBlockedOtherUser.listen(result){
//You logged out of chat sdk update the UI
};

Observe Group Events#

To observe group related events you can implement the following listerns

Example:

Group Profile Fetched#

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

FlyChat.onGroupProfileFetched.listen(result){
//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.

FlyChat.onGroupNotificationMessage.listen(onGroupNotificationMessage){
//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.

FlyChat.onNewGroupCreated.listen(onNewGroupCreated) {
//New group created
};

Group profile updated#

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

FlyChat.onGroupProfileUpdated.listen(onGroupProfileUpdated) {
//Group profile updated
}

New member added to group#

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

FlyChat.onNewMemberAddedToGroup.listen(onNewMemberAddedToGroup) {
//New member added to a group successfully
}

Member removed from group#

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

FlyChat.onMemberRemovedFromGroup.listen(onMemberRemovedFromGroup) {
// 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.

FlyChat.onFetchingGroupMembersCompleted.listen(onFetchingGroupMembersCompleted) {
// Members of a group fetched successfully
}

Group member became an admin#

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

FlyChat.onMemberMadeAsAdmin.listen(onMemberMadeAsAdmin) {
// A group member was made an admin
}

Admin access revoked#

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

FlyChat.onMemberRemovedAsAdmin.listen(onMemberRemovedAsAdmin) {
// A group admin access was revoked
}

Member left from the group#

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

FlyChat.onLeftFromGroup.listen((event){
if(event!=null) {
// A group member left from the group
var data = json.decode(event.toString());
var groupJid = data["groupJid"] ?? "";
var leftUserJid = data["leftUserJid"] ?? "";
onLeftFromGroup(groupJid: groupJid,userJid: leftUserJid);
}
});

Group deleted locally#

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

FlyChat.onGroupDeletedLocally.listen(onGroupDeletedLocally) {
// A group was deleted locally
}

Observing the message events#

You need to register the observer to listen 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.

FlyChat.onMessageReceived.listen(onMessageReceived) {
var chatMessageModel = sendMessageModelFromJson(chatMessage);
//called when the new message is received
}
FlyChat.onMessageStatusUpdated.listen(onMessageStatusUpdated){
var chatMessageModel = sendMessageModelFromJson(event);
//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
}
FlyChat.onMediaStatusUpdated.listen(onMediaStatusUpdated){
var chatMessageModel = sendMessageModelFromJson(event);
//called when the media message status is updated like downloaded,uploaded,failed
//find the index of message object in list using messageId and notify the item in list
}
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
}
});
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
}