Retrieve Messages

Get a message#

Whenever you get callbacks from MessageEventsListeners, you will get messageId sometimes at those times you can fetch the message from db using the below method and then update your list as well as notify the list view.

var message = await Mirrorfly.getMessageOfId(messageId: MESSAGE_ID);
var chatMessage = sendMessageModelFromJson(message.toString());
ArgumentTypeDescription
MESSAGE_IDStringmessageId of the message

Get messages using id's#

To get list of messages from a given message id's call the below method.

var messages = await Mirrorfly.getMessagesUsingIds(MESSAGE_ID_LIST);
var chatMessage = chatMessageModelFromJson(messages.toString());

Get messages of a user/group#

To fetch all the conversation between you and a single chat user or group, call the below method.

var messages = await Mirrorfly.getMessagesOfJid(jid: JID);
var chatMessage = chatMessageModelFromJson(messages.toString());
ArgumentTypeDescription
JIDStringJid of the user/group

Get messages of a user/group via pagination#

Initialization#

First, create a FetchMessageListParams instance. Here, you need to set the message filter to determine the message order and the starting point of the message list in the chat view.

var initializeMessage = await Mirrorfly.initializeMessageList(
userJid: toJid,
limit: 25, //optional default value 25
topicId: topicId, //optional
messageTime: messageTime, //optional
exclude: true, //optional default value `true`
ascendingOrder: false, //optional default value `false`
)
ArgumentTypeDescription
JIDStringJid of the user/group
MESSAGE_IDStringMessage id of the starting point optional
MESSAGE_TIMEStringMessage time of the starting point optional
EXCULDEbooleanIf true starting point message will be excluded in message list default true
ASCENDING_ORDERbooleanIf true message list will be returned ascendingOrder by message time default false
LIMITintNo of messages will be fetched for each request default 25
TOPIC_IDStringTopic Id to be fetched

Load Initial Messages#

To fetch initial conversations between you and a single chat user or group using pagination, call the below method.

if(initializeMessage){
Mirrorfly.loadMessages(flyCallback: (FlyResponse response){
if(response.isSuccess && response.hasData){
List<ChatMessageModel> chatMessageModel = chatMessageModelFromJson(response.data);
}
});
}
ArgumentTypeDescription
flyCallbackFlyResponsecallback to observe the action status

Load Previous Messages#

To fetch previous conversations between you and a single chat user or group, call the below method.

Mirrorfly.loadPreviousMessages(flyCallback: (FlyResponse response){
if(response.isSuccess && response.hasData){
List<ChatMessageModel> chatMessageModel = chatMessageModelFromJson(response.data);
}
});
ArgumentTypeDescription
flyCallbackFlyResponsecallback to observe the action status

Load Next Messages#

To fetch next conversations between you and a single chat user or group, call the below method.

Mirrorfly.loadNextMessages(flyCallback: (FlyResponse response){
if(response.isSuccess && response.hasData){
List<ChatMessageModel> chatMessageModel = chatMessageModelFromJson(response.data);
}
});
ArgumentTypeDescription
flyCallbackFlyResponsecallback to observe the action status

Check Previous Set of Messages Available or not#

To check previous set of conversations available or not, call the below method.

bool hasPreviousMessages = await Mirrorfly.hasPreviousMessages();

Check Next Set of Messages Available#

To check next set of conversations available or not, call the below method.

bool hasNextMessages = await Mirrorfly.hasNextMessages();

Get media messages#

If you want to get the media messages for a user/group, you can utilise the below method.

Mirrorfly.getMediaMessages(jid: JID).then((value) async {
if (value != null) {
var data = chatMessageModelFromJson(value);
}
});
ArgumentTypeDescription
JIDStringjid of the chat user
info

Above methods fetch media messages which are successfully sent and received.

caution

If media message feature unavailable for your plan then it will throw 403 exception.

To get the uploaded/downloaded status of a media message Refer the snippet below.

For received media message:

var message = await Mirrorfly.getMessageOfId(messageId: MESSAGE_ID);
var chatMessage = sendMessageModelFromJson(message.toString());
var mediaMessage = chatMessage.mediaChatMessage;
int mediaStatus = mediaMessage.mediaDownloadStatus;
//The possible values of mediaStatus were
MediaDownloadStatus.mediaDownloading.value
MediaDownloadStatus.mediaDownloaded.value
MediaDownloadStatus.mediaNotDownloaded.value
MediaDownloadStatus.mediaDownloadedNotAvailable.value

For sent media message:

var message = await Mirrorfly.getMessageOfId(messageId: MESSAGE_ID);
var chatMessage = sendMessageModelFromJson(message.toString());
var mediaMessage = chatMessage.mediaChatMessage;
int mediaStatus = mediaMessage.mediaUploadStatus;
//The possible values of mediaStatus were
MediaUploadStatus.mediaNotUploaded.value
MediaUploadStatus.mediaUploading.value
MediaUploadStatus.mediaUploaded.value
MediaUploadStatus.mediaUploadedNotAvailable.value
ArgumentTypeDescription
MEDIA_MESSAGE_IDStringid of a message

Get document messages#

If you want to get the Document messages for a user/group, you can utilise the below method.

Mirrorfly.getDocsMessages(jid: JID).then((value) async {
if (value != null) {
var data = chatMessageModelFromJson(value);
}
});
ArgumentTypeDescription
JIDStringjid of the chat user
info

Above methods fetch document messages which are successfully sent and received.

caution

If media message feature unavailable for your plan then it will throw 403 exception.

Get link messages#

If you want to get the link messages for a user/group, you can utilise the below method.

Mirrorfly.getLinkMessages(jid: JID).then((value) async {
if (value != null) {
var data = chatMessageModelFromJson(value);
}
});
ArgumentTypeDescription
JIDStringjid of the chat user
info

Above methods fetch link messages which are successfully sent and received.

Unread count#

if you want to get the unread count of chat messages except muted chat, you can utilise the below method.

var messageCount = await Mirrorfly.getUnreadMessageCountExceptMutedChat()