Ban/Kick Member from a Group
There are certain actions that can be performed on the group members:
- Kick a member from the group
- Ban a member from the group
- Unban a member from the group
- Update the scope of the member of the group
All the above actions can only be performed by the Admin or the Moderator of the group.
Kick a Group Member
The Admin or Moderator of a group can kick a member out of the group using the kickGroupMember()
method.
- Javascript
- Typescript
var GUID = "GUID";
var UID = "UID";
CometChat.kickGroupMember(GUID, UID).then(
response => {
console.log("Group member kicked successfully", response);
}, error => {
console.log("Group member kicking failed with error", error);
}
);
let GUID: string = "GUID";
let UID: string = "UID";
CometChat.kickGroupMember(GUID, UID).then(
(response: Object) => {
console.log("Group member kicked successfully", response);
}, (error: CometChat.CometChatException) => {
console.log("Group member kicking failed with error", error);
}
);
The kickGroupMember()
takes following parameters
Parameter | Description |
---|---|
UID | The UID of the user to be kicked. |
GUID | The GUID of the group from which user is to be kicked |
The kicked user will be no longer part of the group and can not perform any actions in the group, but the kicked user can rejoin the group.
Ban a Group Member
The Admin or Moderator of the group can ban a member from the group using the banGroupMember()
method.
- Javascript
- Typescript
var GUID = "GUID";
var UID = "UID";
CometChat.banGroupMember(GUID, UID).then(
response => {
console.log("Group member banned successfully", response);
}, error => {
console.log("Group member banning failed with error", error);
}
);
let GUID: string = "GUID";
let UID: string = "UID";
CometChat.banGroupMember(GUID, UID).then(
(response: Object) => {
console.log("Group member banned successfully", response);
}, (error: CometChat.CometChatException) => {
console.log("Group member banning failed with error", error);
}
);
The banGroupMember()
method takes the following parameters:
Parameter | Description |
---|---|
UID | The UID of the user to be banned. |
GUID | The GUID of the group from which user is to be banned. |
The banned user will be no longer part of the group and can not perform any actions in the group. A banned user cannot rejoin the same group without being unbanned.
Unban a Banned Group Member from a Group
Only Admin or Moderators of the group can unban a previously banned member from the group using the unbanGroupMember()
method.
- Javascript
- Typescript
var GUID = "GUID";
var UID = "UID";
CometChat.unbanGroupMember(GUID, UID).then(
response => {
console.log("Group member unbanned successfully", response);
}, error => {
console.log("Group member unbanning failed with error", error);
}
);
let GUID: string = "GUID";
let UID: string = "UID";
CometChat.unbanGroupMember(GUID, UID).then(
(response: Object) => {
console.log("Group member unbanned successfully", response);
}, (error: CometChat.CometChatException) => {
console.log("Group member unbanning failed with error", error);
}
);
The unbanGroupMember()
method takes the following parameters
Parameter | Description |
---|---|
UID | The UID of the user to be unbanned. |
GUID | The UID of the group from which user is to be banned |
The unbanned user can now rejoin the group.
Get List of Banned Members for a Group
In order to fetch the list of banned groups members for a group, you can use the BannedGroupMembersRequest
class. To use this class i.e to create an object of the BannedGroupMembersRequest class, you need to use the BannedGroupMembersRequestBuilder
class. The BannedGroupMembersRequestBuilder
class allows you to set the parameters based on which the banned group members are to be fetched.
The BannedGroupMembersRequestBuilder
class allows you to set the below parameters:
The GUID
of the group for which the banned members are to be fetched must be specified in the constructor of the GroupMembersRequestBuilder
class.
Set Limit
This method sets the limit i.e. the number of banned members that should be fetched in a single iteration.
- Javascript
- Typescript
let GUID = "GUID";
let limit = 30;
let bannedGroupMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
.setLimit(limit)
.build();
let GUID: string = "GUID";
let limit: number = 30;
let bannedGroupMembersRequest: CometChat.BannedMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
.setLimit(limit)
.build();
Set Search Keyword
This method allows you to set the search string based on which the banned group members are to be fetched.
- Javascript
- Typescript
let GUID = "GUID";
let limit = 30;
let searchKeyword = "super";
let bannedGroupMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
.setLimit(limit)
.setSearchKeyword(searchKeyword)
.build();
let GUID: string = "GUID";
let limit: number = 30;
let searchKeyword: string = "super";
let bannedGroupMembersRequest: CometChat.BannedMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
.setLimit(limit)
.setSearchKeyword(searchKeyword)
.build();
Finally, once all the parameters are set to the builder class, you need to call the build() method to get the object of the BannedGroupMembersRequest
class.
Once you have the object of the BannedGroupMembersRequest
class, you need to call the fetchNext()
method. Calling this method will return a list of GroupMember
objects containing n number of banned members where n is the limit set in the builder class.
- Javascript
- Typescript
let GUID = "GUID";
let limit = 30;
let bannedMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
.setLimit(limit)
.build();
bannedMembersRequest.fetchNext().then(
bannedMembers => {
console.log("Banned Group Member list fetched successfully:", bannedMembers);
}, error => {
console.log("Banned Group Member list fetching failed with exception:", error);
}
);
let GUID: string = "GUID";
let limit: number = 30;
let bannedGroupMembersRequest: CometChat.BannedMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
.setLimit(limit)
.build();
bannedGroupMembersRequest.fetchNext().then(
(bannedMembers: CometChat.GroupMember[]) => {
console.log("Banned Group Member list fetched successfully:", bannedMembers);
}, (error: CometChat.CometChatException) => {
console.log("Banned Group Member list fetching failed with exception:", error);
}
);