Core Concepts
MlsGroup
TheMlsGroup struct is the primary interface for group interactions. It represents a group conversation that can contain anywhere from 1 to MAX_GROUP_SIZE inboxes.
- Generic over
Contexttype (allows different API/DB combinations) - Thread-safe with internal locking mechanisms
- Supports both group conversations and direct messages (DMs)
- Integrates with OpenMLS for MLS protocol operations
Group Types
LibXMTP supports different conversation types:- Group - Standard group conversations with multiple members
- DM (Direct Message) - Two-person conversations with special handling
- Virtual - Internal conversation types
Group Lifecycle
Creating Groups
Groups are created through thecreate_and_insert method:
Loading Groups
Groups can be loaded from the database:Core Operations
Membership Management
Adding Members:Messaging
Sending Messages:Group Updates
Updating Installations:Leaving Groups
- Cannot leave a DM
- Cannot leave if you’re the only member
- Super admins must be demoted before leaving
Extensions
Groups use MLS extensions to store additional data:- GroupMetadata - Immutable group metadata (conversation type, creator, DM members)
- GroupMutableMetadata - Mutable metadata (name, description, admin lists)
- GroupMutablePermissions - Permission policies for group actions
- GroupMembers - Membership tracking extension
- MlsGroup - Complete MlsGroup API reference
- Permissions - Permission policies and access control
- Metadata - Group metadata options and management
Error Handling
The Groups API uses theGroupError enum for error reporting:
GroupInactive- Attempting operations on inactive groupsUserLimitExceeded- Exceeding MAX_GROUP_SIZENotFound::GroupById- Group not found in databaseNotFound::MlsGroup- OpenMLS group not found
Integration Notes
Context Requirements
MlsGroup requires a context that implements XmtpSharedContext, providing:
- Database access (
db()) - API client (
api()) - Identity information (
inbox_id(),installation_id()) - MLS storage provider (
mls_provider()) - Synchronization primitives (
mutexes(),mls_commit_lock())
Thread Safety
Groups use multiple locking mechanisms:- Per-group mutex for operation serialization
- MLS commit lock for atomic MLS operations
- Database transactions for data integrity
Storage
Groups persist data across multiple tables:groups- Group metadata and stategroup_messages- Message content and metadatagroup_intents- Pending operations- OpenMLS keystore - MLS-specific data
