Topic Based Chat

Topic based chat lets you to group the chat by topic. You can create the topic , send all types of messages with topic information and thus you can receive the messages by topic.

Create Topic#

You can use the below given method to create a new topic.

Mirrorfly.createTopic(topicName: TOPIC_NAME,metaData: [TopicMetaData(key: "description", value: "value")]).then((value) {
var topics = topicsFromJson(value.toString());
}).catchError((onError) {});
ArgumentTypeDescription
TOPIC_NAMEStringName of the topic (cannot be null or empty)
META_DATAList<MetaData>META_DATA is an optional parameter to provide additional information about the topic. You can pass it as a List of MetaData Maximum Size is 3

Get Topics#

You can use the below given method to get the topics details.

Mirrorfly.getTopics(topicIds: TOPIC_IDS).then((value) {
var topics = topicsFromJson(value.toString());
}).catchError((onError) {});
ArgumentTypeDescription
TOPIC_IDSList<String>List of topic ids

Send Message#

To send the message to the user, use the below methods. Different messages such as text, image, audio, video & document type messages can be sent using the below methods.

Text message#

To send your text message, you need to add the below arguments to the parameter in the sendTextMessage() method.

Mirrorfly.sendTextMessage(TEXT, TO_JID, REPLY_MESSAGE_ID, topicId: TOPIC_ID).then((value) {
var data = sendMessageModelFromJson(value);
});
ArgumentTypeDescription
TO_JIDStringjid of the end user
TEXTStringtext message to be sent
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
TOPIC_IDStringtopic id to be used

Image message#

To send your image message, you need to add the below arguments to the parameter in the sendImageMessage() method.

Mirrorfly.sendImageMessage(TO_JID, IMAGE_FILE, CAPTION, REPLY_MESSAGE_ID, topicId: TOPIC_ID).then((value) {
var data = sendMessageModelFromJson(value);
});
ArgumentTypeDescription
TO_JIDStringjid of the end user
IMAGE_FILEStringimage File path which needs to be sent
CAPTIONStringadditional text which can be sent along with the image message
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
TOPIC_IDStringtopic id to be used

Video message#

To send your video message, you need to add the below arguments to the parameter in the sendVideoMessage() method.

Mirrorfly.sendVideoMessage(TO_JID, LOCAL_FILE_PATH, VIDEO_CAPTION, REPLY_MESSAGE_ID, topicId: TOPIC_ID).then((value) {
var data = sendMessageModelFromJson(value);
});
ArgumentTypeDescription
TO_JIDStringjid of the end user
LOCAL_FILE_PATHStringvideo File path object
VIDEO_CAPTIONStringcaption text for video file
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
TOPIC_IDStringtopic id to be used

Audio message#

To send your audio message, you need to add the below arguments to the parameter in the sendAudioMessage() method.

Mirrorfly.sendAudioMessage(TO_JID, AUDIO_FILE, IS_RECORDED, AUDIO_DURATION, REPLY_MESSAGE_ID,topicId: TOPIC_ID).then((value) {
var data = sendMessageModelFromJson(value);
});
ArgumentTypeDescription
TO_JIDStringjid of the end user
AUDIO_FILEStringaudio File path we are sending
AUDIO_DURATIONintduration of the audio file
IS_RECORDEDbooltrue, if audio file is recorded.false, if audio file is attached.
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
TOPIC_IDStringtopic id to be used

Document message#

To send your document message, you need to add the below arguments to the parameter in the sendDocumentMessage() method.

Mirrorfly.sendDocumentMessage(TO_JID, LOCAL_FILE_PATH, REPLY_MESSAGE_ID, topicId: TOPIC_ID).then((value) {
var data = sendMessageModelFromJson(value);
});
ArgumentTypeDescription
TO_JIDStringjid of the end user
LOCAL_FILE_PATHStringLocal document File path of the document
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
TOPIC_IDStringtopic id to be used

Location message#

To send your location message, you need to add the below arguments to the parameter in the sendLocationMessage() method.

Mirrorfly.sendLocationMessage(TO_JID, LATITUDE, LONGITUDE, REPLY_MESSAGE_ID,topicId: TOPIC_ID).then((value) {
var data = sendMessageModelFromJson(value);
});
ArgumentTypeDescription
TO_JIDStringjid of the end user
LATITUDEdoublelocation latitude which needs to be sent
LONGITUDEdoublelocation longitude which needs to be sent
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
TOPIC_IDStringtopic id to be used

Contact message#

To send your contact message, you need to add the below arguments to the parameter in the sendContactMessage() method.

Mirrorfly.sendContactMessage(TO_JID, CONTACT_NAME, CONTACT_NUMBERS, REPLY_MESSAGE_ID,topicId: TOPIC_ID).then((value) {
var data = sendMessageModelFromJson(value);
});
ArgumentTypeDescription
TO_JIDStringjid of the end user
CONTACT_NAMEStringcontact name
CONTACT_NUMBERSList<String>list of numbers in that contact
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
TOPIC_IDStringtopic id to be used

Send Reply message#

To send reply message to the original message, you need to pass the additional parameter original message-id in replyMessageId.TextMessage object as an argument to the parameter in the sendTextMessage() method.

Mirrorfly.sendTextMessage(TEXT, TO_JID, REPLY_MESSAGE_ID, topicId: TOPIC_ID).then((value) {
var data = sendMessageModelFromJson(value);
});

Receive Message#

To receive a Topic related message from another user you must implement the onMessageReceived function. It's a function that will be triggered whenever you receive a new message or related event in the chat.

Mirrorfly.onMessageReceived.listen((chatMessage){
var data = sendMessageModelFromJson(chatMessage);
});

Get Chats By TopicId#

To get all the list of TopicId related chats, send a request to the server as described below.

Load Initial Topic Based Chat List#

To fetch initial Topic based recent chat list, call the below method.

Mirrorfly.getRecentChatListHistoryByTopic(firstSet: true, limit: chatLimit, topicId: TOPIC_ID)then((value) async {
if(value != null){
var data = recentChatFromJson(value.toString());
}
});
ArgumentTypeDescription
topicIdStringtopic id to be used
firstSetboolset true to get initial recent chat list otherwise get next set of data
limitintThe maximum number of chat items to retrieve is specified by limit with a default value of 15 if not provided.

Get messages#

To get the chat and media messages, use the below methods

Load Initial Messages#

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

Mirrorfly.initializeMessageList(userJid: TO_JID, limit: 25,topicId: TOPIC_ID).then((value) {
Mirrorfly.loadMessages().then((value) {
var data = chatMessageModelFromJson(value);
}).catchError((e) {});
});
ArgumentTypeDescription
TOPIC_IDStringtopic id to be used

Load Previous Messages#

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

Mirrorfly.loadPreviousMessages().then((value) {
var data = chatMessageModelFromJson(value);
}).catchError((e) {});

Load Next Messages#

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

Mirrorfly.loadNextMessages().then((value) {
var data = chatMessageModelFromJson(value);
}).catchError((e) {});