Skip to main content

ChatModeration

Trait ChatModeration 

Source
pub trait ChatModeration: ChatStore {
    // Provided methods
    fn create_chat_ban<F>(
        &self,
        caller: &Self::CallerCtx,
        account_id: &Id,
        create_id: &str,
        build: F,
    ) -> impl Future<Output = Result<(Id, ChatBan), BackendSetError<Self::Error>>> + Send
       where F: FnOnce(&Id) -> ChatBan + Send { ... }
    fn update_chat_ban(
        &self,
        caller: &Self::CallerCtx,
        account_id: &Id,
        id: &Id,
        patch: PatchObject,
    ) -> impl Future<Output = Result<Option<ChatBan>, BackendSetError<Self::Error>>> + Send { ... }
    fn destroy_chat_ban(
        &self,
        caller: &Self::CallerCtx,
        account_id: &Id,
        id: &Id,
    ) -> impl Future<Output = Result<(), BackendSetError<Self::Error>>> + Send { ... }
    fn kick_chat_members(
        &self,
        _caller: &Self::CallerCtx,
        _account_id: &Id,
        _chat: &Chat,
        _user_ids: &[Id],
    ) -> impl Future<Output = Result<Result<(), SetError>, Self::Error>> + Send { ... }
}
Expand description

Group Chat moderation: ChatBan create, update and destroy, and the kickMembers patch key.

Its defaults write through ChatStore.

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

Provided Methods§

Source

fn create_chat_ban<F>( &self, caller: &Self::CallerCtx, account_id: &Id, create_id: &str, build: F, ) -> impl Future<Output = Result<(Id, ChatBan), BackendSetError<Self::Error>>> + Send
where F: FnOnce(&Id) -> ChatBan + Send,

Store a ChatBan and remove the banned user from the Chat’s members as one unit.

crate::handle_chat_ban_set calls this for every ChatBan/set create that passes its checks: the Chat named by chatId is a group Chat, the caller holds its "admin" role and userId is not the accountId. draft-atwood-jmap-chat-00 §ChatBan/set: “Creating a ban removes the user from members if present, as removeMembers would”.

build and every contract of ChatStore::create_object (authorisation, id assignment, errors, state and change log) apply unchanged. On Ok the ban is stored and the user is no longer in the Chat’s members. On Err neither happens. A backend that binds Chats to another group model (for example a MIMI room, where draft-atwood-jmap-chat-mimi-00 §Moderation makes the ban one commit that gives the user the “banned” role and removes the user’s clients) overrides this, and may reject the ban with a BackendSetError::SetError such as forbidden.

§Default implementation

Calls ChatStore::create_object for ChatBan. If the user is in the Chat’s members, it then calls ChatStore::update_object on the Chat with the user removed, and on success ChatEvents::on_outbound_event with the GroupUpdateAction::RemoveMembers event that a removeMembers update reports. If that update fails, the ban is destroyed again and the update’s error is returned. The steps are not one transaction; a backend that needs them in one overrides this.

Source

fn update_chat_ban( &self, caller: &Self::CallerCtx, account_id: &Id, id: &Id, patch: PatchObject, ) -> impl Future<Output = Result<Option<ChatBan>, BackendSetError<Self::Error>>> + Send

Apply a ChatBan/set update to the stored ban id.

crate::handle_chat_ban_set calls this for every update that passes its checks: the caller holds the "admin" role in the ban’s Chat, and patch names only reason and expiresAt (draft-atwood-jmap-chat-00 §ChatBan/set: “update supports: reason, expiresAt”). Every contract of ChatStore::update_object applies unchanged. A backend that mirrors bans into another group model (for example a MIMI room) overrides this.

§Default implementation

Calls ChatStore::update_object for ChatBan.

Source

fn destroy_chat_ban( &self, caller: &Self::CallerCtx, account_id: &Id, id: &Id, ) -> impl Future<Output = Result<(), BackendSetError<Self::Error>>> + Send

Lift the ChatBan id.

crate::handle_chat_ban_set calls this for every destroy that passes its checks (the caller holds the "admin" role in the ban’s Chat), and crate::sweep_expired for every ban whose expiresAt has passed. draft-atwood-jmap-chat-00 §ChatBan/set: “destroy lifts the ban … Lifting a ban does not add the user back to the Chat.” Every contract of ChatStore::destroy_object applies unchanged. A backend that binds Chats to a MIMI room overrides this to give the user the member role again without adding any client (draft-atwood-jmap-chat-mimi-00 §Moderation).

§Default implementation

Calls ChatStore::destroy_object for ChatBan; members is not touched.

Source

fn kick_chat_members( &self, _caller: &Self::CallerCtx, _account_id: &Id, _chat: &Chat, _user_ids: &[Id], ) -> impl Future<Output = Result<Result<(), SetError>, Self::Error>> + Send

Apply the kickMembers key of a Chat/set update.

draft-atwood-jmap-chat-mimi-00 §Moderation: “The kickMembers patch key of Chat/set (String[], ChatContact ids), which this document adds for Chats bound to a room, removes the listed users’ clients from the group but keeps them in the participant list, so that they can rejoin (canKick).” A backend that binds Chats to MIMI rooms overrides this: it checks that chat is bound to a room and that the owner may kick, then commits the client removals. members is not changed; the Chat record stays as it is.

§When the handler calls this

Once per Chat/set update whose patch carries a non-empty kickMembers, after the handler has checked it is an array of valid ids (else invalidProperties), after ChatRestrictions::may_update_chat and the other patch checks, and before ChatStore::update_object writes the rest of the patch (if any). chat is the stored Chat and user_ids the listed ChatContact ids with #creationId references resolved. Ok(Err(set_error)) rejects the update with that SetError and nothing is written; Err is serverFail.

§Default implementation

Rejects every kick with invalidProperties naming kickMembers. A backend with no room model has no Chat that the key applies to, so for it kickMembers is a key outside draft-atwood-jmap-chat-00 §Chat/set “Updating a Chat”, which the handler rejects the same way. Answering success instead would claim clients were removed when none were.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

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

Available on crate feature memory only.
Source§

impl<T: DelegateChatModeration + ChatStore> ChatModeration for T