Groups - LOMENT-SDK/sdk-cashew-android GitHub Wiki

To send group messages use below calls:

Create Group:

The first step is to create a group with a name and at least one participant and the person who creates group will be the Main Admin (Owner) of that group:

new MessagingManager().createGroup(this, groupName, members, new CreateConversationCallback() {...}

The create group results are handled in the following callbacks:

@Override
public void onCreateConversationSuccess(CNConversation conversation) {

	//Handle Create Group Success
}

@Override
public void onCreateConversationError(CNError error){
	//Handle Create Group Error
}

Edit Group Name:

Now that the group is created we can change the Name of the group using below group call:

new MessagingManager().editGroupName(context, conversation, newName, new EditGroupNameCallback() {...}

The edit group name results are handled in the following callbacks:

@Override
public void onEditGroupNameSuccess() {

	//Handle Edit Group Name Success
}

@Override
public void onEditGroupNameError(CNError error){
	//Handle Edit Group Name Error

Change Group Owner:

Now that the group is created we can change the Owner of the group using below group call:

new MessagingManager().changeGroupOwner(context, conversation, newOwner, new ChangeGroupOwnerCallback() {...}

The Change Group Owner results are handled in the following callbacks:

@Override
public void onChangeGroupOwnerSuccess() {

	//Handle Change Group Owner Success
}

@Override
public void onChangeGroupOwnerError(CNError error){
	//Handle Change Group Owner Error
}

Add Members to Group:

Now that the group is created we can add members to the group using below group call:

new MessagingManager().addMembersToGroup(context, conversation, contacts, new AddMembersToGroupCallback() {...}

The Add Members to Group results are handled in the following callbacks:

@Override
public void onAddMembersToGroupSuccess() {

	//Handle Add Members to Group Success
}

@Override
public void onAddMembersToGroupError(CNError error){
	//Handle Add Members to Group Error
}

Remove Members from Group:

Now that the group is created and we added members to the group if we want to remove members from Group we can do that using below call:

new MessagingManager().removeMembersFromGroup(context, conversation, contacts, new RemoveMembersFromGroupCallback() {...}

The Remove Members from Group results are handled in the following callbacks:

@Override
public void onRemoveMembersFromGroupSuccess() {

	//Handle Remove Members from Group Success
}

@Override
public void onRemoveMembersFromGroupError(CNError error){
	//Handle Remove Members from Group Error
}

Add Admins to Group:

Now that the group is created and we added members to make some one as Admin on the group then we can do that using below call. This is valid operation if it is performed by group main admin:

new MessagingManager().addAdminsToGroup(context, conversation, contacts, new AddAdminsToGroupCallback() {...}

The Add Admins to Group results are handled in the following callbacks:

@Override
public void onaddAdminsToGroupSuccess() {

	//Handle Add Admins to Group Success
}

@Override
public void onaddAdminsToGroupError(CNError error){
	//Handle Add Admins to Group Error
}

Change Owner of the Group:

Now that the group is created and we added members and made some of the members as Admins and we want to remove them from Admin list then we can do that using below call. This is Valid operation if it is performed by Main admin of group:

new MessagingManager().changeGroupOwner(context, conversation, newOwner, new ChangeGroupOwnerCallback() {...}

The Change Group Owner results are handled in the following callbacks:

@Override
public void onchangeGroupOwnerSuccess() {

	//Handle Change GroupOwner Success
}

@Override
public void onchangeGroupOwnerError(CNError error){
	//Handle Change Group Owner Error
}

Enable / Disable (Any one can add members) Feature:

When a group is created it is created by default with option that Any member of the group can add new members to the group and if we don't want to happen then we can restrict that to only Main admin and Admins then we can do that using below call and this is a valid only if Main admin of the group performs this operation: To enable feature: {2,4} To disable feature: {2}

new MessagingManager().setFeature(context, conversation, featureValue, new EditGroupNameCallback() {...}

The Set Feature results are handled in the following callbacks:

@Override
public void onEditGroupNameSuccess() {

	//Handle Set Feature Success
}

@Override
public void onEditGroupNameError(CNError error){
	//Handle SetFeature Error
}

Remove Admins From Group:

Now that the group is created and we added members to made some one as Admin on the group then we can remove admin fromthe group do that using below call. This is valid operation if it is performed by group main admin:

new MessagingManager().removeAdminsFromGroup(context, conversation, contyacts, new AddAdminsToGroupCallback() {...}

The Remove Admins from Group results are handled in the following callbacks:

@Override
public void onaddAdminsToGroupSuccess() {

	//Handle Remove Admins from Group Success
}

@Override
public void onaddAdminsToGroupError(CNError error){
	//Handle Remove Admins from Group Error
}

Leave Group:

You can leave Group using using below call. This is valid operation if the you are only a member not Main admin (or) Admin :

new MessagingManager().leaveGroup(context, conversation, new RemoveMembersFromGroupCallback() {...}

The leave group results are handled in the following callbacks:

@Override
public void onRemoveMemberFromGroupSuccess() {

	//Handle Leave Group Success
}

@Override
public void onRemoveMemberFromGroupError(CNError error){
	//Handle Leave Group Error
}