pub trait ChatSettings: JmapBackend {
// Provided methods
fn limits(&self, _caller: &Self::CallerCtx, _account_id: &Id) -> ChatLimits { ... }
fn retains_edit_history(&self) -> bool { ... }
fn maintains_unread_count(&self) -> bool { ... }
fn owner_user_id(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
) -> impl Future<Output = Result<Option<String>, Self::Error>> + Send { ... }
fn search_capability(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
) -> impl Future<Output = Result<Option<SearchCapability>, Self::Error>> + Send { ... }
}Expand description
Deployment settings and identity: limits, edit history, unread counts, the owner’s user id.
Part of ChatBackend (docs/design/chat-backend-split.md).
Provided Methods§
Sourcefn limits(&self, _caller: &Self::CallerCtx, _account_id: &Id) -> ChatLimits
fn limits(&self, _caller: &Self::CallerCtx, _account_id: &Id) -> ChatLimits
Implementation-defined per-Space content limits for this caller and account.
Called by handle_space_set once per request, before
dispatching to ChatSpaces::apply_space_patch, to enforce
per-aggregate caps on roles, members, channels, and categories
per Space (draft-atwood-jmap-chat-00 §Space/set, spec commit
80d5e11), and by handle_message_set once per request to
validate bodyType against ChatLimits::supported_body_types
and ChatLimits::server_reserved_body_types.
The default implementation returns ChatLimits::default,
which carries conservative reference-impl-grade values. The
caller and account_id arguments are plumbed even though the
default impl ignores them, so production backends can vary caps
per-account (Free vs. Pro tier, multi-tenant SaaS, etc.)
without a future API break. Implementations SHOULD return
quickly (in-process struct construction, possibly off a cached
per-account record) — this method is called on the hot
Space/set path.
§Why sync, not async
Space/set calls this once per request before dispatching the
mutation; an async .await here would add a roundtrip to the
hot path of every Space mutation. Production backends with
per-tenant caps SHOULD cache the resolved ChatLimits for
each account on first use and serve from the cache thereafter.
See the trait-level “Async vs sync method convention” section
above for the workspace rationale.
Workspace cross-extension pattern: see AGENTS.md “Backend
caps and limits”.
Sourcefn retains_edit_history(&self) -> bool
fn retains_edit_history(&self) -> bool
Whether the backend retains edit history for messages.
Per draft-atwood-jmap-chat-00 commit 0783fc4 (“condition
MessageRevision push on edit-history retention”) +
§Message editHistory: servers MAY limit retained
MessageRevisions, and when the server does not retain edit
history, the editHistory field MUST be omitted from
Message/get and (in principle) Message/changes responses.
Message/changes per RFC 8620 §5.2 returns only id arrays,
not Message objects, so the spec’s “omit from /changes” is
a no-op at the wire level — the kit only enforces the
Message/get projection.
§When the handler calls this
handle_message_get consults this predicate once per call.
When false, every returned Message has its
edit_history field set to None before serialization,
which serde’s skip_serializing_if = "Option::is_none"
collapses to a wire-absent field per spec.
§Why sync, not async
This is a static deployment-policy flag, not a per-call
decision — it does not consult per-account state, principal
identity, or per-message bounds. Production backends that
need to vary retention per-account would file a follow-up
bead for a parallel retains_edit_history_for_account hook
rather than reshaping this method.
§Default implementation
Returns false — no retention. This matches the workspace’s
“kit defines the hook; consumer enforces the policy” posture.
Production backends that retain edit history MUST override
this to true; the reference MemoryBackend exposes a
test-only setter for tests that need the retain-on path.
Sourcefn maintains_unread_count(&self) -> bool
fn maintains_unread_count(&self) -> bool
Whether the backend keeps Chat.unreadCount itself instead of
the kit recomputing it.
draft-atwood-jmap-chat-00 §Chat unreadCount (jmap-chat-spec
33702a5 L629): “The value is advisory, for display such as
badges. Servers SHOULD keep it accurate, but MAY update it some
time after the change that affects it, MAY combine several such
changes into one update, and MAY report a server-defined maximum
in place of any larger count. Whenever the server changes the
value, the Chat’s state changes as for any other property
({{RFC8620}} Section 5.1).”
§When the handlers call this
When false, the kit keeps the count exact: Chat/get recomputes
unreadCount from the account’s Messages and ReadPositions, and
every Message create or destroy, Message expiry, read-and-burn and
ReadPosition update writes the recomputed count to each affected
Chat through ChatStore::update_object, which advances the
Chat state.
When true, the kit does neither: Chat/get returns the stored
unreadCount and no Chat is rewritten. The backend sees every
write that moves the count (the create_object, update_object
and destroy_object calls for Message and ReadPosition,
ChatMessageLifecycle::expire_message and
ChatMessageLifecycle::read_and_burn_message), and may defer, coalesce or
cap its update. It MUST still advance the Chat state, and log the
Chat as updated for Chat/changes, whenever the stored value
changes (RFC 8620 §5.1: “If the data changes, this string MUST
change”).
§Default implementation
Returns false, the exact upkeep the spec’s SHOULD asks for. A
backend for which the per-event rewrite costs too much (it scans
every Message in the account) overrides this to true.
Sourcefn owner_user_id(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
) -> impl Future<Output = Result<Option<String>, Self::Error>> + Send
fn owner_user_id( &self, _caller: &Self::CallerCtx, _account_id: &Id, ) -> impl Future<Output = Result<Option<String>, Self::Error>> + Send
The owner’s identity for account_id: the value of the
ownerUserId Session field (draft-atwood-jmap-chat-00 §Session
Object Extensions).
crate::contact::handle_contact_set rejects a ChatContact/set
create whose identity equals this value, octet for octet, with
an invalidProperties SetError naming identity
(draft-atwood-jmap-chat-00 §ChatContact/set: “the owner has no
ChatContact”).
§Default implementation
Returns Ok(None): the owner’s identity is unknown and the check
is skipped. Backends that serve ownerUserId MUST override this
to return the same value. A backend used with federation (a
jmap_chat_federation_server::FederationBackend) must return
Some for every mailbox: “Servers implementing {{JMAP-CHAT-FED}}
MUST include this field in the Session they serve an authenticated
owner” (draft-atwood-jmap-chat-00 §Session Object Extensions,
jmap-chat-spec b1cd625 L346), and the Peer/* handlers read it to
recognize the owner’s identity in a call.
Sourcefn search_capability(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
) -> impl Future<Output = Result<Option<SearchCapability>, Self::Error>> + Send
fn search_capability( &self, _caller: &Self::CallerCtx, _account_id: &Id, ) -> impl Future<Output = Result<Option<SearchCapability>, Self::Error>> + Send
The account-level urn:ietf:params:jmap:search capability object
(crate-jmap docs/specs/jmap-search.md §Account-Level Capability
Object) the consumer advertises for account_id, or None when it
does not advertise the capability.
With None, or without "Message" in its dataTypes, a
Message/query or Message/queryChanges filter that sets where
is unsupportedFilter, as it is when the request’s using lacks
urn:ietf:params:jmap:search (§Opting In a Data Type). With it, the
handlers check where against it
(jmap_search::check_where_filter), report canCalculateChanges: false from Message/query and answer Message/queryChanges with
cannotCalculateChanges (§Query Changes). query_objects then
evaluates where over the Messages the caller may fetch, each as
the caller would receive it from Message/get (§Visibility,
§Addressable Properties).
§Default implementation
Returns Ok(None): no search.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl<C: MemoryCaller> ChatSettings for MemoryBackend<C>
memory only.