Skip to main content

ChatEvents

Trait ChatEvents 

Source
pub trait ChatEvents: JmapBackend {
    // Provided methods
    fn on_chat_destroyed(
        &self,
        caller: &Self::CallerCtx,
        account_id: &Id,
        chat_id: &Id,
    ) -> impl Future<Output = ()> + Send { ... }
    fn on_space_destroyed(
        &self,
        caller: &Self::CallerCtx,
        account_id: &Id,
        space_id: &Id,
    ) -> impl Future<Output = ()> + Send { ... }
    fn on_space_ban_created(
        &self,
        caller: &Self::CallerCtx,
        account_id: &Id,
        ban: &SpaceBan,
    ) -> impl Future<Output = ()> + Send { ... }
    fn on_outbound_event(
        &self,
        caller: &Self::CallerCtx,
        account_id: &Id,
        event: &OutboundEvent,
    ) -> impl Future<Output = ()> + Send { ... }
}
Expand description

Notifications from the handlers after a change: lifecycle callbacks and outbound events.

Part of ChatBackend (docs/design/chat-backend-split.md).

Provided Methods§

Source

fn on_chat_destroyed( &self, caller: &Self::CallerCtx, account_id: &Id, chat_id: &Id, ) -> impl Future<Output = ()> + Send

Called after a Chat is destroyed, so a companion extension can update the records that reference it. Examples: draft-atwood-jmap-chat-tasks-00 §Lifecycle (“the affected Tasks’ chatId fields MUST be cleared”) and draft-atwood-jmap-vtc-00 §VTCCall (“the server MUST clear the corresponding field to null on all VTCCalls that reference it”).

§When the handler calls this

Once for each Chat that a request destroys, after the destroy succeeds:

  • a Chat/set destroy;
  • each channel in a successful Space/set removeChannels patch;
  • each channel Chat whose spaceId is a Space that Space/set destroys (draft-atwood-jmap-chat-00 §Destroying a Space: “Cascades to all channel Chats”). These calls come before Self::on_space_destroyed for that Space.

It is not called when the handler deletes a duplicate direct Chat it created in the same request, because no response ever named that id.

The destroy is already committed, so the hook cannot fail the request. A backend handles its own errors here. A change it makes to another record type MUST advance that type’s state, as in ChatStore::destroy_object (“Cascades”).

§Default implementation

Does nothing. A backend that implements an extension which references Chats overrides it.

Source

fn on_space_destroyed( &self, caller: &Self::CallerCtx, account_id: &Id, space_id: &Id, ) -> impl Future<Output = ()> + Send

Called after a Space/set destroy succeeds, so a companion extension can update the records that reference the Space. Examples: draft-atwood-jmap-vtc-00 §VTCCall (clear spaceId on VTCCalls) and draft-atwood-jmap-chat-filenode-00 §Space Deletion (“the server SHOULD also destroy the associated file tree”).

The handler calls it once per destroyed Space, after Self::on_chat_destroyed for each of its channel Chats. The error and state rules of Self::on_chat_destroyed apply.

§Default implementation

Does nothing. A backend that implements an extension which references Spaces overrides it.

Source

fn on_space_ban_created( &self, caller: &Self::CallerCtx, account_id: &Id, ban: &SpaceBan, ) -> impl Future<Output = ()> + Send

Called after a SpaceBan/set create succeeds, with the stored ban, so a companion extension can apply the ban to its own records. Example: draft-atwood-jmap-vtc-00 §Access Control “Space ban enforcement” (the server “MUST set leftAt on that VTCParticipant record”; “The ban takes effect immediately on active calls”).

The handler calls it once per created ban. The error and state rules of Self::on_chat_destroyed apply.

§Default implementation

Does nothing. A backend that implements an extension which must enforce Space bans overrides it.

Source

fn on_outbound_event( &self, caller: &Self::CallerCtx, account_id: &Id, event: &OutboundEvent, ) -> impl Future<Output = ()> + Send

Called when the owner’s action must be sent to other participants’ servers: a new Message, a retraction (deletedForAll), an edit, a reaction added or removed, a group Chat change, a read receipt, a typing signal or a presence change. A backend that implements draft-atwood-jmap-chat-federation-00 turns the OutboundEvent into Peer/deliver (message, edit or reactionUpdate), Peer/retract, Peer/groupUpdate, Peer/receipt, Peer/typing or Peer/presence calls, typically by enqueueing the durable ones (§Persistent Queue). OutboundEvent::Typing also drives the local typing push to the Chat’s other local participants.

§When the handler calls this
  • Message/set create: OutboundEvent::NewMessage, after the Message is written (draft-atwood-jmap-chat-00 §Message/set: “enqueues the message for outbound delivery”).

  • Message/set update setting deletedForAll: true: OutboundEvent::Retract, after the update is written (§Peer/retract “Sender Behavior”: “the server MUST send Peer/retract to the server of every other participant in the Chat”). If the write fails, nothing is reported.

  • Message/set update editing body, bodyType, mentions or broadcastMentions and not deleting the Message: OutboundEvent::Edit, after the update is written.

  • Chat/set create of a group Chat, or update that changes a group Chat’s members, roles, name, description or avatarBlobId: one OutboundEvent::GroupUpdate per action, after the write (draft-atwood-jmap-chat-00 §Chat/set).

  • Message/set update patching reactions/<senderReactionId> and not deleting the Message: one OutboundEvent::ReactionUpdate per key that adds a reaction or removes a stored one, after the update is written (draft-atwood-jmap-chat-00 §Adding and Removing Reactions).

  • Message/set update setting a non-null readAt on a Message whose senderId is not the accountId: OutboundEvent::Receipt, after the update (or the burnOnRead hard-delete) is written, unless the effective receiptSharing (Chat.receiptSharing, else PresenceStatus.receiptSharing) is false (draft-atwood-jmap-chat-federation-00 §Peer/receipt “Sender Behavior”).

  • Chat/typing: OutboundEvent::Typing, after the request is validated (draft-atwood-jmap-chat-00 §Chat/typing).

  • PresenceStatus/set update naming presence, statusText or statusEmoji: OutboundEvent::Presence, after the update is written (draft-atwood-jmap-chat-federation-00 §Peer/subscribePresence).

The hook cannot fail the request. A backend handles its own errors here.

§Default implementation

Does nothing, for a server that does not federate.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<C: MemoryCaller> ChatEvents for MemoryBackend<C>

Available on crate feature memory only.
Source§

impl<T: DelegateChatEvents> ChatEvents for T