Retrieve Messages

Get a message#

Whenever you get callbacks from MessageEventsListener, 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.

ChatMessage message = FlyMessenger.getMessageOfId(MESSAGE_ID);
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.

List<ChatMessage> messages = FlyMessenger.getMessagesUsingIds(MESSAGE_ID_LIST);

Get messages of a user/group#

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

List<ChatMessage> messages = FlyMessenger.getMessagesOfJid(JID);
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.

FetchMessageListParams messageListParams = new FetchMessageListParams();
messageListParams.setChatJid(JID);
messageListParams.setMessageId(MESSAGE_ID);
messageListParams.setMessageTime(MESSAGE_TIME);
messageListParams.setInclusive(true);
messageListParams.setAscendingOrder(true);
messageListParams.setLimit(50);
messageListParams.setTopicId(TOPIC_ID); //optional
ArgumentTypeDescription
JIDStringJid of the user/group
MESSAGE_IDStringMessage id of the starting point optional
MESSAGE_TIMEStringMessage time of the starting point optional
INCLUSIVEbooleanIf true starting point message will included in message list default false
ASCENDING_ORDERbooleanIf true message list will be returned ascendingOrder by message time default false
LIMITintNo of messages will be fetched for each request default 50
TOPIC_IDStringTopic Id to be fetched

Second, create a FetchMessageListQuery instance.

FetchMessageListQuery messageListQuery = new FetchMessageListQuery(MESSAGE_LIST_PARAM);
ArgumentTypeDescription
MESSAGE_LIST_PARAMFetchMessageListParamsInsatance of 'FetchMessageListParams'

Load Initial Messages#

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

messageListQuery.loadMessages((isSuccess, throwable, data) -> {
if (isSuccess) {
List<ChatMessage> messageList = (List<ChatMessage>) data.get("data");
} else {
// Fetch messages failed print throwable to find the exception details.
}
});
ArgumentTypeDescription
CALLBACKFlyCallback'FlyCallback' implemented as lambda expression

Load Previous Messages#

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

messageListQuery.loadPreviousMessages((isSuccess, throwable, data) -> {
if (isSuccess) {
List<ChatMessage> messageList = (List<ChatMessage>) data.get("data");
} else {
// Fetch messages failed print throwable to find the exception details.
}
});
ArgumentTypeDescription
CALLBACKFlyCallback'FlyCallback' implemented as lambda expression

Load Next Messages#

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

messageListQuery.loadNextMessages((isSuccess, throwable, data) -> {
if (isSuccess) {
List<ChatMessage> messageList = (List<ChatMessage>) data.get("data");
} else {
// Fetch messages failed print throwable to find the exception details.
}
});
ArgumentTypeDescription
CALLBACKFlyCallback'FlyCallback' implemented as lambda expression

Check Previous Set of Messages Available or not#

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

Boolean hasPreviousMessages = messageListQuery.hasPreviousMessages();

Check Next Set of Messages Available#

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

Boolean hasNextMessages = messageListQuery.hasNextMessages();

Check Message Fetching InProgress#

To check conversations fetching in progress or not, call the below method.

Boolean fetchingInProgress = messageListQuery.isFetchingInProgress();

Get media messages#

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

List<ChatMessage> mediaMessages = ChatManager.getMediaMessages(JID);
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:

ChatMessage message = FlyMessenger.getMessageOfId(MEDIA_MESSAGE_ID);
MediaChatMessage mediaMessage = message.getMediaChatMessage();
@MediaDownloadStatus int mediaStatus = mediaMessage.getMediaDownloadStatus();
//The possible values of mediaStatus were
MediaDownloadStatus.MEDIA_DOWNLOADING
MediaDownloadStatus.MEDIA_DOWNLOADED
MediaDownloadStatus.MEDIA_NOT_DOWNLOADED
MediaDownloadStatus.MEDIA_DOWNLOADED_NOT_AVAILABLE

For sent media message:

ChatMessage message = FlyMessenger.getMessageOfId(MEDIA_MESSAGE_ID);
MediaChatMessage mediaMessage = message.getMediaChatMessage();
@MediaUploadStatus int mediaStatus = mediaMessage.getMediaUploadStatus();
//The possible values of mediaStatus were
MediaUploadStatus.MEDIA_NOT_UPLOADED
MediaUploadStatus.MEDIA_UPLOADING
MediaUploadStatus.MEDIA_UPLOADED
MediaUploadStatus.MEDIA_UPLOADED_NOT_AVAILABLE
ArgumentTypeDescription
MEDIA_MESSAGE_IDStringid of a message

Get recalled messages of a user/group#

To get the recalled messages of a user/group call the below method.

List<ChatMessage> recalledMessages = FlyMessenger.getRecalledMessagesOfAConversation(JID);
ArgumentTypeDescription
JIDStringJid of the user/group