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
// this API is experimental and may change in the future
const isAdmin = group.isAdmin(inboxId);
Check if inbox ID is a super admin
// this API is experimental and may change in the future
const isSuperAdmin = group.isSuperAdmin(inboxId);
List admins
// this API is experimental and may change in the future
const admins = group.admins;
List super admins
// this API is experimental and may change in the future
const superAdmins = group.superAdmins;
Add admin status to inbox ID
// this API is experimental and may change in the future
await group.addAdmin(inboxId);
Add super admin status to inbox ID
// this API is experimental and may change in the future
await group.addSuperAdmin(inboxId);
Remove admin status from inbox ID
// this API is experimental and may change in the future
await group.removeAdmin(inboxId);
Remove super admin status from inbox ID
await group.removeSuperAdmin(client.inboxId);
Manage group chat membership
Add members by inbox ID
// this API is experimental and may change in the future
await group.addMembersByInboxId([inboxId]);
Add members by address
// this API is experimental and may change in the future
await group.addMembers([walletAddress]);
Remove members by inbox ID
// this API is experimental and may change in the future
await group.removeMembersByInboxId([inboxId]);
Remove members by address
// this API is experimental and may change in the future
await group.removeMembers([walletAddress]);
Get inbox IDs for members
// this API is experimental and may change in the future
const inboxId = await client.getInboxIdByAddress(address);
Get addresses for members
// this API is experimental and may change in the future
// sync group first
await group.sync();
// get group members
const members = 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
// note that this can only be done with the JS SDK (@xmtp/xmtp-js)
await client.contacts.allow([walletAddress]);
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
// this API is experimental and may change in the future
const groupName = group.name;
Update a group chat name
// this API is experimental and may change in the future
await group.updateName("New Group Name");
Get a group chat image URL
// this API is experimental and may change in the future
const groupImageUrl = group.imageUrl;
Update a group chat image URL
// this API is experimental and may change in the future
await group.updateImageUrl("newurl.com");