Set group chat permissions and metadata
Handle group chat permissions
Robust group chat permissions are key to providing users with a friendly and safe group chat experience.
Available permissions and options
These are the permissions allowed for a group:
- Add member
- Remove member
- Update metadata
- Add admin
- Remove admin
- Update permissions
These are the permission options available for each permission:
- Unspecified
- Allow
- Deny
- Allow if admin or super admin
- Allow if super admin
You can list, add, and remove members from a group chat. Only the group chat creator (super admin) has permission to add or remove members. This restriction ensures that only authorized individuals can modify the participant list.
Manage group chat admins
There are two kinds of administrators: super admins and admins. The group creator starts as a super admin, who has the most permissions so that a normal admin cannot remove the creator or destroy a group.
While group membership is inherent to the MLS group, administrators are specified through the group metadata. Updating the metadata is how you add or remove admins and specify who are admins versus super admins.
Here's an overview of how group chat admin statuses work:
- Everyone in a group chat is a member.
- A member can be granted admin or super admin status.
If the member's admin or super admin status is removed, they are still a member of the group chat. - By default, only a member with super admin can add and remove admin and super admin statuses.
Also by default, the group creator is the only member with super admin status.
Check if inbox ID is an admin
const isAdmin = group.isAdmin(inboxId);
Check if inbox ID is a super admin
const isSuperAdmin = group.isSuperAdmin(inboxId);
List admins
const admins = group.admins;
List super admins
const superAdmins = group.superAdmins;
Add admin status to inbox ID
await group.addAdmin(inboxId);
Add super admin status to inbox ID
await group.addSuperAdmin(inboxId);
Remove admin status from inbox ID
await group.removeAdmin(inboxId);
Remove super admin status from inbox ID
await group.removeSuperAdmin(inboxId);
Manage group chat membership
Add members by inbox ID
await group.addMembersByInboxId([inboxId]);
Add members by address
await group.addMembers([walletAddress]);
Remove members by inbox ID
await group.removeMembersByInboxId([inboxId]);
Remove members by address
await group.removeMembers([walletAddress]);
Get inbox IDs for members
const inboxId = await client.findInboxIdByAddress(address);
Get addresses for members
// sync group first
await group.sync();
// get group members
const members = await group.members();
// map inbox ID to account addresses
const inboxIdAddressMap = new Map(
members.map((member) => [member.inboxId, member.accountAddresses])
);
Get the inbox ID that added the current member
const addedByInboxId = group.addedByInboxId;
SDK method call flow to add and remove members
When you add or remove members from a group, a proposal/commit message is sent to all the installations in the group. When the commit happens, the cryptographic state of the group is changed. This allows new members to receive messages but not decrypt older ones and prevents removed members from decrypting messages after their departure.
Handle group chat metadata
Group chats can have metadata, like names and images. Metadata can help users more easily identify their group chats. You can also set group chat metadata when creating a group chat.
Get a group chat name
const groupName = group.name;
Update a group chat name
await group.updateName("New Group Name");
Get a group chat image URL
const groupImageUrl = group.imageUrl;
Update a group chat image URL
await group.updateImageUrl("newurl.com");
await group.updateImageUrl("newurl.com");