Users

User List#

To retrive all registered users on MirrorFly SDK use below method. User list can also be retrived based on search key word, also this method supports pagination. This function will return total page of users.

warning

User presence and Profile instant update will not happen until a messege is sent to that particular user.

    ContactManager.shared.getUsersList(PAGE_NUMBER, PER_PAGE_RESULT_SIZE, SEARCH_TERM){ isSuccess,flyError,flyData in
    if isSuccess{
    var data = flyData
    if let profileArray = data.getData() as? [ProfileDetails]{}
    let totalPages = data["totalPages"] as? Int
    let totalUsers = data["totalRecords"] as? Int
    } else {
    //print error
    }
    });

    Refer this doc to know more about Profile Details Class

    ArgumentTypeDescription
    PAGE_NUMBERintPage number of user list default value 1
    PER_PAGE_RESULT_SIZEintNumber of users per page default value 50
    SEARCH_TERMStringtext characters for which search has to happen default value empty
    META_DATAMetaDataUserListmodel class which filters the results by metadata default value is empty
    CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

    Sync Contact#

    warning

    It will be only applicable for mobile number registration and contact book synchronization.

    If mobile number is used as a primary id for communication in chat sdk then there has to be sync between user and server. The following code block initiate the contact sync and let the user communicate with their contacts who uses the client app too.

    Note : In order to sync mobile contacts need to enable Contact syncing using ChatManager.enableContactSync() method

      ContactSyncManager.shared.syncContacts(){ isSuccess, flyError, flyData in
      var data = flyData
      if isSuccess {
      // Contact synced successfully update the UI
      } else{
      print(data.getMessage() as! String)
      }
      })
      ArgumentTypeDescription
      CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

      Note : To access phone contacts add the Privacy - Contacts Usage Description key and proper description for contact access request value, so the ContactSyncManager class can read phone's contacts for syncing.

      Observe Contact Sync#

      The progress of contact syncing can be observed using the NotificationCenter using the name of FlyConstants.contactSyncState. From the notification's userInfo get the status of the progress using the key FlyConstants.contactSyncState, which gives a string value which can be used as a raw value for the enum type ContactSyncState. The code snippet below shows the show the observer and handling of contact sync progress.

        NotificationCenter.default.addObserver(self, selector: #selector(self.contactSyncCompleted(notification:)), name: NSNotification.Name(FlyConstants.contactSyncState), object: nil)
        @objc func contactSyncCompleted(notification: Notification){
        if let contactSyncState = notification.userInfo?[FlyConstants.contactSyncState] as? String {
        switch ContactSyncState(rawValue: contactSyncState) {
        case .inprogress:
        //Update the UI
        case .success:
        //Update the UI
        case .failed:
        //Update the UI
        }
        }
        }

        Once contact sync is completed successfully, ContactManager.shared.getRegisteredUsers() method will be called internally to fetch the profile data of the phone contacts.

        Note : Remove the Observer for Contact Sync properly to avoid memory leaks.

        Get Registered Users#

        Note : The registered contacts who are in your contacts will retrieved after the contact sync, those people's only observe your profile,user presence updates.

        Once we started communicating , we can get the list of contact with chat data with whom we communicated so far.

          ContactManager.shared.getRegisteredUsers(FETCH_FROM_SERVER) { isSuccess, flyError, flyData in
          var data = flyData
          if isSuccess {
          let profileDetailsArray = data.getData() as! [ProfileDetails]
          } else{
          print(flyError!.localizedDescription)
          }
          }

          Refer this doc to know more about ProfileDetails Class

          ArgumentTypeDescription
          FETCH_FROM_SERVERBooltrue to fetch from server false will fetch from local database
          CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler
          caution

          FlyCompletionHandler which is used as a callback for most of the i/o operation is being expressed as lambda expression for easy reading.