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 (@).
| Argument | Type | Description |
|---|---|---|
| groupId | String | unique groupId for preparing group JID |
- Swift
- Objective-C
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.
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupName | String | Name 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) |
| groupImageFileUrl | String | local file url of the image (can be empty) |
| completionHandler | FlyCompletionHandler | implemented 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.
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupJid | String | groupJid of a group |
| fetchFromServer | Bool | if fetchFromServer is true, prfoile details will be fetched from server or else (false) from local |
| completionHandler | FlyCompletionHandler | callback to get success or failure response. implemented as closure expression |
Get Participants#
To get group members from the server, call below method
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupJID | String | groupJid 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
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupId | String | jid 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) |
| completionHandler | FlyCompletionHandler | callback 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
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupId | String | jid of a group |
| removeGroupMemberJid | String | jid of participant to be removed from group, who is member of this group) |
| completionHandler | FlyCompletionHandler | callback 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
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| fetchFromServer | Bool | if fetchFromServer is true, groups will be feteched from server or else from local |
| completionHandler | FlyCompletionHandler | callback 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
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupJid | String | jid of the group |
| groupProfileImageUrl | String | local file url (image path) of the image |
| completionHandler | FlyCompletionHandler | implemented 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
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupJid | String | jid of the group |
| completionHandler | FlyCompletionHandler | implemented 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
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupJid | String | jid of the group |
| groupName | String | group name (should not be null or empty) |
| completionHandler | FlyCompletionHandler | implemented 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.
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupJid | String | jid of the group |
| userJid | String | jid of the participant, to make as admin |
| completionHandler | FlyCompletionHandler | implemented 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
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupJid | String | jid of the group |
| userJid | String | jid of the participant, to exit from the group |
| completionHandler | FlyCompletionHandler | implemented 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
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupJid | String | jid of the group to be deleted |
| completionHandler | FlyCompletionHandler | implemented 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
- Swift
- Objective-C
| Return Type | Description |
|---|---|
Int | returns the count of group from local DB |
Check admin user#
To check a member is admin, call below method
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupJid | String | jid of the group |
| participantJid | String | participantJid to check admin user |
| Returns | Type | Description |
|---|---|---|
| (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
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupJid | String | jid of the group |
| participantJid | String | participantJid to check existance in the group |
| Returns | Type | Description |
|---|---|---|
| (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.
- Swift
- Objective-C
| Argument | Type | Description |
|---|---|---|
| groupJid | String | jid of the group |
| Returns | Type | Description |
|---|---|---|
| (participantDetailArray : [GroupParticipantDetail] , message : String) | Tuple ([GroupParticipantDetail] ,String) | [GroupParticipantDetail] array of participant detail. message : response message |