Profile module

All the contact related operation will be found below.

Enable Contact Sync#

To enable/Disable contact sync call the below method.

ChatManager.enableContactSync(isEnable: ENABLE_CONTACT_SYNC)
ArgumentTypeDescription
ENABLE_CONTACT_SYNCBoolif true Contact Sync will be enabled at SDK level

Contact Sync#

If contact sync is enabled in ChatSDK builder,then phone book contacts can be synced with the server by calling the below method. Once the contacts were synced successfully it will let the user communicate with their contacts who uses the client app too.

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.getFriendsList() method will be called internally to fetch the profile data of the phone contacts who are all installed the client app.

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

Friends#

The contacts who are in your contacts after the contact sync is considered as your friends, those people's only observe your profile and presence updates.

ProfileDetails#

Every single chat contact has been modelled after ProfileDetails class. It holds the data of a user name, display picture, whether you blocked them or not etc. Refer Class documentation to know about ProfileDetails Class

Get Friends List#

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

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

Refer Class documentation to know about ProfileDetails Class

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

Get User profile data#

To get the profile data of a user(not a group) call the below method.

ContactManager.shared.getUserProfile(USER_JID,FETCH_FROM_SERVER,SAVE_AS_FRIEND){ isSuccess, flyError, flyData in
var data = flyData
if isSuccess {
let profileDetail = data.getData() as! [ProfileDetails]
} else{
print(flyError!.localizedDescription)
}
}
ArgumentTypeDescription
USER_JIDStringJid of the user
FETCH_FROM_SERVERBooltrue to fetch from server false will fetch from local database
SAVE_AS_FRIENDBoolif true the user will be saved as friend and will be available in list of contacts to chat
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

Update your profile info#

To update your profile call the below method.

ContactManager.shared.updateMyProfile(PROFILE_OBJECT){ isSuccess, flyError, flyData in
if isSuccess {
// Profile updated successfully update the UI
} else{
print(flyError!.localizedDescription)
}
}
info

In profile object for image property set the absolute file path of a file if a image file needs to be uploaded or else set it to profile image id.

ArgumentDescriptionData type
PROFILE_OBJECTProfileProfile object which the updated value
CALLBACKFlyCallbackFlyCallback implemented as as lambda expression

Remove Profile Image#

To remove your profile image call the below method.

ContactManager.shared.removeProfileImage(){ isSuccess, flyError, flyData in
if isSuccess {
// Profile Image removed successfully update the UI
} else{
print(flyError!.localizedDescription)
}
}
ArgumentTypeDescription
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

Enable disable hide seen status#

Hide Last seen status enables the user's last logged in time unavailable to their friends. To enable or disable the hide last seen status of the user call the below method.

Block a User#

To block a user call the below method.

ContactManager.shared.blockUser(for: JID_TO_BLOCK){ isSuccess, flyError, flyData in
if isSuccess {
//User is blocked update the UI
} else{
print(flyError!.localizedDescription)
}
}
ArgumentTypeDescription
JID_TO_BLOCKStringJID of the user
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

Unblock a User#

To unblock a user who is blocked already call the below method.

ContactManager.shared.unblockUser(for: JID_TO_UNBLOCK){ isSuccess, flyError, flyData in
if isSuccess {
//User is unblocked update the UI
} else{
print(flyError!.localizedDescription)
}
}
ArgumentTypeDescription
JID_TO_UNBLOCKStringJID of the user
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler
caution

Blocking and Unblocking valid for Single chat user only not for Group/Broadcast.

Get user profiles that you blocked#

To get the list of chat user profiles that you blocked call the below method.

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

Refer Class documentation to know about ProfileDetails Class

ArgumentDescriptionData type
FETCH_FROM_SERVERtrue to fetch from server false will fetch from local databaseBool
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

Note : To make server call internet connection is required

Get user profiles that blocked you#

To get the list of single chat user that blocked you call the below method.

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

Refer Class documentation to know about ProfileDetails Class

ArgumentDescriptionData type
FETCH_FROM_SERVERtrue to fetch from server false will fetch from local databaseBool
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

Note : To make server call internet connection is required

Enable disable hide seen status#

Hide Last seen status enables the user's last logged in time unavailable to their friends. To enable or disable the hide last seen status of the user call the below method.

ChatManager.shared.enableDisableHideLastSeen( EnableLastSeen: lastSeen) { isSuccess, flyError, flyData in
var data = flyData
if isSuccess {
print(data.getMessage() as! String )
} else{
print(data.getMessage() as! String )
}
}
ArgumentTypeDescription
EnableLastSeenBooltrue enables the last seen available to friends false disables it
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

Check last seen status#

To check whether last seen status is available to friends or not, call the below method.

var lastSeenStatus = Bool()
lastSeenStatus = ChatManager.isLastSeenEnabled()

Get last seen status#

To get whether last seen status is available to friends or not, call the below method.

ChatManager.shared.getUserLastSeen( for: JID_STRING) { isSuccess, flyError, flyData in
var data = flyData
if isSuccess {
print(data.getMessage() as! String )
print(data.getData() as! String )
} else{
print(data.getMessage() as! String )
}
}
ArgumentTypeDescription
JID_TO_GETLASTSEENStringJID of the user
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

Delete My Account#

To delete your chat account call the below method. This will clear your profile,login information and messages(including media files) in the server as well as in your device. No information will be retained after account deletion. And if registration is made again with the same account it will be treated as a new account.

ContactManager.shared.deleteMyAccountRequest(REASON, FEEDBACK) { isSuccess, flyError, flyData in
var data = flyData
print(data.getMessage() as! String )
if isSuccess {
// Clear necessary data and redirect to login page
} else{
// Show error in UI
}
}
ArgumentTypeDescription
REASONStringReason for the account deletion
FEEDBACKStringFeedback for tha app if any
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler
caution

Once account is deleted the user will be removed from every group in which is he/her is a participant.