Retrieve Messages

Get messages using ids#

To get array of messages from database using their message ids, call the below method.

    var messages : [ChatMessage] = FlyMessenger.getMessagesUsingIds(MESSAGE_MIDS)
    ArgumentTypeDescription
    MESSAGE_MIDS[String]Ids of messages

    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 : [ChatMessage] = FlyMessenger.getMessagesOf(jid: JID)
      ArgumentTypeDescription
      JIDStringJid of the chat user/group

      Get messages by pagination#

      Initialization#

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

        let messageListParams = FetchMessageListParams()
        messageListParams.chatId = "CHAT_ID"
        messageListParams.messageId = "MESSAGE_ID"
        messageListParams.messageTime = "MESSAGE_TIME"
        messageListParams.exclude = "EXCLUDE"
        messageListParams.limit = "LIMIT"
        messageListParams.ascendingOrder = "ASCENDING_ORDER"
        messageListParams.topicID = "TOPIC_ID" // Optional
        ArgumentTypeDescription
        CHAT_IDStringJid of the user/group
        MESSAGE_IDStringMessage id of the starting point optional
        MESSAGE_TIMEDoubleMessage time of the starting point optional
        EXCLUDEBoolIf true starting point message will be excluded in message list default true
        ASCENDING_ORDERBoolIf 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`

        Secondly, create a FetchMessageListQuery instance.

          let messageListQuery = FetchMessageListQuery(MESSAGE_LIST_PARAM)
          ArgumentTypeDescription
          MESSAGE_LIST_PARAMFetchMessageListParams'Insatance 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, flyError, flyData in
            var data = flyData
            if (isSuccess) {
            let messageList = data.getData() as? [ChatMessage]
            } else {
            // Fetch messages failed print error to know more about the exception
            }
            }
            ArgumentTypeDescription
            CALLBACKFlyCompletionHandlerFlyCompletionHandler implemented as closures

            Load Previous Messages#

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

              messageListQuery.loadPreviousMessages { isSuccess, flyError, flyData in
              var data = flyData
              if (isSuccess) {
              let messageList = data.getData() as? [ChatMessage]
              } else {
              // Fetch messages failed print error to know more about the exception
              }
              }
              ArgumentTypeDescription
              CALLBACKFlyCompletionHandlerFlyCompletionHandler implemented as closures

              Load Next Messages#

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

                messageListQuery.loadNextMessages { isSuccess, flyError, flyData in
                var data = flyData
                if (isSuccess) {
                let messageList = data.getData() as? [ChatMessage]
                } else {
                // Fetch messages failed print error to know more about the exception
                }
                }
                ArgumentTypeDescription
                CALLBACKFlyCompletionHandlerFlyCompletionHandler implemented as closures

                Check Previous Set of Messages availability#

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

                  let hasPreviousMessages: Bool = messageListQuery.hasPreviousMessages()

                  Check Next Set of Messages availability#

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

                    let hasNextMessages: Bool = messageListQuery.hasNextMessages()

                    Check Message Fetching InProgress#

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

                      let fetchingInProgress: Bool = messageListQuery.isFetchingInProgress()

                      Get media messages#

                      To get the media messages of a conversation, call the below method.

                        var mediaMessages : [ChatMessage] = FlyMessenger.getMediaMessagesOf(jid: JID)
                        ArgumentTypeDescription
                        JIDStringJid of the chat user/group

                        To get Video, Image, and Audio messages a conversation, call the below method. It is used in view all media to get array of messages group by month

                          ChatManager.getVideoImageAudioMessageGroupByMonth(jid: jid) { (isSuccess, flyError, resultDict) in
                          }
                          ArgumentTypeDescription
                          jidStringjid of the chat user/group

                          Unread count#

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

                            let (messageCount, chatCount) = ChatManager.getUNreadMessageAndChatCount()