Retrieve Recent Chats

Get Recent Chat#

To get the recent chat of a user or a group.

    let recentChat: RecentChat = ChatManager.getRecentChatOf(jid:jid)

    Refer this doc to know more about RecentChat Class

    ArgumentTypeDescription
    JIDStringjid of the user/group
    caution

    Will return a null object if a user never made a conversation with that user/group.

    Get Recent Chat list#

    To get the recent chat list

      ChatManager.getRecentChatList()
      or
      ChatManager.getRecentChatList { isSuccess, error, data in
      }

      Provides recent chat list without Archive

      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"
        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 default50

        Secondly, create a FetchMessageListQuery instance.

          let messageListQuery = 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, 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#

                      let fetchingInProgress: Bool = messageListQuery.isFetchingInProgress()

                      Get RecentChat by pagination#

                      Create a RecentChatListParams instance. Here, you can set the recentchat filter options .

                        let recentChatListParams = RecentChatListParams()
                        recentChatListParams.limit = "LIMIT"
                        ArgumentTypeDescription
                        LIMITIntNo of recent chats will be fetched for each request default 40

                        Secondly, create a RecentChatListBuilder instance.

                          let recentChatListBuilder = RecentChatListBuilder(RECENT_LIST_PARAM)
                          ArgumentTypeDescription
                          RECENT_LIST_PARAMRecentChatListParamsInsatance of 'RecentChatListParams

                          Load Initial RecentChats#

                          To fetch initial set of recentChat data, call the below method.

                            recentChatBuilder.loadRecentChatList { isSuccess, flyError, flyData in
                            var data = flyData
                            if (isSuccess) {
                            let recentChatArray = data.getData() as? [RecentChat]
                            } else {
                            // Fetch recentchat failed print error to know more about the exception
                            }
                            }
                            ArgumentTypeDescription
                            CALLBACKFlyCompletionHandlerFlyCompletionHandler implemented as closures

                            Load Next RecentChats#

                            To fetch next set of recentChats, call the below method.

                              recentChatBuilder.nextSetOfData { { isSuccess, flyError, flyData in
                              var data = flyData
                              if (isSuccess) {
                              let recentChatArray = data.getData() as? [RecentChat]
                              } else {
                              // Fetch recentchat failed print error to know more about the exception
                              }
                              }
                              ArgumentTypeDescription
                              CALLBACKFlyCompletionHandlerFlyCompletionHandler implemented as closures

                              Get Recent Chat list with archived chats#

                              To get the recent chat list including the arhived chat conversation call the below method.

                                let recentChatList: [RecentChat] = ChatManager.getRecentChatListIncludingArchived()

                                Unread count#

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

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