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