Quick Reference for AI Agents & Developers
Join a Group
To start participating in group conversations, you need to join a group. You can do so using thejoinGroup() method.
- Java
- Kotlin
joinGroup() method takes the following parameters:
| Parameter | Description |
|---|---|
GUID | The GUID of the group you would like to join |
groupType | Type of the group. CometChat provides 3 types of groups: 1. CometChatConstants.GROUP_TYPE_PUBLIC (public) 2. CometChatConstants.GROUP_TYPE_PASSWORD (password) 3. CometChatConstants.GROUP_TYPE_PRIVATE (private) |
password | Password is mandatory for password-protected groups. |
hasJoined parameter in the Group object.
Real-Time Group Member Joined Events
As a member of a group, how do I know if someone joins the group when my app is running? If a user joins any group, the members of the group receive a real-time event in theonGroupMemberJoined() method of the GroupListener class.
- Java
- Kotlin
Missed Group Member Joined Events
As a member of a group, how do I know if someone joins the group when my app is not running? When you retrieve the list of previous messages, if a member has joined any group that the logged-in user is a member of, the list of messages will contain anAction message. An Action message is a sub-class of the BaseMessage class.
For the group member joined event, in the Action object received, the following fields can help you get the relevant information:
action-joinedactionBy- User object containing the details of the user who joined the groupactionFor- Group object containing the details of the group the user has joined
Best Practices
Check hasJoined Before Joining
Check hasJoined Before Joining
Use the
hasJoined property of the Group object to avoid attempting to join groups you’re already a member of.Handle Password-Protected Groups
Handle Password-Protected Groups
Always prompt users for passwords when joining password-protected groups. Store passwords securely if needed for re-authentication.
Listen for Join Events
Listen for Join Events
Register group listeners to receive real-time notifications when other users join groups you’re a member of.
Troubleshooting
Join Failed - Already a Member
Join Failed - Already a Member
Symptom:
joinGroup() fails with “Already a member” error.Cause: User is already a member of the group.Solution: Check the hasJoined property before calling joinGroup(). CometChat tracks joined groups automatically.Join Failed - Incorrect Password
Join Failed - Incorrect Password
Symptom:
joinGroup() fails with “Incorrect password” error for password-protected groups.Cause: Wrong password provided for a password-protected group.Solution: Verify the password is correct. Passwords are case-sensitive.Join Failed - Private Group
Join Failed - Private Group
Symptom:
joinGroup() fails with “Cannot join private group” error.Cause: Attempting to join a private group without an invitation.Solution: Private groups require an admin or moderator to add members. Use the group-add-members functionality instead.