From a21925392ab83ec8d3b353f524af9451905b0a42 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Sun, 26 Oct 2025 16:49:50 +0100 Subject: [PATCH 1/2] api: jsonrpc: add `get_push_state` to check push notification state --- deltachat-jsonrpc/src/api.rs | 7 +++++ deltachat-jsonrpc/src/api/types/mod.rs | 1 + .../src/api/types/notify_state.rs | 26 +++++++++++++++++++ src/lib.rs | 2 +- src/push.rs | 1 + 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 deltachat-jsonrpc/src/api/types/notify_state.rs diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index 3af97db87a..1237624430 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -53,6 +53,7 @@ use types::contact::{ContactObject, VcardContact}; use types::events::Event; use types::http::HttpResponse; use types::message::{MessageData, MessageObject, MessageReadReceipt}; +use types::notify_state::JsonrpcNotifyState; use types::provider_info::ProviderInfo; use types::reactions::JsonrpcReactions; use types::webxdc::WebxdcMessageInfo; @@ -312,6 +313,12 @@ impl CommandApi { } } + /// Get the current push notification state. + async fn get_push_state(&self, account_id: u32) -> Result { + let ctx = self.get_context(account_id).await?; + Ok(ctx.push_state().await.into()) + } + /// Get the combined filesize of an account in bytes async fn get_account_file_size(&self, account_id: u32) -> Result { let ctx = self.get_context(account_id).await?; diff --git a/deltachat-jsonrpc/src/api/types/mod.rs b/deltachat-jsonrpc/src/api/types/mod.rs index 0f49fcaa37..c71a995c8f 100644 --- a/deltachat-jsonrpc/src/api/types/mod.rs +++ b/deltachat-jsonrpc/src/api/types/mod.rs @@ -8,6 +8,7 @@ pub mod http; pub mod location; pub mod login_param; pub mod message; +pub mod notify_state; pub mod provider_info; pub mod qr; pub mod reactions; diff --git a/deltachat-jsonrpc/src/api/types/notify_state.rs b/deltachat-jsonrpc/src/api/types/notify_state.rs new file mode 100644 index 0000000000..1e083449c0 --- /dev/null +++ b/deltachat-jsonrpc/src/api/types/notify_state.rs @@ -0,0 +1,26 @@ +use deltachat::push::NotifyState; +use serde::Serialize; +use typescript_type_def::TypeDef; + +#[derive(Serialize, TypeDef, schemars::JsonSchema)] +#[serde(rename = "NotifyState")] +pub enum JsonrpcNotifyState { + /// Not subscribed to push notifications. + NotConnected = 0, + + /// Subscribed to heartbeat push notifications. + Heartbeat = 1, + + /// Subscribed to push notifications for new messages. + Connected = 2, +} + +impl From for JsonrpcNotifyState { + fn from(state: NotifyState) -> Self { + match state { + NotifyState::NotConnected => JsonrpcNotifyState::NotConnected, + NotifyState::Heartbeat => JsonrpcNotifyState::Heartbeat, + NotifyState::Connected => JsonrpcNotifyState::Connected, + } + } +} diff --git a/src/lib.rs b/src/lib.rs index d3d30e3868..089b486868 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,7 +98,7 @@ pub mod color; pub mod html; pub mod net; pub mod plaintext; -mod push; +pub mod push; mod stats; pub use stats::SecurejoinSource; pub use stats::SecurejoinUiPath; diff --git a/src/push.rs b/src/push.rs index a16f946da7..5c9933c9b2 100644 --- a/src/push.rs +++ b/src/push.rs @@ -170,6 +170,7 @@ pub(crate) struct PushSubscriberState { heartbeat_subscribed: bool, } +/// Push notification state #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)] #[repr(i8)] pub enum NotifyState { From 9861d1d040e86dc2eead7eb1bd789729d831f624 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Sun, 26 Oct 2025 21:42:03 +0100 Subject: [PATCH 2/2] apply suggestions from code review --- deltachat-jsonrpc/src/api/types/notify_state.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/deltachat-jsonrpc/src/api/types/notify_state.rs b/deltachat-jsonrpc/src/api/types/notify_state.rs index 1e083449c0..027f0ee23d 100644 --- a/deltachat-jsonrpc/src/api/types/notify_state.rs +++ b/deltachat-jsonrpc/src/api/types/notify_state.rs @@ -6,21 +6,21 @@ use typescript_type_def::TypeDef; #[serde(rename = "NotifyState")] pub enum JsonrpcNotifyState { /// Not subscribed to push notifications. - NotConnected = 0, + NotConnected, /// Subscribed to heartbeat push notifications. - Heartbeat = 1, + Heartbeat, /// Subscribed to push notifications for new messages. - Connected = 2, + Connected, } impl From for JsonrpcNotifyState { fn from(state: NotifyState) -> Self { match state { - NotifyState::NotConnected => JsonrpcNotifyState::NotConnected, - NotifyState::Heartbeat => JsonrpcNotifyState::Heartbeat, - NotifyState::Connected => JsonrpcNotifyState::Connected, + NotifyState::NotConnected => Self::NotConnected, + NotifyState::Heartbeat => Self::Heartbeat, + NotifyState::Connected => Self::Connected, } } }