Skip to main content

jmap_chat_client/
lib.rs

1//! jmap-chat-client — auth-agnostic JMAP Chat HTTP client with WebSocket and SSE support.
2//!
3//! See PLAN.md for the full implementation plan.
4//!
5//! # Usage
6//!
7//! ```rust,no_run
8//! # use jmap_chat_client::JmapChatExt;
9//! # use jmap_types::Id;
10//! # async fn example(client: jmap_base_client::JmapClient) -> Result<(), jmap_base_client::ClientError> {
11//! let session = client.fetch_session().await?;
12//! let sc = client.with_chat_session(session);
13//! // Look up previously-uploaded blobs by their content-addressed hashes.
14//! // Pass `type_names: None` to accept any MIME type.
15//! let blob_ids = [Id::from("sha256-...")];
16//! let resolved = sc.blob_lookup(&blob_ids, None).await?;
17//! # let _ = resolved;
18//! # Ok(())
19//! # }
20//! ```
21
22#![forbid(unsafe_code)]
23
24pub mod methods;
25pub mod session;
26pub mod sse;
27pub mod types;
28pub mod utils;
29pub mod ws;
30
31pub use jmap_base_client::ClientError;
32pub use methods::blob::{BlobConvertResponse, BlobLookupEntry, BlobLookupResponse, BlobObject};
33pub use methods::quota::Quota;
34pub use methods::{
35    AddMemberInput, AddedItem, ChangesResponse, ChatContactPatch, ChatContactQueryInput,
36    ChatCreateInput, ChatPatch, ChatQueryInput, ContactSortProperty, CustomEmojiCreateInput,
37    CustomEmojiQueryInput, GetResponse, MessageCreateInput, MessagePatch, MessageQueryInput, Patch,
38    PresenceStatusPatch, PushSubscriptionCreateInput, PushSubscriptionCreateResponse,
39    PushSubscriptionPatch, QueryChangesResponse, QueryResponse, ReactionChange, SessionClient,
40    SetError, SetResponse, SpaceAddCategoryInput, SpaceAddChannelInput, SpaceAddMemberInput,
41    SpaceAddRoleInput, SpaceBanCreateInput, SpaceCreateInput, SpaceInviteCreateInput,
42    SpaceJoinInput, SpaceJoinResponse, SpacePatch, SpaceQueryInput, SpaceUpdateCategoryInput,
43    SpaceUpdateChannelInput, SpaceUpdateMemberInput, SpaceUpdateRoleInput, TypingResponse,
44    UpdateMemberRoleInput,
45};
46pub use session::{ChatCapability, ChatPushCapability, ChatSessionExt};
47pub use sse::{parse_chat_sse_block, ChatSseEvent, ChatSseFrame};
48pub use ws::{ChatWsExt, ChatWsFrame};
49
50/// Extension trait adding JMAP Chat methods to [`jmap_base_client::JmapClient`].
51///
52/// Import this trait to use: `use jmap_chat_client::JmapChatExt;`
53///
54/// All JMAP Chat method calls are made through the [`SessionClient`] returned
55/// by [`with_chat_session`](JmapChatExt::with_chat_session).
56pub trait JmapChatExt {
57    /// Create a [`SessionClient`] bound to this client and session.
58    ///
59    /// All JMAP Chat method calls are made through the returned [`SessionClient`].
60    fn with_chat_session(&self, session: jmap_base_client::Session) -> methods::SessionClient;
61}
62
63impl JmapChatExt for jmap_base_client::JmapClient {
64    fn with_chat_session(&self, session: jmap_base_client::Session) -> methods::SessionClient {
65        methods::SessionClient {
66            client: self.clone(),
67            session,
68        }
69    }
70}