Skip to main content
LibXMTP Groups provides a robust implementation of group messaging using the MLS (Messaging Layer Security) protocol. This API allows you to create, manage, and interact with both group conversations and direct messages.

Core Concepts

MlsGroup

The MlsGroup struct is the primary interface for group interactions. It represents a group conversation that can contain anywhere from 1 to MAX_GROUP_SIZE inboxes.
Key Features:
  • Generic over Context type (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 the create_and_insert method:

Loading Groups

Groups can be loaded from the database:

Core Operations

Membership Management

Adding Members:
Removing Members:

Messaging

Sending Messages:
Querying Messages:
Message Deletion:

Group Updates

Updating Installations:
Syncing:

Leaving Groups

Constraints:
  • 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:
  1. GroupMetadata - Immutable group metadata (conversation type, creator, DM members)
  2. GroupMutableMetadata - Mutable metadata (name, description, admin lists)
  3. GroupMutablePermissions - Permission policies for group actions
  4. GroupMembers - Membership tracking extension
See the following pages for detailed information:
  • MlsGroup - Complete MlsGroup API reference
  • Permissions - Permission policies and access control
  • Metadata - Group metadata options and management

Error Handling

The Groups API uses the GroupError enum for error reporting:
Common errors include:
  • GroupInactive - Attempting operations on inactive groups
  • UserLimitExceeded - Exceeding MAX_GROUP_SIZE
  • NotFound::GroupById - Group not found in database
  • NotFound::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 state
  • group_messages - Message content and metadata
  • group_intents - Pending operations
  • OpenMLS keystore - MLS-specific data