Group chat modules

Groups is the simplest way to chat with multiple user at any given time.

Preparing group chat jid#

Almost of the sdk methods expect jid as a input parameter, so sdk provides below utility method to prepare the group jid from the group id. The method prepares the group chat jid from the given string by using chat config provided via [com.contusflysdk.api.ChatConnectionManager.initialize] method.

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

String groupJid = FlyUtils.getGroupJid(GROUP_ID)
ArgumentTypeDescription
GROUP_IDStringId of the group
caution

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

Create Group#


To create a group with image url to be uploaded as group profile image call the below method.

GroupManager.createGroup(GROUP_NAME, MEMBERS_JID_LIST, GROUP_IMAGE_ID , (isSuccess, throwable, data) -> {
if(isSuccess){
//Update the UI
}else{
// Group creation failed print throwable to find the exception details.
}
});
ArgumentTypeDescription
GROUP_NAMEStringName of the group(cannot be null or empty)
MEMBERS_JID_LISTList<String>List of jids of the member (size cannot be less than 2
excluding group creator)
GROUP_IMAGE_IDStringurl id of the uploaded image (can be empty)
CALLBACKFlyCallbackFlyCallback implemented as lambda expression
info

There is an overloading method available for createGroup which accepts image as a File instead of url id.


To create a group with image file to be uploaded as group profile image call the below method.

GroupManager.createGroup(GROUP_NAME, MEMBERS_JID_LIST, GROUP_IMAGE_FILE , (isSuccess, throwable, data) -> {
if(isSuccess){
//Update the UI
}else{
// Group creation failed print throwable to find the exception details.
}
});
ArgumentTypeDescription
GROUP_NAMEStringName of the group(cannot be null or empty)
MEMBERS_JID_LISTList<String>List of jids of the member (size cannot be less than 2
excluding group creator)
GROUP_IMAGE_FILEFileimage file to be uploaded as group profile image(can be empty)
CALLBACKFlyCallbackFlyCallback implemented as lambda expression
caution

If there is no internet or the connection between chat server and the app isn't made create group functionality will be executed and group will be created locally. Until the group is available in server messaging/profile update should be restricted in app side by checking the isGroupInOfflineMode property of RecentChat or ProfileDetails class else an exception will be thrown.

Move offline group to online#

To move the group which is created locally to online(create in server) call the below method.

GroupManager.createOfflineGroupInOnline(GROUP_JID, (isSuccess, throwable, data) -> {
if(isSuccess){
// Group created in server update the UI
}else{
// Group creation failed print throwable to find the exception details.
}
});
ArgumentTypeDescription
GROUP_JIDStringJid of the offline group
CALLBACKFlyCallbackFlyCallback implemented as lambda expression

Group profile Update#

Update group name#

User can able to update group name whenever they want by using the below method.

GroupManager.updateGroupName(GROUP_JID,GROUP_NAME, LISTENER);
ArgumentTypeDescription
GROUP_JIDStringjid of the group
GROUP_NAMEStringnew name for the group which has to updated
LISTENERChatActionListenerlistener callback to observe the action status

Update group profile image#

User can able to update group profile image whenever they want by using the below method.

To update group profile image as either file or by using uploaded image id:

GroupManager.updateGroupProfileImage(GROUP_JID,IMAGE_FILE, LISTENER);
GroupManager.updateGroupProfileImage(GROUP_JID,IMAGE_ID, LISTENER);
ArgumentTypeDescription
GROUP_JIDStringJid of the group
IMAGE_FILEFileFile object of the group profile image
IMAGE_IDStringnew profile image as a url which has to updated for the group
LISTENERChatActionListenercallback to observe the action status

Remove group profile image#

User can able to remove group profile image whenever they want by using the below method.

GroupManager.removeGroupProfileImage(GROUP_JID, LISTENER);
ArgumentTypeDescription
GROUP_JIDStringJid of the group
LISTENERChatActionListenercallback to observe the action status
caution

If there is no internet or the connection between chat server and the app isn't made group update functionality will be executed locally once the connection is restored it will be updated for other group members and in the server.

Get profile data#

To get the detail of a group call the below method.

GroupManager.getGroupProfile(GROUP_JID,FETCH_FROM_SERVER, (isSuccess, throwable, data) ->
if(isSuccess){
ProfileDetails groupProfileDetails = (ProfileDetails) data.get("data")
// Update the UI
}else{
// Fetching group data failed print throwable to find the exception details.
}
});
ArgumentsTypeDescription
GROUP_JIDStringJid of the group
FETCH_FROM_SERVERbooleanif true fetches data from the server else from local database
CALLBACKFlyCallbackFlyCallback implemented as lambda expression

Get all Groups#

To fetch all the groups in which you are member of call the below method.

GroupManager.getAllGroups(GET_SERVER_DATA, (isSuccess, throwable, data) ->
if(isSuccess){
ArrayList<ProfileDetails> groupsProfileList = (ArrayList<ProfileDetails>) data.get("data")
// Update the UI
}else{
// Fetching group list failed print throwable to find the exception details.
}
});
caution

Need to call getAllGroups atlas once after user login so that the all the groups info will be fetched and saved in local DB else no group related data will be available.

ArgumentTypeDescription
GET_SERVER_DATAbooleanif true fetches data from the server else fetches data from local database
CALLBACKFlyCallbackFlyCallback implemented as lambda expression

Get Group Members#


To fetch all the groups members of a group call the below method.

GroupManager.getGroupMembersList(GET_SERVER_DATA,GROUP_JID, (isSuccess, throwable, data) ->
if(isSuccess){
ArrayList<ProfileDetails> groupsMembersProfileList = data.get("data")
// Update the UI
}else{
// Fetching group members list failed print throwable to find the exception details.
}
});
caution

Fetching group members from a server will be called internally when required. So , unless it was necessary set false for getServerData.

ArgumentTypeDescription
GET_SERVER_DATAbooleanif true fetches data from the server else fetches data from local database
GROUP_JIDStringJid of the group
CALLBACKFlyCallbackFlyCallback implemented as lambda expression

Check User is a member#


To check whether a user of a given jid is a member of the group

boolean isMember = GroupManager.isMemberOfGroup(GROUP_ID, USER_JID);
ArgumentTypeDescription
GROUP_IDStringJid of the group
USER_JIDStringJid of the user

Validate Members list server call#

To check whether a server call to get the members list for a group is required or not call the below method.

boolean doesServerCallRequired = GroupManager.doesFetchingMembersListFromServedRequired(GROUP_JID);
ArgumentTypeDescription
GROUP_JIDStringJid of the group

Group members count#


To get count of members in a group call the below method.

int groupMembersCount = GroupManager.getMembersCountOfGroup(GROUP_JID);
ArgumentsData typeDescription
GROUP_JIDStringJid of the group

Get user list to add to a group#

To get the list of users who are eligible to add to a group while creating or to a old group call one of the the below method.

List<ProfileDetails> usersList = GroupManager.getUsersListToAddMembersInNewGroup();
List<ProfileDetails> usersList = GroupManager.getUsersListToAddMembersInOldGroup(GROUP_JID);
warning

Those two methods above are available only if contact sync is enabled.

ArgumentTypeDescription
GROUP_JIDStringJid of the group

Add user to Group#

To add users to a group call the below method.

GroupManager.addUsersToGroup(GROUP_JID,NEW_USERS_JID_LIST, (isSuccess, throwable, data) ->
if(isSuccess){
// Update the UI
}else{
// Adding users to group failed print throwable to find the exception details.
}
});
ArgumentTypeDescription
GROUP_JIDStringJid of the group
NEW_USERS_JID_LISTList<String>Jid list of the new users
CALLBACKFlyCallbackFlyCallback implemented as lambda expression

Remove a group member#


To remove a user from group call the below method.

GroupManager.removeMemberFromGroup(GROUP_JID,REMOVING_MEMBER_JID, (isSuccess, throwable, data) ->
if(isSuccess){
// Update the UI
}else{
// Removing a user from group failed print throwable to find the exception details.
}
});
ArgumentTypeDescription
GROUP_JIDStringJid of the group
REMOVING_MEMBER_JIDStringJid of the user who is going to be removed
CALLBACKFlyCallbackFlyCallback implemented as lambda expression

Make participant as admin#

User can able to make some participant of the group as a admin to the group. The below method can be used to make someone as admin. only admins can perform this action

GroupManager.makeAdmin(GROUP_JID, NEW_ADMIN_JID, LISTENER);
ArgumentTypeDescription
GROUP_JIDStringjid of the group
NEW_ADMIN_JIDStringjid of the group participant
LISTENERChatActionListenercallback to observe the action status

Check group admin#

User can able to check some participant of the group is a admin or not to the group. The below method can be used to check someone admin or not.The below method will return true if userJid is admin for the provided groupJid.

boolean isAdmin = GroupManager.isAdmin(GROUP_JID, USER_JID);
ArgumentTypeDescription
GROUP_JIDStringJid of the group
USER_JIDStringJid of the group participant

Group messaging#

Group messaging is very similiar to the single chat messaging. Instead of giving single chat jid , you need to provide group jid. if you don't have group jid, you can prepare that using the above method by giving group id.

Refer this doc for group messaging

Message Delivered list#

To get the list of users to whom a message was successfully delivered call the below method.

GroupManager.getGroupMessageDeliveredToList(MESSAGE_ID,(isSuccess, throwable, data) ->
if(isSuccess){
List<MessageStatusDetail> messageStatusList = (List<MessageStatusDetail>) data.get("data);
// Update the UI
}else{
// Delivered list fetching failed print throwable to find the exception details.
}
});

Refer this doc to know more about MessageStatusDetail Class

info

Only messages sent by the current user will have the options to get delivered and read list.

ArgumentTypeDescription
MESSAGE_IDStringId of a group message
CALLBACKFlyCallbackFlyCallback implemented as lambda expression

Message Read list#

To get the list of users whom are read/seen the message call the below method.

GroupManager.getGroupMessageReadByList(MESSAGE_ID,(isSuccess, throwable, data) ->
if(isSuccess){
List<MessageStatusDetail> messageStatusList = (List<MessageStatusDetail>) data.get("data);
// Update the UI
}else{
// Read list fetching failed print throwable to find the exception details.
}
});
info

Only messages sent by the current user will have the options to get delivered and read list.

ArgumentTypeDescription
MESSAGE_IDStringId of a group message
CALLBACKFlyCallbackFlyCallback implemented as lambda expression

Get message status count#

To get the count of statuses for a given message id call the below method.

int messageStatuses = FlyMessenger.getGroupMessageStatusCount(MESSAGE_ID);
ArgumentTypeDescription
MESSAGE_IDStringId of the message

Leave from a group#


To leave from a group in which you are a member call the below method.

GroupManager.leaveFromGroup(GROUP_JID,(isSuccess, throwable, data) ->
if(isSuccess){
// Update the UI
}else{
// Leaving from group failed print throwable to find the exception details.
}
});
ArgumentTypeDescription
GROUP_JIDStringJid of the group
CALLBACKFlyCallbackFlyCallback implemented as lambda expression

Delete a group#


To delete a group locally call the below method.

GroupManager.deleteGroup(GROUP_JID,(isSuccess, throwable, data) ->
if(isSuccess){
// Update the UI
}else{
// Deleting group failed print throwable to find the exception details.
}
});
warning

Deleting a group only delete the group data locally its doesn't delete the group in the server or to other users.

ArgumentData typeDescription
GROUP_JIDStringJid of the group
CALLBACKFlyCallbackFlyCallback implemented as lambda expression

Delete offline group#

To delete a offline group which is not yet available online(created in server) call the below method.

GroupManager.deleteOfflineGroup(GROUP_JID);
ArgumentTypeDescription
GROUP_JIDStringJid of the group