Callback Delegates

FlyCompletionHandler#

FlyCompletionHandler is used as a base callback block for most of the IO operations.

public typealias FlyCompletionHandler = (_ isSuccess: Bool,_ error: FlyError? , _ data : [String: Any]) -> Void

Observe Chat Connection#

To observe the chat connection status you must adopt a protocol 'ConnectionEventDelegate' through ChatManager

extension YourViewControleler : ConnectionEventDelegate {
func onConnected()
func onDisconnected()
func onConnectionNotAuthorized()
}
ChatManager.shared.connectionDelegate = self

Observe Profile Events#

To observe profile related events you can must adopt a protocol 'ProfileEventsDelegate' through ContactsManager

Example:

extension YourViewControleler : ProfileEventsDelegate {
func usersProfilesFetched() {}
func userBlockedMe(jid : String) {}
func userUnBlockedMe(jid : String) {}
func userUpdatedTheirProfile(for jid : String, profileDetails:ProfileDetails) {}
func myProfileUpdated() {}
func userCameOnline(for jid : String) {}
func userWentOffline(for jid : String) {}
func usersBlockedMeListFetched(jidList : [String]) {}
func usersIBlockedListFetched(jidList : [String]) {}
func blockedThisUser(jid : String) {}
func unblockedThisUser(jid : String) {}
func hideUserLastSeen() {}
func getUserLastSeen() {}
}
ContactManager.shared.profileDelegate = self

Contacts Profiles Fetched.#

If the client application has mobile number as the primary identifier of the user and enabled contact sync they can fetch their contacts data and its completion is triggered in the following callbacks.

ContactManager.getRoster() //Start fetching the users data asynchronously
@Override
public void usersProfilesFetched() {
// User Profiles Fetching done Update the UI
}

User blocked you#

If a user blocked you then the following method will be triggered in the ProfileEventsDelegate.

public func userBlockedMe(jid: String) { {
//jid will be user's Jid who blocked you
}

User unblocked you#

If a user unblocked you then the following method will be triggered in the ProfileEventsDelegate.

@Override
public void userUnBlockedMe(@NotNull String jid) {
//jid will be user's Jid who unblocked you
}

User Updated his profile#

If a user updated his profile then the following method will be triggered in the ProfileEventsDelegate.

public func userUpdatedTheirProfile(for jid: String, profileDetails: ProfileDetails) {
//jid will be user's Jid who updated his profile
}

My Profile update status#

Once you initiated the update for your profile its status will be triggered by the following method in the ProfileEventsDelegate.

func myProfileUpdated() {
}

User came online#

If a user came online then the following method will be triggered in the ProfileEventsDelegate.

func userCameOnline(for jid : String) () {
//jid will be user's Jid who just came online
}

User went offine#

If a user went offline then the following method will be triggered in the ProfileEventsDelegate.

func userWentOffline(for jid : String) {
//jid will be user's Jid who just went offline
}

Users blocked me list callback#

When called to get the users who blocked me then the following method will be triggered in the ProfileEventsDelegate.

func usersBlockedMeListFetched(jidList : [String]) {
//jidList will be list of user's Jid who blocked you
}

Users i blocked list callback#

When called to get the users who i blocked then the following method will be triggered in the ProfileEventsDelegate.

func usersIBlockedListFetched(jidList : [String]) {
//jidList will be list of user's Jid who i blocked
}

User profile fetched#

When called to get the profile detatil of a user from the server then the following method will be triggered in the ProfileEventsDelegate.

@Override
func userProfileFetched(for jid:String, profileDetails:ProfileDetails?) {
//profileDetails will be the ProfileDetails object of the requested user
}

Block a user#

When called to block a user then the following method will be triggered in the ProfileEventsDelegate.

func blockedThisUser(jid : String) {
//jid will be user's Jid who i blocked just now
}

UnBlock a user#

When called to unblock a user then the following method will be triggered in the ProfileEventsDelegate.

func unblockedThisUser(jid : String) {
//jid will be user's Jid who i unblocked just now
}

Observe Group Events#

To observe group related events you must adopt a protocol GroupEventsDelegate

Example:

GroupManager.shared.groupDelegate = self
func didGroupDeleteLocally(groupJid: String) {
}
func didReceiveGroupNotificationMessage(message: ChatMessage) {
}
func didLeftFromGroup(groupJid: String, leftUserJid: String) {
}
func didRemoveMemberFromAdmin(groupJid: String, removedAdminMemberJid: String, removedByMemberJid: String) {
}
func didMakeMemberAsAdmin(groupJid: String, newAdminMemberJid: String, madeByMemberJid: String) {
}
func didFetchGroups(groups: [ProfileDetails]) {
}
func didFetchGroupMembers(groupJid: String) {
}
func didRemoveMemberFromGroup(groupJid: String, removedMemberJid: String, removedByMemberJid: String) {
}
func didAddNewMemeberToGroup(groupJid: String, newMemberJid: String, addedByMemberJid: String) {
}
func didGroupCreate(message : String) {
}
func didFetchGroupProfile(groupJid: String) {
}
func didUpdateGroupProfile(groupJid: String) {
}

Group Profile Fetched#

When the request for fetching a group profile is completed successfully this delegate will be triggered.

func didFetchGroupProfile(groupJid: String) {
//Group profile data fetched successfully
}

Group notification message received#

When events like new member added or member removed a notification message will be generated locally and inserted in the local database. After insertion this delegate will be triggered.

func didReceiveGroupNotificationMessage(message: ChatMessage) {
//Group Notification message received
}

New group created#

When a new group was created like when someone added you to a group this delegate will be triggered.

func didCreateGroup(groupJid: String) {
//New group created
}

Group profile updated#

When a group profile is updated this delegate will be triggered.

func didUpdateGroupProfile(groupJid: String) {
//Group profile updated
}

New member added to group#

When a new member is added to the group this delegate will be triggered.

func didAddNewMemeberToGroup(groupJid: String, newMemberJid: String, addedByMemberJid: String) {
//New member added to a group successfully
}

Member removed from group#

When a member is removed from the group this delegate will be triggered.

func didRemoveMemberFromGroup(groupJid: String, removedMemberJid: String, removedByMemberJid: String) {{
// A group member was removed
}

Fetching group members#

When a group is created, members of that group will be fetched once sucessfully fetched this delegate will be triggered.

func didFetchGroupMembers(groupJid: String) {{
// Members of a group fetched successfully
}

Group member became an admin#

When a group member became an admin this delegate will be triggered.

func didMakeMemberAsAdmin(groupJid: String, newAdminMemberJid: String, madeByMemberJid: String) {
// A group member was made an admin
}

Admin access revoked#

When a group member's admin access is revoked this delegate will be triggered.

func didRemoveMemberFromAdmin(groupJid: String, removedAdminMemberJid: String, removedByMemberJid: String) {
// A group admin access was revoked
}

Member left from the group#

When a member left the group this delegate will be triggered.

func didLeftFromGroup(groupJid: String, leftUserJid: String) { {
// A group member left from the group
}

Group deleted locally#

When the current user delete a group locally this delegate will be triggered.

func didDeleteGroupLocally(groupJid: String) {
// A group was deleted locally
}

Observing the message events#

You need to conform the MessageEventsDelegate protocol to observe all the message related events, so that you can update the UI immediately based on the message events.Once you have sent the message via sdk, you will get the callbacks for message status events.You can attach your own listener by using the below method. This is common for both single chat and groups.

tip

There can be only one message listener at a time, if you set multiple times using the below method it will always replace the old listener.

@objc public protocol MessageEventsDelegate : NSObjectProtocol {
/**
Called when the a new message is received in all types of chat
*/
func onMessageReceived(message : ChatMessage, chatJid: String)
/**
Called when the receipts from the other users or server for a particular message sent by you or received by you is updated.
*/
func onMessageStatusUpdated(messageId: String, chatJid: String, status : MessageStatus)
/**
Called when upload or download of a media file is completed successfully
*/
func onMediaStatusUpdated(message : ChatMessage)
/**
Called when the progress of upload or download of a media file is changed
*/
func onUploadDownloadProgressChanged(messageId: String, chatJid: String, progressPercentage: Int)
/**
Called when the message/conversation deleted for the chat user.
*/
func onMessagesClearedOrDeleted(messageIds: Array<String>)
/**
Called whenever a notification needed to be shown or updated or cancelled
*/
func showOrUpdateOrCancelNotification()
}
info

For group, message status will be updated only if all the participants sent the delivery/seen status.

Handling Banned User/Group#

Current User#

To observe current user blocking/unblocking, confirm to AdminBlockCurrentUserDelegate

public protocol AdminBlockCurrentUserDelegate : NSObjectProtocol {
// Called when current user is blocked or unblocked
func didBlockOrUnblockCurrentUser(userJid : String, isBlocked : Bool)
}

Contacts and Group#

To observe contact and group blocking/unblocking, confirm to AdminBlockDelegate

public protocol AdminBlockDelegate : NSObjectProtocol {
// Called when contact is blocked or unblocked
func didBlockOrUnblockContact(userJid : String, isBlocked : Bool)
// Called when current user is blocked or unblocked
func didBlockOrUnblockSelf(userJid : String, isBlocked : Bool)
// Called when group is blocked or unblocked
func didBlockOrUnblockGroup(groupJid : String, isBlocked : Bool)
}