Skip to content

Commit 92c3190

Browse files
authored
api: jsonrpc: add get_push_state to check push notification state (#7356)
1 parent 145145f commit 92c3190

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

deltachat-jsonrpc/src/api.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use types::contact::{ContactObject, VcardContact};
5353
use types::events::Event;
5454
use types::http::HttpResponse;
5555
use types::message::{MessageData, MessageObject, MessageReadReceipt};
56+
use types::notify_state::JsonrpcNotifyState;
5657
use types::provider_info::ProviderInfo;
5758
use types::reactions::JsonrpcReactions;
5859
use types::webxdc::WebxdcMessageInfo;
@@ -312,6 +313,12 @@ impl CommandApi {
312313
}
313314
}
314315

316+
/// Get the current push notification state.
317+
async fn get_push_state(&self, account_id: u32) -> Result<JsonrpcNotifyState> {
318+
let ctx = self.get_context(account_id).await?;
319+
Ok(ctx.push_state().await.into())
320+
}
321+
315322
/// Get the combined filesize of an account in bytes
316323
async fn get_account_file_size(&self, account_id: u32) -> Result<u64> {
317324
let ctx = self.get_context(account_id).await?;

deltachat-jsonrpc/src/api/types/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub mod http;
88
pub mod location;
99
pub mod login_param;
1010
pub mod message;
11+
pub mod notify_state;
1112
pub mod provider_info;
1213
pub mod qr;
1314
pub mod reactions;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use deltachat::push::NotifyState;
2+
use serde::Serialize;
3+
use typescript_type_def::TypeDef;
4+
5+
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
6+
#[serde(rename = "NotifyState")]
7+
pub enum JsonrpcNotifyState {
8+
/// Not subscribed to push notifications.
9+
NotConnected,
10+
11+
/// Subscribed to heartbeat push notifications.
12+
Heartbeat,
13+
14+
/// Subscribed to push notifications for new messages.
15+
Connected,
16+
}
17+
18+
impl From<NotifyState> for JsonrpcNotifyState {
19+
fn from(state: NotifyState) -> Self {
20+
match state {
21+
NotifyState::NotConnected => Self::NotConnected,
22+
NotifyState::Heartbeat => Self::Heartbeat,
23+
NotifyState::Connected => Self::Connected,
24+
}
25+
}
26+
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub mod color;
9898
pub mod html;
9999
pub mod net;
100100
pub mod plaintext;
101-
mod push;
101+
pub mod push;
102102
mod stats;
103103
pub use stats::SecurejoinSource;
104104
pub use stats::SecurejoinUiPath;

src/push.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub(crate) struct PushSubscriberState {
170170
heartbeat_subscribed: bool,
171171
}
172172

173+
/// Push notification state
173174
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)]
174175
#[repr(i8)]
175176
pub enum NotifyState {

0 commit comments

Comments
 (0)