It looks like students who are a member of another group can participate in chatroom of other groups in a Group Mode .
However, the description from https://docs.moodle.org/39/en/Groups#Visible_groups says that:
- No groups - There are no sub groups, everyone is part of one big community
- Separate groups - Each group can only see their own group, others are invisible.
Steps to replicate:
- Create a course and enrol two student users.
- Create a group (groupA), member: studentA
- Create another one (groupB), member: studentB
- Turn editing on.
- Add a Chat activity and set Common module settings / Group mode = Visible groups.
- Click the "Save and return to course" button.
- Log in as studentA, go to the course contents page and visit the Chat activity.
- Remember that studentA is a member of groupA. In the Visible groups dropdown control, select Other groups / Group B.
- Click on the link "Use more accessible interface" and that will open up a new window.
- Type in a message and click the "Submit" button, then close the window.
- Log back as an admin/teacher and visit the Chat activity.
- On the Visible groups dropdown control, select "groupB".
- Click on "View past chat sessions" link then click the "List all sessions" link.
You will see that the message that was submitted by studentA of groupA was posted in the session of groupB.