#![forbid(unsafe_code)]
#![warn(
clippy::cast_possible_truncation,
clippy::cast_possible_wrap,
clippy::cast_sign_loss
)]
use std::sync::Arc;
use jmap_server::{CallContext, ClosureHandler, Dispatcher, HandlerFuture, JmapHandler};
mod backend;
mod ban;
mod chat;
mod contact;
mod did_auth;
mod emoji;
mod ephemeral;
mod expiry;
mod helpers;
mod invite;
#[cfg(feature = "memory")]
pub mod memory;
pub mod message;
mod outbound;
mod permissions;
mod position;
mod presence;
mod push;
mod space;
#[cfg(feature = "testkit")]
pub mod testkit;
pub use backend::{
AttachmentBlob, ChatBackend, ChatLimits, EmojiSetOp, InviteJoinRefusal, OpResult, SlowModeError,
};
pub use ban::{handle_ban_changes, handle_ban_get, handle_ban_set};
pub use chat::{
handle_chat_changes, handle_chat_get, handle_chat_query, handle_chat_query_changes,
handle_chat_set, handle_chat_typing,
};
pub use contact::{
handle_contact_changes, handle_contact_get, handle_contact_query, handle_contact_query_changes,
handle_contact_set,
};
pub use did_auth::{DidAuthRejection, DidDocument, verify_did_binding};
pub use emoji::{
handle_emoji_changes, handle_emoji_get, handle_emoji_query, handle_emoji_query_changes,
handle_emoji_set,
};
pub use ephemeral::{
CompanionStreams, EphemeralSubscription, IdScope, project_presence, should_deliver_typing,
};
pub use expiry::sweep_expired;
pub use invite::{handle_invite_changes, handle_invite_get, handle_invite_set};
pub use jmap_chat_types::{
ChatContactProperty, ChatProperty, MessageProperty, ReadPositionProperty, SpaceProperty,
};
pub use jmap_chat_types::{SpaceMetadataPatch, SpacePatchOp};
pub use outbound::{GroupUpdateAction, OutboundEvent, ReactionAction};
pub use permissions::{
RequiredPermissions, required_permissions_for_op, resolve_channel_permissions,
};
pub use position::{handle_position_changes, handle_position_get, handle_position_set};
pub use presence::{handle_presence_changes, handle_presence_get, handle_presence_set};
pub use push::{
BuiltPush, OwnerFlags, PushItem, build_chat_message_push, chat_state_change_for,
fit_chat_message_push, owner_unread_count, should_push, strip_unsupported_chat_push,
validate_chat_push,
};
pub use space::{
handle_space_changes, handle_space_get, handle_space_join, handle_space_query,
handle_space_query_changes, handle_space_set,
};
pub fn register_chat_handlers<B>(dispatcher: &mut Dispatcher<B::CallerCtx>, backend: Arc<B>)
where
B: ChatBackend + 'static,
{
macro_rules! reg {
($method:expr, $backend:expr, |$b:ident, $ci:ident, $a:ident, $ctx:ident $(, $field:ident)*| $body:expr) => {{
let backend_arc: Arc<B> = Arc::clone(&$backend);
let h: Arc<dyn JmapHandler<B::CallerCtx>> = Arc::new(ClosureHandler::new(
backend_arc,
move |$b: Arc<B>, cx: CallContext<B::CallerCtx>| {
let CallContext {
call_id: $ci,
args: $a,
caller: $ctx,
$($field,)*
..
} = cx;
Box::pin(async move { $body }) as HandlerFuture
},
));
dispatcher.register($method, h);
}};
}
reg!("Chat/get", backend, |b, _ci, a, ctx, using| {
handle_chat_get(&*b, &ctx, a, &using).await
});
reg!("Chat/changes", backend, |b, _ci, a, ctx, using| {
handle_chat_changes(&*b, &ctx, a, &using).await
});
reg!("Chat/query", backend, |b, _ci, a, ctx, using| {
handle_chat_query(&*b, &ctx, a, &using).await
});
reg!("Chat/queryChanges", backend, |b, _ci, a, ctx, using| {
handle_chat_query_changes(&*b, &ctx, a, &using).await
});
reg!("Chat/set", backend, |b, _ci, a, ctx, created_ids, using| {
handle_chat_set(&*b, &ctx, &created_ids, a, &using).await
});
reg!("Chat/typing", backend, |b, _ci, a, ctx| {
handle_chat_typing(&*b, &ctx, a).await
});
reg!("Message/get", backend, |b, _ci, a, ctx, using| {
message::handle_message_get(&*b, &ctx, a, &using).await
});
reg!("Message/changes", backend, |b, _ci, a, ctx, using| {
message::handle_message_changes(&*b, &ctx, a, &using).await
});
reg!("Message/query", backend, |b, _ci, a, ctx, using| {
message::handle_message_query(&*b, &ctx, a, &using).await
});
reg!("Message/queryChanges", backend, |b, _ci, a, ctx, using| {
message::handle_message_query_changes(&*b, &ctx, a, &using).await
});
reg!(
"Message/set",
backend,
|b, _ci, a, ctx, created_ids, using| {
message::handle_message_set(&*b, &ctx, &created_ids, a, &using).await
}
);
reg!("Space/get", backend, |b, _ci, a, ctx, using| {
handle_space_get(&*b, &ctx, a, &using).await
});
reg!("Space/changes", backend, |b, _ci, a, ctx, using| {
handle_space_changes(&*b, &ctx, a, &using).await
});
reg!("Space/query", backend, |b, _ci, a, ctx, using| {
handle_space_query(&*b, &ctx, a, &using).await
});
reg!("Space/queryChanges", backend, |b, _ci, a, ctx, using| {
handle_space_query_changes(&*b, &ctx, a, &using).await
});
reg!(
"Space/set",
backend,
|b, _ci, a, ctx, created_ids, using| {
handle_space_set(&*b, &ctx, &created_ids, a, &using).await
}
);
reg!("Space/join", backend, |b, _ci, a, ctx| {
handle_space_join(&*b, &ctx, a).await
});
reg!("ChatContact/get", backend, |b, _ci, a, ctx| {
handle_contact_get(&*b, &ctx, a).await
});
reg!("ChatContact/changes", backend, |b, _ci, a, ctx| {
handle_contact_changes(&*b, &ctx, a).await
});
reg!("ChatContact/query", backend, |b, _ci, a, ctx| {
handle_contact_query(&*b, &ctx, a).await
});
reg!("ChatContact/queryChanges", backend, |b, _ci, a, ctx| {
handle_contact_query_changes(&*b, &ctx, a).await
});
reg!("ChatContact/set", backend, |b, _ci, a, ctx| {
handle_contact_set(&*b, &ctx, a).await
});
reg!("ReadPosition/get", backend, |b, _ci, a, ctx| {
handle_position_get(&*b, &ctx, a).await
});
reg!("ReadPosition/changes", backend, |b, _ci, a, ctx| {
handle_position_changes(&*b, &ctx, a).await
});
reg!(
"ReadPosition/set",
backend,
|b, _ci, a, ctx, created_ids| handle_position_set(&*b, &ctx, &created_ids, a).await
);
reg!("SpaceInvite/get", backend, |b, _ci, a, ctx| {
handle_invite_get(&*b, &ctx, a).await
});
reg!("SpaceInvite/changes", backend, |b, _ci, a, ctx| {
handle_invite_changes(&*b, &ctx, a).await
});
reg!("SpaceInvite/set", backend, |b, _ci, a, ctx, created_ids| {
handle_invite_set(&*b, &ctx, &created_ids, a).await
});
reg!("SpaceBan/get", backend, |b, _ci, a, ctx| {
handle_ban_get(&*b, &ctx, a).await
});
reg!("SpaceBan/changes", backend, |b, _ci, a, ctx| {
handle_ban_changes(&*b, &ctx, a).await
});
reg!("SpaceBan/set", backend, |b, _ci, a, ctx, created_ids| {
handle_ban_set(&*b, &ctx, &created_ids, a).await
});
reg!("CustomEmoji/get", backend, |b, _ci, a, ctx| {
handle_emoji_get(&*b, &ctx, a).await
});
reg!("CustomEmoji/changes", backend, |b, _ci, a, ctx| {
handle_emoji_changes(&*b, &ctx, a).await
});
reg!("CustomEmoji/query", backend, |b, _ci, a, ctx| {
handle_emoji_query(&*b, &ctx, a).await
});
reg!("CustomEmoji/queryChanges", backend, |b, _ci, a, ctx| {
handle_emoji_query_changes(&*b, &ctx, a).await
});
reg!("CustomEmoji/set", backend, |b, _ci, a, ctx, created_ids| {
handle_emoji_set(&*b, &ctx, &created_ids, a).await
});
reg!("PresenceStatus/get", backend, |b, _ci, a, ctx| {
handle_presence_get(&*b, &ctx, a).await
});
reg!("PresenceStatus/changes", backend, |b, _ci, a, ctx| {
handle_presence_changes(&*b, &ctx, a).await
});
reg!("PresenceStatus/set", backend, |b, _ci, a, ctx| {
handle_presence_set(&*b, &ctx, a).await
});
}