Skip to main content

Crate jmap_chat_server

Crate jmap_chat_server 

Source
Expand description

JMAP Chat extension method handlers.

§Usage

Implement ChatBackend for your storage layer, then call register_chat_handlers to wire all method names into a jmap_server::Dispatcher:

let mut dispatcher: Dispatcher<()> = Dispatcher::new();
register_chat_handlers(&mut dispatcher, Arc::new(backend));

§memory feature (reference implementation)

Enable the memory feature to expose the memory::MemoryBackend reference implementation of ChatBackend. This is the same backend used by this crate’s own integration tests, intended for downstream contributors to study and for smoke tests / examples that do not want to stand up a real database. Not production. API stability is opt-in via this feature and may break across minor versions while the crate is pre-1.0.

§realistic-demo-ids feature (test-id format toggle)

The realistic-demo-ids feature changes the id-minting format that [memory::MemoryBackend] uses for server-assigned object ids. It requires memory to be enabled (the feature only affects the in-memory reference backend; no other code path observes it).

  • Default (feature OFF): deterministic, lex-orderable per-(type, account) ids of the form "<type><n:016x>". Easy to read in test debug output. Load-bearing for draft-atwood-jmap-chat-00 Chat.unreadCount semantics (count of Messages whose id is lex-greater than lastReadMessageId).
  • Feature ON: mail-server-style timestamp+counter ids of the form "{n:016x}". Lex-orderable globally within a process, not repeatable across runs.

Cargo feature unification hazard. The output format of every MemoryBackend-minted id depends on this feature, and cargo unifies features across the dep graph. If crate A’s tests activate realistic-demo-ids for realism and crate B’s tests consume MemoryBackend expecting the deterministic format, a unified workspace build silently switches B to the realistic format and B’s tests break. Crates that depend on a specific id format MUST NOT rely on the absence of the feature elsewhere in the dep graph — they MUST encode the expected format in their own tests via fixture matching or prefix assertions rather than literal id comparison.

§Permission enforcement: backend canonical

All Space/set permission gates live in the backend’s apply_space_patch implementation (see memory::MemoryBackend under the memory feature for the reference impl). The handler handle_space_set does NOT permission-check.

The pure helper required_permissions_for_op in permissions maps each SpacePatchOp variant to its required permission strings per draft-atwood-jmap-chat-00 §Space/set. Backends consume this helper inside apply_space_patch after resolving the caller’s effective permissions via jmap_server::JmapBackend::principal_id. Handlers MUST NOT consume the helper for gating — backends are the single source of truth. This mirrors the workspace-wide rule documented in workspace AGENTS.md “Caller identity (foundation seam)”:

  • Handlers do NO permission checking.
  • Defense-in-depth handler pre-checks are allowed but the backend MUST re-verify atomically with the mutation.
  • A None return from JmapBackend::principal_id means the deployment has not wired identity; chat permission semantics cannot be honored and the backend MUST reject the patch rather than fail open.

Re-exports§

pub use backend::ChatBackend;
pub use backend::ChatLimits;
pub use backend::EmojiSetOp;
pub use backend::OpResult;
pub use backend::SlowModeError;
pub use ban::handle_ban_changes;
pub use ban::handle_ban_get;
pub use ban::handle_ban_set;
pub use chat::handle_chat_changes;
pub use chat::handle_chat_get;
pub use chat::handle_chat_query;
pub use chat::handle_chat_query_changes;
pub use chat::handle_chat_set;
pub use chat::handle_chat_typing;
pub use contact::handle_contact_changes;
pub use contact::handle_contact_get;
pub use contact::handle_contact_query;
pub use contact::handle_contact_query_changes;
pub use contact::handle_contact_set;
pub use emoji::handle_emoji_changes;
pub use emoji::handle_emoji_get;
pub use emoji::handle_emoji_query;
pub use emoji::handle_emoji_query_changes;
pub use emoji::handle_emoji_set;
pub use invite::handle_invite_changes;
pub use invite::handle_invite_get;
pub use invite::handle_invite_set;
pub use message::handle_message_changes;
pub use message::handle_message_get;
pub use message::handle_message_query;
pub use message::handle_message_query_changes;
pub use message::handle_message_set;
pub use permissions::required_permissions_for_op;
pub use permissions::RequiredPermissions;
pub use permissions::MANAGE_CHANNELS;
pub use permissions::MANAGE_MEMBERS;
pub use permissions::MANAGE_ROLES;
pub use permissions::MANAGE_SPACE;
pub use permissions::PIN;
pub use position::handle_position_changes;
pub use position::handle_position_get;
pub use position::handle_position_set;
pub use presence::handle_presence_changes;
pub use presence::handle_presence_get;
pub use presence::handle_presence_set;
pub use space::handle_space_changes;
pub use space::handle_space_get;
pub use space::handle_space_join;
pub use space::handle_space_query;
pub use space::handle_space_query_changes;
pub use space::handle_space_set;

Modules§

backend
ChatBackend trait and supporting types for JMAP Chat method handlers.
ban
SpaceBan/* method handlers (draft-atwood-jmap-chat-00 §SpaceBan).
chat
Chat/* method handlers (draft-atwood-jmap-chat-00 §Chat).
contact
ChatContact/* method handlers (draft-atwood-jmap-chat-00 §ChatContact).
emoji
CustomEmoji/* method handlers (draft-atwood-jmap-chat-00 §CustomEmoji).
invite
SpaceInvite/* method handlers (draft-atwood-jmap-chat-00 §SpaceInvite).
message
Message/* method handlers (draft-atwood-jmap-chat-00 §Message).
permissions
Pure permission-vocabulary helpers for backend authorization gating.
position
ReadPosition/* method handlers (draft-atwood-jmap-chat-00 §ReadPosition).
presence
PresenceStatus/* method handlers (draft-atwood-jmap-chat-00 §PresenceStatus).
space
Space/* method handlers (draft-atwood-jmap-chat-00 §Space).

Structs§

AddedItem
One entry in the added list of a /queryChanges response (RFC 8620 §5.6).
ChangesResult
Result of a /changes call (RFC 8620 §5.2).
ClosureHandler
Generic closure-to-JmapHandler adapter from jmap_server.
QueryChangesResult
Result of a /queryChanges call (RFC 8620 §5.6).
QueryResult
Result of a /query call (RFC 8620 §5.5).
SetError
A per-item error in a /set response (notCreated, notUpdated, notDestroyed maps) (RFC 8620 §5.3).
SpaceMetadataPatch
A typed view of the five top-level metadata fields that Space/set update can mutate (draft-atwood-jmap-chat-00 §Space/set, fields name, description, iconBlobId, isPublic, isPubliclyPreviewable).

Enums§

BackendChangesError
Error type returned by JmapBackend::get_changes and JmapBackend::query_changes.
BackendSetError
Error type returned by create/update/destroy backend methods.
ChatContactProperty
Property selector for crate::ChatContact /get and /set.
ChatProperty
Property selector for crate::Chat /get and /set.
MessageProperty
Property selector for crate::Message /get and /set.
ReadPositionProperty
Property selector for crate::ReadPosition /get and /set.
SetErrorType
The machine-readable type for a SetError (RFC 8620 §5.3 and RFC 8621).
SpacePatchOp
A single Space/set update mutation operation.
SpaceProperty
Property selector for crate::Space /get and /set.

Traits§

GetObject
Marker for object types that support get and changes operations.
JmapBackend
Read-side backend supertrait shared by all JMAP server crates.
JmapObject
Marker trait for all JMAP object types.
QueryObject
Marker for object types that support query and queryChanges operations.
SetObject
Marker for object types that support set (create/update/destroy) operations.

Functions§

register_chat_handlers
Register all JMAP Chat method handlers with dispatcher.