Skip to main content

MlsGroup Struct

MlsGroup<Context> is the primary interface for group conversations in LibXMTP.

Fields

Traits

  • Clone - Groups can be cloned (shares underlying context)
  • PartialEq, Eq - Equality based on group_id
  • Hash - Hashing based on group_id
  • Debug - Formatted debug output

Constructor Methods

new

Creates a new group instance without database validation. Parameters:
  • context - Shared context
  • group_id - Group identifier
  • dm_id - Optional DM identifier
  • conversation_type - Conversation type
  • created_at_ns - Creation timestamp
Returns: New MlsGroup instance

new_cached

Creates a group instance from the database with validation. Parameters:
  • context - Shared context
  • group_id - Group identifier
Returns: Tuple of (MlsGroup, StoredGroup) Errors:
  • NotFound::GroupById - Group not found in database

create_and_insert

Creates a new group and saves it to the database. Parameters:
  • context - Shared context
  • conversation_type - Must not be ConversationType::Dm
  • permissions_policy_set - Permission policies for the group
  • opts - Metadata options (name, description, etc.)
  • oneshot_message - Optional oneshot message
Returns: New MlsGroup instance Side Effects:
  • Creates OpenMLS group
  • Stores group in database
  • Sets consent state to Allowed

create_dm_and_insert

Creates a new DM conversation and saves it to the database. Parameters:
  • context - Shared context
  • membership_state - Initial membership state
  • dm_target_inbox_id - Target inbox ID for the DM
  • opts - DM metadata options
  • existing_group_id - Optional existing group ID (for backup restoration)
Returns: New MlsGroup instance

Messaging Methods

send_message

Sends a message and waits for publishing to complete. Parameters:
  • message - Message content bytes (typically encoded EncodedContent)
  • opts - Send options (includes should_push flag)
Returns: Message ID bytes Errors:
  • GroupError::GroupInactive - Group is not active
Side Effects:
  • Updates installations if needed
  • Publishes all pending intents
  • Sets group consent state to Allowed

send_message_optimistic

Sends a message optimistically, returning immediately without waiting for publishing. Parameters:
  • message - Message content bytes
  • opts - Send options
Returns: Message ID bytes Note: Message is queued locally but not published. Call publish_messages() to publish.

prepare_message_for_later_publish

Prepares a message for later publishing without creating an intent. Parameters:
  • message - Message content bytes
  • should_push - Whether to send push notification when publishing
Returns: Message ID bytes Note: Message is stored with Unpublished status. Use publish_stored_message to publish.

publish_stored_message

Publishes a previously stored message by ID. Parameters:
  • message_id - ID of the message to publish
Errors:
  • GroupError::GroupInactive - Group is not active
  • NotFound::MessageById - Message not found
Note: No-op if message is already published.

publish_messages

Publishes all unpublished messages by syncing until all intents are resolved. Side Effects:
  • Updates installations if needed
  • Sets group consent state to Allowed

delete_message

Deletes a message by its ID. Parameters:
  • message_id - Raw bytes of the message ID
Returns: ID of the deletion message Authorization:
  • Only the original sender or a super admin can delete messages
Wire Protocol: The message ID is hex-encoded for wire transmission. When processing incoming deletions, the hex string is decoded back to bytes for database lookups. Errors:
  • DeleteMessageError::MessageNotFound - Message not found
  • DeleteMessageError::NotAuthorized - Not the sender or super admin
  • DeleteMessageError::MessageAlreadyDeleted - Message already deleted
  • DeleteMessageError::NonDeletableMessage - Message type cannot be deleted

Query Methods

find_messages

Queries the database for stored messages. Parameters:
  • args - Query arguments (time range, kind, delivery status, limit)
Returns: Vector of StoredGroupMessage

count_messages

Counts the number of stored messages matching the criteria. Parameters:
  • args - Query arguments
Returns: Message count

find_messages_with_reactions

Queries messages with their associated reactions. Parameters:
  • args - Query arguments
Returns: Vector of StoredGroupMessageWithReactions

find_enriched_messages

Queries enriched messages with reactions, replies, and deletion status. Parameters:
  • args - Query arguments
Returns: Vector of DecodedMessage

get_last_read_times

Gets the last read receipt times by sender. Returns: Map of latest message times by sender

Membership Methods

add_members_by_identity

Adds members to the group by account address. Parameters:
  • account_identifiers - Vector of account identifiers to add
Returns: UpdateGroupMembershipResult with added/removed members and errors Errors:
  • GroupError::UserLimitExceeded - Would exceed MAX_GROUP_SIZE
  • GroupError::AddressNotFound - Some addresses not found
Note: Also updates existing members’ installations.

add_members

Adds members to the group by inbox IDs. Parameters:
  • inbox_ids - Vector of inbox IDs to add
Returns: UpdateGroupMembershipResult

remove_members_by_identity

Removes members from the group by account addresses. Parameters:
  • account_addresses_to_remove - Vector of account identifiers to remove

remove_members

Removes members from the group by inbox IDs. Parameters:
  • inbox_ids - Slice of inbox ID references to remove

update_installations

Checks the network for identity updates and adds/removes installations accordingly. Note: This is automatically called periodically during send_message.

leave_group

Leaves the group (sends a leave request). Errors:
  • GroupLeaveValidationError::NotAGroupMember - Not a member
  • GroupLeaveValidationError::SingleMemberLeaveRejected - Only member
  • GroupLeaveValidationError::DmLeaveForbidden - Cannot leave DMs
  • GroupLeaveValidationError::SuperAdminLeaveForbidden - Super admins must be demoted first

remove_members_pending_removal

Removes all members from the pending removal list. Authorization: Only admins and super admins can call this.

cleanup_pending_removal_list

Removes members from the pending removal list who are no longer in the group.

Utility Methods

load

Loads the group reference from the local database. Returns: StoredGroup with database fields Errors:
  • NotFound::GroupById - Group not found

SendMessageOpts

Options for sending messages.

UpdateGroupMembershipResult

Result of membership update operations.

MsgQueryArgs

Arguments for querying messages:
  • Time range filtering
  • Message kind filtering
  • Delivery status filtering
  • Limit and offset

Source References

  • Definition: crates/xmtp_mls/src/groups/mod.rs:122
  • Constructor: crates/xmtp_mls/src/groups/mod.rs:290
  • Messaging: crates/xmtp_mls/src/groups/mod.rs:588
  • Membership: crates/xmtp_mls/src/groups/mod.rs:970