Group chat

Prerequisites#

In order to send messages using the chat sdk , at first you need to establish the connection to the server. sdk provides methods for initializing the connection configuration as well as methods for making connection.

Note: Even if you don't have internet connection, you are still allowed to send messages which will be kept in offline database.Once the user connected to the internet, the messages will be sent automatically when user opens the app.

Preparing Group chat jid#

SDK provieds the below utility method to preparing group JID. FlyUtils.getGroupJid(groupId : String)

Note: The below characters is not allowed in uniqueId: U+0022 (") U+0026 (&) U+0027 (') U+002F (/) U+003A (:) U+003C (<) U+003E (>) U+0040 (@).

ArgumentTypeDescription
groupIdStringunique groupId for preparing group JID
try FlyUtils.getGroupJid(groupId : String)
caution

If group chat feature unavailable for your plan then below methods will throw 403 exception.

Create a Group#

To create a group, call the below method.

try GroupManager.shared.createGroup(groupName: "ABCXYZ", participantJidList: [jids], groupImageFileUrl: "", completionHandler: { [self] isSuccess, flyError, flyData in
if isSuccess {
// Update the UI
} else{
// failure case of the group creation
}
})
ArgumentTypeDescription
groupNameStringName of the group (cannot be null or empty)
participantJidList[String]Array of jids of the member (size cannot be less than 2 excluding group creator)
groupImageFileUrlStringlocal file url of the image (can be empty)
completionHandlerFlyCompletionHandlerimplemented as closure expression

Note: Even if you don't have internet connection, you are still allowed to send messages which will be kept in offline database.Once the user connected to the internet, the messages will be sent automatically when user opens the app.

Get Group Profile#

To get a group profile from server or local, call below method.

try GroupManager.shared.getGroupProfile(groupJid: groupId, fetchFromServer: fromServer, completionHandler: { isSuccess, flyError, flyData in
if isSuccess {
let data = (flyData.getData() as? ProfileDetails)
// Update the UI
} else{
// failure case of get group profile
}
})
ArgumentTypeDescription
groupJidStringgroupJid of a group
fetchFromServerBoolif fetchFromServer is true, prfoile details will be fetched from server or else (false) from local
completionHandlerFlyCompletionHandlercallback to get success or failure response. implemented as closure expression

Get Participants#

To get group members from the server, call below method

GroupManager.shared.getParticipants(groupJID: groupId)
ArgumentTypeDescription
groupJIDStringgroupJid of a group
info

if getParticipants(groupJID: groupId) is success, didFetchGroupMembers(groupJid: String) method will be called, which is defined in GroupEventsDelegate.

Add Participants to a group#

To add participants to a group, call below method

try GroupManager.shared.addParticipantToGroup(groupId: groupId, newUserJidList: selectedItemArray) { isSuccess, flyError, flyData in
if isSuccess {
// Update the UI
} else{
// failure cases
}
ArgumentTypeDescription
groupIdStringjid of a group
newUserJidList[String]array of jid list to be added in group (jid list should not contain jid, which is already exiting in same group)
completionHandlerFlyCompletionHandlercallback to get success or failure response. implemented as closure expression
info

if addParticipantToGroup is success, func didAddNewMemeberToGroup(groupJid : String, newMemberJid : String, addedByMemberJid : String) method will be called, which is defined in GroupEventsDelegate.

Remove a Participant from a group#

To remove a participant from a group, call below method

try GroupManager.shared.removeParticipantFromGroup(groupId: groupId, removeGroupMemberJid: userJid) { isSuccess, flyError, flyData in
if isSuccess {
// Update UI
} else{
// failure cases
}
}
ArgumentTypeDescription
groupIdStringjid of a group
removeGroupMemberJidStringjid of participant to be removed from group, who is member of this group)
completionHandlerFlyCompletionHandlercallback to get success or failure response. implemented as closure expression
info

if removeParticipantFromGroup is success, func didRemoveMemberFromGroup(groupJid : String, removedMemberJid : String, removedByMemberJid : String) method will be called, which is defined in GroupEventsDelegate.

Get Groups#

To get groups from local or server, call below method

GroupManager.shared.getGroups(fetchFromServer: true) { isSuccess, flyError, flyData in
var data = flyData
if isSuccess {
// Update UI
} else{
// failure cases
}
}
ArgumentTypeDescription
fetchFromServerBoolif fetchFromServer is true, groups will be feteched from server or else from local
completionHandlerFlyCompletionHandlercallback to get success or failure response. implemented as closure expression
info

func didFetchGroups(groups : [ProfileDetails], message : String) method will be called, which is defined in GroupEventsDelegate.

Add or Update Group Image#

Too add or update group image, call below method

try GroupManager.shared.updateGroupProfileImage(groupJid: groupId, groupProfileImageUrl: selectPath, completionHandler: { isSuccess, flyError, flyData in
if isSuccess {
// Update UI
} else{
// failure case
}
})
ArgumentTypeDescription
groupJidStringjid of the group
groupProfileImageUrlStringlocal file url (image path) of the image
completionHandlerFlyCompletionHandlerimplemented as closure expression
info

func didUpdateGroupProfile(groupJid: String) method will be called, which is defined in GroupEventsDelegate.

Remove Group Image#

To remove group image, call below method

try GroupManager.shared.removeGroupProfileImage(groupJid: groupId, completionHandler: { isSuccess, flyError, flyData in
if isSuccess {
// Updat UI in success case
} else{
// failure case
}
})
ArgumentTypeDescription
groupJidStringjid of the group
completionHandlerFlyCompletionHandlerimplemented as closure expression
info

func didUpdateGroupProfile(groupJid: String) method will be called, which is defined in GroupEventsDelegate.

Update a Group Name#

To update a group name, call below method

try GroupManager.shared.updateGroupName(groupJid: groupId, groupName: "Changing Group Name wXyZ 123", completionHandler: { isSuccess, flyError, flyData in
if isSuccess {
// Update UI
} else{
// failure case
}
})
ArgumentTypeDescription
groupJidStringjid of the group
groupNameStringgroup name (should not be null or empty)
completionHandlerFlyCompletionHandlerimplemented as closure expression
info

func didUpdateGroupProfile(groupJid: String) method will be called, which is defined in GroupEventsDelegate.

Make a participant as Admin#

To make a participant as admin, call below method. Admin only can make a participant as admin.

try GroupManager.shared.makeAdmin(groupJid: groupId, userJid: userJid, completionHandler: { isSuccess, flyError, flyData in
if isSuccess {
// update UI
} else{
// failure case
}
})
ArgumentTypeDescription
groupJidStringjid of the group
userJidStringjid of the participant, to make as admin
completionHandlerFlyCompletionHandlerimplemented as closure expression
info

func didMakeMemberAsAdmin(groupJid: String, newAdminMemberJid : String, madeByMemberJid : String) and func didGroupInfoUpdatedWithId(groupJid: String) method will be called, these are defined in GroupEventsDelegate.

Exit from a Group#

To exit from a group, call below method

try GroupManager.shared.leaveFromGroup(groupJid: groupId, userJid: userJid, completionHandler: { isSuccess, flyError, flyData in
if isSuccess {
// update UI
} else{
// failure case
}
})
ArgumentTypeDescription
groupJidStringjid of the group
userJidStringjid of the participant, to exit from the group
completionHandlerFlyCompletionHandlerimplemented as closure expression
info

func didLeftFromGroup(groupJid: String, leftUserJid: String) method will be called, these are defined in GroupEventsDelegate.

Delete a Group#

To delete a group, call below method Before delete a group, participant should be left the group

try GroupManager.shared.deleteGroup(groupJid: groupId, completionHandler: { isSuccess, flyError, flyData in
if isSuccess {
// update UI
} else{
// failure case
}
})
ArgumentTypeDescription
groupJidStringjid of the group to be deleted
completionHandlerFlyCompletionHandlerimplemented as closure expression
info

didDeleteGroupLocally(groupJid: String) method will be called, which is defined in GroupEventsDelegate.

Get Group Count#

To get group count from local DB, call below method

let groupCount: Int = GroupManager.shared.getGroupCount()
Return TypeDescription
Intreturns the count of group from local DB

Check admin user#

To check a member is admin, call below method

let (isAdmin, message) = GroupManager.shared.isAdmin(participantJid : jid, groupJid : groupId)
ArgumentTypeDescription
groupJidStringjid of the group
participantJidStringparticipantJid to check admin user
ReturnsTypeDescription
(isAdmin : Bool,message :String)Tuple (Bool,String)isAdmin is true, if participantJid is admin. message : response message

Participant Existance in a Group#

To check a participant existance in a group, call below method

let (isExist, message) = GroupManager.shared.isParticiapntExistingIn(groupJid: groupId, participantJid: jid)
ArgumentTypeDescription
groupJidStringjid of the group
participantJidStringparticipantJid to check existance in the group
ReturnsTypeDescription
(doesExist : Bool, message : String)Tuple (Bool,String)doesExist is true, if participantJid is existing in the group. message : response message

Get Group Members from Local#

To get group member from local DB, call below method.

let groupMembers: [GroupParticipantDetail] = GroupManager.shared.getGroupMemebersFromLocal(groupJid : groupId)
ArgumentTypeDescription
groupJidStringjid of the group
ReturnsTypeDescription
(participantDetailArray : [GroupParticipantDetail] , message : String)Tuple ([GroupParticipantDetail] ,String)[GroupParticipantDetail] array of participant detail. message : response message