Migration guide
MirrorFly Chat SDK Version 3 has introduced major send message method changes to streamline the code structure and enhance its scalability.
This guide explains step by step guide for migrating to Version 3.
Send Text Message#
Step 1: Below method were deprecated from Version 3, Remove the following method from the code.
- Java
- Kotlin
FlyMessenger.sendTextMessage(TO_JID, TEXT, REPLY_MESSAGE_ID, MENTION_IDS, new SendMessageListener() {
@Override
public void onResponse(boolean isSuccess, @Nullable ChatMessage chatMessage) {
// you will get the message sent success response
}
});
FlyMessenger.sendTextMessage(TO_JID, TEXT, REPLY_MESSAGE_ID, MENTION_IDS, object : SendMessageListener {
override fun onResponse(isSuccess: Boolean, chatMessage: ChatMessage?) {
// you will get the message sent success response
}
})
Step 2: This method is newly introduced from Version 3, Add the following code to send the message.
- Java
- Kotlin
TextMessage textMessage = new TextMessage();
textMessage.setToId(TO_JID);
textMessage.setMessageText(TEXT);
textMessage.setReplyMessageId(REPLY_MESSAGE_ID); // Optional
textMessage.setMentionedUsersIds(MENTION_IDS); // Optional
textMessage.setMetaData(META_DATA); //Optional
textMessage.setTopicId(TOPIC_ID); //Optional
FlyMessenger.sendTextMessage(textMessage, (isSuccess, error, chatMessage) -> {
if (isSuccess) {
//you can add this message obje ct to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
});
val textMessage = TextMessage().apply {
toId = TO_JID
messageText = TEXT
replyMessageId = REPLY_MESSAGE_ID // Optional
mentionedUsersIds = MENTION_IDS // Optional
metaData = META_DATA // Optional
topicId = TOPIC_ID// optional
}
FlyMessenger.sendTextMessage(textMessage, object : SendMessageCallback {
override fun onResponse(isSuccess: Boolean, error: Throwable?, chatMessage: ChatMessage?) {
if (isSuccess) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
}
})
Refer this doc to know more about Send Text Message
Send File Message#
Step 1: Below method were deprecated from Version 3, Remove the following method from the code.
Location Message#
- Java
- Kotlin
FlyMessenger.sendLocationMessage(TO_JID, LATITUDE, LONGITUDE, REPLY_MESSAGE_ID, (isSuccess, chatMessage) -> {
if (chatMessage != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
});
FlyMessenger.sendLocationMessage(TO_JID, LATITUDE, LONGITUDE, REPLY_MESSAGE_ID, object : SendMessageListener {
override fun onResponse(isSuccess: Boolean, message: ChatMessage?) {
if (message != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
}
})
Contact Message#
- Java
- Kotlin
FlyMessenger.sendContactMessage(TO_JID, CONTACT_NAME, CONTACT_NUMBERS, REPLY_MESSAGE_ID, (isSuccess, chatMessage) -> {
if (chatMessage != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
});
FlyMessenger.sendContactMessage(TO_JID, CONTACT_NAME, CONTACT_NUMBERS, REPLY_MESSAGE_ID, object : SendMessageListener {
override fun onResponse(isSuccess: Boolean, message: ChatMessage?) {
if (message != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
}
})
Document Message#
- Java
- Kotlin
FlyMessenger.sendDocumentMessage(TO_JID, FILE, FILE_NAME ,REPLY_MESSAGE_ID, (isSuccess, chatMessage) -> {
if (chatMessage != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
});
FlyMessenger.sendDocumentMessage(TO_JID, FILE, FILE_NAME ,REPLY_MESSAGE_ID, object : SendMessageListener {
override fun onResponse(isSuccess: Boolean, chatMessage: ChatMessage?) {
if (chatMessage != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
}
})
Video Message#
- Java
- Kotlin
FlyMessenger.sendVideoMessage(TO_JID, FILE, CAPTION_TEXT, REPLY_MESSAGE_ID, MENTION_IDS, (isSuccess, chatMessage) -> {
if (chatMessage != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
});
FlyMessenger.sendVideoMessage(TO_JID, FILE, CAPTION_TEXT, REPLY_MESSAGE_ID, MENTION_IDS, object : SendMessageListener {
override fun onResponse(isSuccess: Boolean, chatMessage: ChatMessage?) {
if (chatMessage != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
}
})
Image message#
- Java
- Kotlin
FlyMessenger.sendImageMessage(TO_JID, IMAGE_FILE, THUMBNAIL_BASE64, CAPTION, REPLY_MESSAGE_ID, MENTION_IDS, (isSuccess, chatMessage) -> {
if (chatMessage != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
});
FlyMessenger.sendImageMessage(TO_JID, IMAGE_FILE, THUMBNAIL_BASE64, CAPTION, REPLY_MESSAGE_ID, MENTION_IDS, object : SendMessageListener{
override fun onResponse(isSuccess: Boolean, chatMessage: ChatMessage?) {
if (chatMessage != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
}
})
Audio message#
- Java
- Kotlin
FlyMessenger.sendAudioMessage(TO_JID, AUDIO_FILE, AUDIO_DURATION, IS_RECORDED, REPLY_MESSAGE_ID, (isSuccess, chatMessage) -> {
if (chatMessage != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
});
FlyMessenger.sendAudioMessage(TO_JID, AUDIO_FILE, AUDIO_DURATION, IS_RECORDED, REPLY_MESSAGE_ID, object : SendMessageListener {
override fun onResponse(isSuccess: Boolean, message: ChatMessage?) {
if (message != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
}
})
Step 2: This method is newly introduced from Version 3, Add the following code to send the file messages.
- Java
- Kotlin
FileMessageParams fileMessageParams = new FileMessageParams();
fileMessageParams.setFile(FILE);
fileMessageParams.setCaption(CAPTION); //Optional
FileMessage fileMessage = new FileMessage();
fileMessage.setToId(TO_JID);
fileMessage.setMessageType(MessageType.IMAGE);
fileMessage.setReplyMessageId(REPLY_MESSAGE_ID); //Optional
fileMessage.setMentionedUsersIds(MENTION_IDS); //Optional
fileMessage.setMetaData(META_DATA); //Optional
fileMessage.setTopicId(TOPIC_ID); //Optional
fileMessage.setFileMessage(fileMessageParams);
FlyMessenger.sendFileMessage(fileMessage, (isSuccess, error, chatMessage) -> {
if (isSuccess) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
});
val fileMessageParams = FileMessageParams().apply {
file = FILE
caption = CAPTION //Optional
}
val fileMessage = FileMessage().apply {
toId = TO_JID
messageType = MessageType.IMAGE
replyMessageId = REPLY_MESSAGE_ID //Optional
mentionedUsersIds = MENTION_IDS //Optional
metaData = META_DATA // Optional
topicId = TOPIC_ID// optional
fileMessage = fileMessageParams
}
FlyMessenger.sendFileMessage(fileMessage, object : SendMessageCallback {
override fun onResponse(isSuccess: Boolean, error: Throwable?, chatMessage: ChatMessage?) {
if (isSuccess) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
}
})