1#![forbid(unsafe_code)]
54
55use std::sync::Arc;
56
57use jmap_server::{Dispatcher, HandlerFuture, JmapHandler};
58
59pub mod backend;
60pub mod ban;
61pub mod chat;
62pub mod contact;
63pub mod emoji;
64mod helpers;
65pub mod invite;
66#[cfg(feature = "memory")]
71pub mod memory;
72pub mod message;
73pub mod permissions;
74pub mod position;
75pub mod presence;
76pub mod push;
77pub mod space;
78
79pub use backend::{
80 AddedItem, BackendChangesError, BackendQueryError, BackendSetError, ChangesResult, ChatBackend,
81 ChatContactProperty, ChatLimits, ChatProperty, EmojiSetOp, GetObject, InviteJoinRefusal,
82 JmapBackend, JmapObject, MessageProperty, OpResult, QueryChangesResult, QueryObject,
83 QueryResult, ReadPositionProperty, SetError, SetErrorType, SetObject, SlowModeError,
84 SpaceMetadataPatch, SpacePatchOp, SpaceProperty,
85};
86pub use ban::{handle_ban_changes, handle_ban_get, handle_ban_set};
87pub use chat::{
88 handle_chat_changes, handle_chat_get, handle_chat_query, handle_chat_query_changes,
89 handle_chat_set, handle_chat_typing,
90};
91pub use contact::{
92 handle_contact_changes, handle_contact_get, handle_contact_query, handle_contact_query_changes,
93 handle_contact_set,
94};
95pub use emoji::{
96 handle_emoji_changes, handle_emoji_get, handle_emoji_query, handle_emoji_query_changes,
97 handle_emoji_set,
98};
99pub use invite::{handle_invite_changes, handle_invite_get, handle_invite_set};
100pub use message::{
101 handle_message_changes, handle_message_get, handle_message_query, handle_message_query_changes,
102 handle_message_set,
103};
104pub use permissions::{
105 required_permissions_for_op, RequiredPermissions, BAN, MANAGE_CHANNELS, MANAGE_MEMBERS,
106 MANAGE_ROLES, MANAGE_SPACE, PIN,
107};
108pub use position::{handle_position_changes, handle_position_get, handle_position_set};
109pub use presence::{handle_presence_changes, handle_presence_get, handle_presence_set};
110pub use push::{
111 build_chat_message_push, chat_state_change_for, should_push, strip_unsupported_chat_push,
112 validate_chat_push, BuiltPush, OwnerFlags, PushItem,
113};
114pub use space::{
115 handle_space_changes, handle_space_get, handle_space_join, handle_space_query,
116 handle_space_query_changes, handle_space_set,
117};
118
119pub fn register_chat_handlers<B>(dispatcher: &mut Dispatcher<B::CallerCtx>, backend: Arc<B>)
160where
161 B: ChatBackend + 'static,
162{
163 macro_rules! reg {
172 ($method:expr, $backend:expr, |$b:ident, $ci:ident, $a:ident, $ctx:ident| $body:expr) => {{
173 let backend_arc: Arc<B> = Arc::clone(&$backend);
174 let h: Arc<dyn JmapHandler<B::CallerCtx>> = Arc::new(ClosureHandler::new(
175 backend_arc,
176 move |$b: Arc<B>, $ci: String, $a: serde_json::Value, $ctx: B::CallerCtx| {
177 Box::pin(async move { $body }) as HandlerFuture
178 },
179 ));
180 dispatcher.register($method, h);
181 }};
182 }
183
184 reg!("Chat/get", backend, |b, _ci, a, ctx| {
186 handle_chat_get(&*b, &ctx, a).await
187 });
188 reg!("Chat/changes", backend, |b, _ci, a, ctx| {
189 handle_chat_changes(&*b, &ctx, a).await
190 });
191 reg!("Chat/query", backend, |b, _ci, a, ctx| {
192 handle_chat_query(&*b, &ctx, a).await
193 });
194 reg!("Chat/queryChanges", backend, |b, _ci, a, ctx| {
195 handle_chat_query_changes(&*b, &ctx, a).await
196 });
197 reg!("Chat/set", backend, |b, _ci, a, ctx| {
198 handle_chat_set(&*b, &ctx, a).await
199 });
200 reg!("Chat/typing", backend, |b, _ci, a, ctx| {
201 handle_chat_typing(&*b, &ctx, a).await
202 });
203
204 reg!("Message/get", backend, |b, _ci, a, ctx| {
206 handle_message_get(&*b, &ctx, a).await
207 });
208 reg!("Message/changes", backend, |b, _ci, a, ctx| {
209 handle_message_changes(&*b, &ctx, a).await
210 });
211 reg!("Message/query", backend, |b, _ci, a, ctx| {
212 handle_message_query(&*b, &ctx, a).await
213 });
214 reg!("Message/queryChanges", backend, |b, _ci, a, ctx| {
215 handle_message_query_changes(&*b, &ctx, a).await
216 });
217 reg!("Message/set", backend, |b, _ci, a, ctx| {
218 handle_message_set(&*b, &ctx, a).await
219 });
220
221 reg!("Space/get", backend, |b, _ci, a, ctx| {
223 handle_space_get(&*b, &ctx, a).await
224 });
225 reg!("Space/changes", backend, |b, _ci, a, ctx| {
226 handle_space_changes(&*b, &ctx, a).await
227 });
228 reg!("Space/query", backend, |b, _ci, a, ctx| {
229 handle_space_query(&*b, &ctx, a).await
230 });
231 reg!("Space/queryChanges", backend, |b, _ci, a, ctx| {
232 handle_space_query_changes(&*b, &ctx, a).await
233 });
234 reg!("Space/set", backend, |b, _ci, a, ctx| {
235 handle_space_set(&*b, &ctx, a).await
236 });
237 reg!("Space/join", backend, |b, _ci, a, ctx| {
238 handle_space_join(&*b, &ctx, a).await
239 });
240
241 reg!("ChatContact/get", backend, |b, _ci, a, ctx| {
243 handle_contact_get(&*b, &ctx, a).await
244 });
245 reg!("ChatContact/changes", backend, |b, _ci, a, ctx| {
246 handle_contact_changes(&*b, &ctx, a).await
247 });
248 reg!("ChatContact/query", backend, |b, _ci, a, ctx| {
249 handle_contact_query(&*b, &ctx, a).await
250 });
251 reg!("ChatContact/queryChanges", backend, |b, _ci, a, ctx| {
252 handle_contact_query_changes(&*b, &ctx, a).await
253 });
254 reg!("ChatContact/set", backend, |b, _ci, a, ctx| {
255 handle_contact_set(&*b, &ctx, a).await
256 });
257
258 reg!("ReadPosition/get", backend, |b, _ci, a, ctx| {
260 handle_position_get(&*b, &ctx, a).await
261 });
262 reg!("ReadPosition/changes", backend, |b, _ci, a, ctx| {
263 handle_position_changes(&*b, &ctx, a).await
264 });
265 reg!("ReadPosition/set", backend, |b, _ci, a, ctx| {
266 handle_position_set(&*b, &ctx, a).await
267 });
268
269 reg!("SpaceInvite/get", backend, |b, _ci, a, ctx| {
271 handle_invite_get(&*b, &ctx, a).await
272 });
273 reg!("SpaceInvite/changes", backend, |b, _ci, a, ctx| {
274 handle_invite_changes(&*b, &ctx, a).await
275 });
276 reg!("SpaceInvite/set", backend, |b, _ci, a, ctx| {
277 handle_invite_set(&*b, &ctx, a).await
278 });
279
280 reg!("SpaceBan/get", backend, |b, _ci, a, ctx| {
282 handle_ban_get(&*b, &ctx, a).await
283 });
284 reg!("SpaceBan/changes", backend, |b, _ci, a, ctx| {
285 handle_ban_changes(&*b, &ctx, a).await
286 });
287 reg!("SpaceBan/set", backend, |b, _ci, a, ctx| {
288 handle_ban_set(&*b, &ctx, a).await
289 });
290
291 reg!("CustomEmoji/get", backend, |b, _ci, a, ctx| {
293 handle_emoji_get(&*b, &ctx, a).await
294 });
295 reg!("CustomEmoji/changes", backend, |b, _ci, a, ctx| {
296 handle_emoji_changes(&*b, &ctx, a).await
297 });
298 reg!("CustomEmoji/query", backend, |b, _ci, a, ctx| {
299 handle_emoji_query(&*b, &ctx, a).await
300 });
301 reg!("CustomEmoji/queryChanges", backend, |b, _ci, a, ctx| {
302 handle_emoji_query_changes(&*b, &ctx, a).await
303 });
304 reg!("CustomEmoji/set", backend, |b, _ci, a, ctx| {
305 handle_emoji_set(&*b, &ctx, a).await
306 });
307
308 reg!("PresenceStatus/get", backend, |b, _ci, a, ctx| {
310 handle_presence_get(&*b, &ctx, a).await
311 });
312 reg!("PresenceStatus/changes", backend, |b, _ci, a, ctx| {
313 handle_presence_changes(&*b, &ctx, a).await
314 });
315 reg!("PresenceStatus/set", backend, |b, _ci, a, ctx| {
316 handle_presence_set(&*b, &ctx, a).await
317 });
318}
319
320pub use jmap_server::ClosureHandler;