Callback listeners

Observing the message events Individually#

Use the event listeners for 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. This is common for both single chat and groups.

tip

There can be used as multiple message listener at a time, if you set multiple times using the below method it will not replace the old listener.

Event Listener for Incoming Message#

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

Event Listener for Edit Message#

Mirrorfly.onMessageEdited.listen((event){
var chatMessageModel = sendMessageModelFromJson(event);
//called when the message is edited
});

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"]);
});

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
});

User typing status#

To observe the typing status changes, you can use the below method to setup the listener.

Mirrorfly.typingStatus.listen((event) {
var data = json.decode(event.toString());
var singleOrgroupJid = data["singleOrgroupJid"];
var userJid = data["userJid"];
var typingStatus = data["status"];
});

Available Features status#

To observe the available features based on your subscription, you can use the below method to setup the listener.

Mirrorfly.onAvailableFeaturesUpdated.listen((value) {
var features = availableFeaturesFromJson(value.toString());
});
info

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

Observing the message events Collectively#

Assign the listener to the appropriate class to receive event updates. Extend the class and implement the necessary event listeners collectively for streamlined integration 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.

Mirrorfly.setMessageEventListener(YourClass());
class YourClass extends MessageEventListeners{
@override
void onAvailableFeaturesUpdated(AvailableFeatures availableFeatures) {
// TODO: implement onAvailableFeaturesUpdated
}
@override
void onMediaStatusUpdated(ChatMessageModel mediaMessage) {
// TODO: implement onMediaStatusUpdated
}
@override
void onMessageReceived(ChatMessageModel chatMessage) {
// TODO: implement onMessageReceived
}
@override
void onMessageEdited(ChatMessageModel chatMessage) {
// TODO: implement onMessageEdited
}
@override
void onMessageStatusUpdated(ChatMessageModel chatMessage) {
// TODO: implement onMessageStatusUpdated
}
@override
void onUploadDownloadProgressChanged(String messageId, int progressPercentage) {
// TODO: implement onUploadDownloadProgressChanged
}
@override
void setTypingStatus(String singleOrGroupJid, String userJid, String status) {
// TODO: implement setTypingStatus
}
@override
void showOrUpdateOrCancelNotification(String jid, ChatMessageModel chatMessageModel) {
// TODO: implement showOrUpdateOrCancelNotification
}
@override
void userCameOnline(String jid) {
// TODO: implement userCameOnline
}
@override
void userWentOffline(String jid) {
// TODO: implement userWentOffline
}
}