1#![forbid(unsafe_code)]
54#![warn(
58 clippy::cast_possible_truncation,
59 clippy::cast_possible_wrap,
60 clippy::cast_sign_loss
61)]
62
63use std::sync::Arc;
64
65use jmap_server::{CallContext, ClosureHandler, Dispatcher, HandlerFuture, JmapHandler};
66
67mod backend;
68mod ban;
69mod chat;
70mod contact;
71mod did_auth;
72mod emoji;
73mod ephemeral;
74mod expiry;
75mod helpers;
76mod invite;
77#[cfg(feature = "memory")]
82pub mod memory;
83pub mod message;
84mod outbound;
85mod permissions;
86mod position;
87mod presence;
88mod push;
89mod space;
90#[cfg(feature = "testkit")]
91pub mod testkit;
92
93pub use backend::{
94 AttachmentBlob, ChatBackend, ChatLimits, EmojiSetOp, InviteJoinRefusal, OpResult, SlowModeError,
95};
96pub use ban::{handle_ban_changes, handle_ban_get, handle_ban_set};
97pub use chat::{
98 handle_chat_changes, handle_chat_get, handle_chat_query, handle_chat_query_changes,
99 handle_chat_set, handle_chat_typing,
100};
101pub use contact::{
102 handle_contact_changes, handle_contact_get, handle_contact_query, handle_contact_query_changes,
103 handle_contact_set,
104};
105pub use did_auth::{DidAuthRejection, DidDocument, verify_did_binding};
106pub use emoji::{
107 handle_emoji_changes, handle_emoji_get, handle_emoji_query, handle_emoji_query_changes,
108 handle_emoji_set,
109};
110pub use ephemeral::{
111 CompanionStreams, EphemeralSubscription, IdScope, project_presence, should_deliver_typing,
112};
113pub use expiry::sweep_expired;
114pub use invite::{handle_invite_changes, handle_invite_get, handle_invite_set};
115pub use jmap_chat_types::{
116 ChatContactProperty, ChatProperty, MessageProperty, ReadPositionProperty, SpaceProperty,
117};
118pub use jmap_chat_types::{SpaceMetadataPatch, SpacePatchOp};
119pub use outbound::{GroupUpdateAction, OutboundEvent, ReactionAction};
120pub use permissions::{
121 RequiredPermissions, required_permissions_for_op, resolve_channel_permissions,
122};
123pub use position::{handle_position_changes, handle_position_get, handle_position_set};
124pub use presence::{handle_presence_changes, handle_presence_get, handle_presence_set};
125pub use push::{
126 BuiltPush, OwnerFlags, PushItem, build_chat_message_push, chat_state_change_for,
127 fit_chat_message_push, owner_unread_count, should_push, strip_unsupported_chat_push,
128 validate_chat_push,
129};
130pub use space::{
131 handle_space_changes, handle_space_get, handle_space_join, handle_space_query,
132 handle_space_query_changes, handle_space_set,
133};
134
135pub fn register_chat_handlers<B>(dispatcher: &mut Dispatcher<B::CallerCtx>, backend: Arc<B>)
176where
177 B: ChatBackend + 'static,
178{
179 macro_rules! reg {
192 ($method:expr, $backend:expr, |$b:ident, $ci:ident, $a:ident, $ctx:ident $(, $field:ident)*| $body:expr) => {{
193 let backend_arc: Arc<B> = Arc::clone(&$backend);
194 let h: Arc<dyn JmapHandler<B::CallerCtx>> = Arc::new(ClosureHandler::new(
195 backend_arc,
196 move |$b: Arc<B>, cx: CallContext<B::CallerCtx>| {
197 let CallContext {
198 call_id: $ci,
199 args: $a,
200 caller: $ctx,
201 $($field,)*
202 ..
203 } = cx;
204 Box::pin(async move { $body }) as HandlerFuture
205 },
206 ));
207 dispatcher.register($method, h);
208 }};
209 }
210
211 reg!("Chat/get", backend, |b, _ci, a, ctx, using| {
213 handle_chat_get(&*b, &ctx, a, &using).await
214 });
215 reg!("Chat/changes", backend, |b, _ci, a, ctx, using| {
216 handle_chat_changes(&*b, &ctx, a, &using).await
217 });
218 reg!("Chat/query", backend, |b, _ci, a, ctx, using| {
219 handle_chat_query(&*b, &ctx, a, &using).await
220 });
221 reg!("Chat/queryChanges", backend, |b, _ci, a, ctx, using| {
222 handle_chat_query_changes(&*b, &ctx, a, &using).await
223 });
224 reg!("Chat/set", backend, |b, _ci, a, ctx, created_ids, using| {
225 handle_chat_set(&*b, &ctx, &created_ids, a, &using).await
226 });
227 reg!("Chat/typing", backend, |b, _ci, a, ctx| {
228 handle_chat_typing(&*b, &ctx, a).await
229 });
230
231 reg!("Message/get", backend, |b, _ci, a, ctx, using| {
233 message::handle_message_get(&*b, &ctx, a, &using).await
234 });
235 reg!("Message/changes", backend, |b, _ci, a, ctx, using| {
236 message::handle_message_changes(&*b, &ctx, a, &using).await
237 });
238 reg!("Message/query", backend, |b, _ci, a, ctx, using| {
239 message::handle_message_query(&*b, &ctx, a, &using).await
240 });
241 reg!("Message/queryChanges", backend, |b, _ci, a, ctx, using| {
242 message::handle_message_query_changes(&*b, &ctx, a, &using).await
243 });
244 reg!(
245 "Message/set",
246 backend,
247 |b, _ci, a, ctx, created_ids, using| {
248 message::handle_message_set(&*b, &ctx, &created_ids, a, &using).await
249 }
250 );
251
252 reg!("Space/get", backend, |b, _ci, a, ctx, using| {
254 handle_space_get(&*b, &ctx, a, &using).await
255 });
256 reg!("Space/changes", backend, |b, _ci, a, ctx, using| {
257 handle_space_changes(&*b, &ctx, a, &using).await
258 });
259 reg!("Space/query", backend, |b, _ci, a, ctx, using| {
260 handle_space_query(&*b, &ctx, a, &using).await
261 });
262 reg!("Space/queryChanges", backend, |b, _ci, a, ctx, using| {
263 handle_space_query_changes(&*b, &ctx, a, &using).await
264 });
265 reg!(
266 "Space/set",
267 backend,
268 |b, _ci, a, ctx, created_ids, using| {
269 handle_space_set(&*b, &ctx, &created_ids, a, &using).await
270 }
271 );
272 reg!("Space/join", backend, |b, _ci, a, ctx| {
273 handle_space_join(&*b, &ctx, a).await
274 });
275
276 reg!("ChatContact/get", backend, |b, _ci, a, ctx| {
278 handle_contact_get(&*b, &ctx, a).await
279 });
280 reg!("ChatContact/changes", backend, |b, _ci, a, ctx| {
281 handle_contact_changes(&*b, &ctx, a).await
282 });
283 reg!("ChatContact/query", backend, |b, _ci, a, ctx| {
284 handle_contact_query(&*b, &ctx, a).await
285 });
286 reg!("ChatContact/queryChanges", backend, |b, _ci, a, ctx| {
287 handle_contact_query_changes(&*b, &ctx, a).await
288 });
289 reg!("ChatContact/set", backend, |b, _ci, a, ctx| {
290 handle_contact_set(&*b, &ctx, a).await
291 });
292
293 reg!("ReadPosition/get", backend, |b, _ci, a, ctx| {
295 handle_position_get(&*b, &ctx, a).await
296 });
297 reg!("ReadPosition/changes", backend, |b, _ci, a, ctx| {
298 handle_position_changes(&*b, &ctx, a).await
299 });
300 reg!(
301 "ReadPosition/set",
302 backend,
303 |b, _ci, a, ctx, created_ids| handle_position_set(&*b, &ctx, &created_ids, a).await
304 );
305
306 reg!("SpaceInvite/get", backend, |b, _ci, a, ctx| {
308 handle_invite_get(&*b, &ctx, a).await
309 });
310 reg!("SpaceInvite/changes", backend, |b, _ci, a, ctx| {
311 handle_invite_changes(&*b, &ctx, a).await
312 });
313 reg!("SpaceInvite/set", backend, |b, _ci, a, ctx, created_ids| {
314 handle_invite_set(&*b, &ctx, &created_ids, a).await
315 });
316
317 reg!("SpaceBan/get", backend, |b, _ci, a, ctx| {
319 handle_ban_get(&*b, &ctx, a).await
320 });
321 reg!("SpaceBan/changes", backend, |b, _ci, a, ctx| {
322 handle_ban_changes(&*b, &ctx, a).await
323 });
324 reg!("SpaceBan/set", backend, |b, _ci, a, ctx, created_ids| {
325 handle_ban_set(&*b, &ctx, &created_ids, a).await
326 });
327
328 reg!("CustomEmoji/get", backend, |b, _ci, a, ctx| {
330 handle_emoji_get(&*b, &ctx, a).await
331 });
332 reg!("CustomEmoji/changes", backend, |b, _ci, a, ctx| {
333 handle_emoji_changes(&*b, &ctx, a).await
334 });
335 reg!("CustomEmoji/query", backend, |b, _ci, a, ctx| {
336 handle_emoji_query(&*b, &ctx, a).await
337 });
338 reg!("CustomEmoji/queryChanges", backend, |b, _ci, a, ctx| {
339 handle_emoji_query_changes(&*b, &ctx, a).await
340 });
341 reg!("CustomEmoji/set", backend, |b, _ci, a, ctx, created_ids| {
342 handle_emoji_set(&*b, &ctx, &created_ids, a).await
343 });
344
345 reg!("PresenceStatus/get", backend, |b, _ci, a, ctx| {
347 handle_presence_get(&*b, &ctx, a).await
348 });
349 reg!("PresenceStatus/changes", backend, |b, _ci, a, ctx| {
350 handle_presence_changes(&*b, &ctx, a).await
351 });
352 reg!("PresenceStatus/set", backend, |b, _ci, a, ctx| {
353 handle_presence_set(&*b, &ctx, a).await
354 });
355}