Callback listeners

Observe Profile Events#

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

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.

Mirrorfly.usersProfilesFetched.listen((event){
//true profiles fetched is success.
});

User blocked you#

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

Mirrorfly.userBlockedMe.listen((event){
var data = json.decode(event.toString());
var jid = data["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.

Mirrorfly.userUnBlockedMe.listen((event){
var data = json.decode(event.toString());
var jid = data["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.

Mirrorfly.userUpdatedHisProfile.listen((event){
var data = json.decode(event.toString());
var jid = data["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.

Mirrorfly.userDeletedHisProfile.listen((event){
var data = json.decode(event.toString());
var jid = data["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.

Mirrorfly.myProfileUpdated.listen((event){
//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.

Mirrorfly.userCameOnline.listen((event){
var data = json.decode(event.toString());
var jid = data["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.

Mirrorfly.userWentOffline.listen((event){
var data = json.decode(event.toString());
var jid = data["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.

Mirrorfly.usersWhoBlockedMeListFetched.listen((event){
var data = json.decode(event.toString());
var jidlist = data["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.

Mirrorfly.usersIBlockedListFetched.listen((event){
var data = json.decode(event.toString());
var jidlist = data["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.

Mirrorfly.userProfileFetched.listen((event){
var data = json.decode(event.toString());
var jid = data["jid"];
var profileDetails = data["profileDetails"];
//profileDetails of the requested user
});

Block a user#

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

Mirrorfly.blockedThisUser.listen((event){
var data = json.decode(event.toString());
var jid = data["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.

Mirrorfly.unblockedThisUser.listen((event){
var data = json.decode(event.toString());
var jid = data["jid"];
//jid will be user's Jid who i unblocked just now
});

Logged out#

When logout called then the following method will be triggered.

Mirrorfly.onLoggedOut.listen((event){
//You logged out of chat sdk update the UI
});

Admin blocked#

When Admin blocked then the following method will be triggered

Mirrorfly.onAdminBlockedUser.listen((event){
var data = json.decode(event.toString());
var jid = data["jid"];
var status = data["status"];
//You logged out of chat sdk update the UI
});

Admin blocked others#

When Admin blocked then the following method will be triggered

Mirrorfly.onAdminBlockedOtherUser.listen((event){
var data = json.decode(event.toString());
var jid = data["jid"];
var type = data["type"];
var status = data["status"];
//You logged out of chat sdk update the UI
});

Observe Group Events#

To observe group related events you can implement the following listeners

Group Profile Fetched#

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

Mirrorfly.onGroupProfileFetched.listen((event){
//Group profile jid data fetched.
});

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.

Mirrorfly.onGroupNotificationMessage.listen((event){
//Group Notification message received
ChatMessageModel chatMessageModel = sendMessageModelFromJson(event.toString());
});

New group created#

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

Mirrorfly.onNewGroupCreated.listen((event){
//New group created jid
});

Group profile updated#

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

Mirrorfly.onGroupProfileUpdated.listen((event){
//Group profile updated jid
});

New member added to group#

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

Mirrorfly.onNewMemberAddedToGroup.listen((event){
var data = json.decode(event.toString());
var groupJid = data["groupJid"];
var newMemberJid = data["newMemberJid"];
var addedByMemberJid = data["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.

Mirrorfly.onMemberRemovedFromGroup.listen((event){
var data = json.decode(event.toString());
var groupJid = data["groupJid"];
var removedMemberJid = data["removedMemberJid"];
var removedByMemberJid = data["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.

Mirrorfly.onFetchingGroupMembersCompleted.listen((event){
// Members fetched successfully of a group jid
});

Group member became an admin#

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

Mirrorfly.onMemberMadeAsAdmin.listen((event){
var data = json.decode(event.toString());
var groupJid = data["groupJid"];
var newAdminMemberJid = data["newAdminMemberJid"];
var madeByMemberJid = data["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.

Mirrorfly.onMemberRemovedAsAdmin.listen((event){
var data = json.decode(event.toString());
var groupJid = data["groupJid"];
var removedAdminMemberJid = data["removedAdminMemberJid"];
var removedByMemberJid = data["removedByMemberJid"];
// A group admin access was revoked
});

Member left from the group#

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

Mirrorfly.onLeftFromGroup.listen((event){
// A group member left from the group
var data = json.decode(event.toString());
var groupJid = data["groupJid"];
var leftUserJid = data["leftUserJid"];
});

Group deleted locally#

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

Mirrorfly.onGroupDeletedLocally.listen((event){
// 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.

Event Listener for Incoming Message#

Mirrorfly.onMessageReceived.listen((event){
var chatMessageModel = sendMessageModelFromJson(event);
//called when the new message is received
});

Event Listener for Message Status Updates#

Mirrorfly.onMessageStatusUpdated.listen((event){
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 `Mirrorfly.getMessageOfId(messageId)` and notify the item in list
});

Event Listener for Media Message Status Updates#

Mirrorfly.onMediaStatusUpdated.listen((event){
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
});

Event Listener for Media Message Upload/Download Progress Updates#

Mirrorfly.onUploadDownloadProgressChanged.listen((event){
var data = json.decode(event.toString());
var messageId = data["message_id"] ?? "";
var progressPercentage = data["progress_percentage"] ?? 0;
});

Event Listener for Message Notification's#

Mirrorfly.showOrUpdateOrCancelNotification.listen((event){
// This event is triggered when the user needs to be notified.
// You can display the notification in the UI if necessary.
var data = json.decode(event.toString());
var jid = data["jid"];
var chatMessage = sendMessageModelFromJson(data["chatMessage"]);
});
info

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