Skip to content

Commit 1251b6d

Browse files
committed
jsonrpc: add connectivity functions
1 parent 7105625 commit 1251b6d

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
- `getDraft()`
3030
- `miscSendMsg()`
3131
- `miscSetDraft()`
32+
- `maybeNetwork()`
33+
- `getConnectivity()`
3234
- jsonrpc: add `is_broadcast` property to `ChatListItemFetchResult` #3584
3335
- jsonrpc: add `was_seen_recently` property to `ChatListItemFetchResult`, `FullChat` and `Contact` #3584
3436
- jsonrpc: add `webxdc_info` property to `Message` #3588

deltachat-jsonrpc/src/api/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,36 @@ impl CommandApi {
828828
Ok(media.iter().map(|msg_id| msg_id.to_u32()).collect())
829829
}
830830

831+
// ---------------------------------------------
832+
// connectivity
833+
// ---------------------------------------------
834+
835+
/// Indicate that the network likely has come back.
836+
/// or just that the network connditions might have changed
837+
async fn maybe_network(&self) -> Result<()> {
838+
self.accounts.read().await.maybe_network().await;
839+
Ok(())
840+
}
841+
842+
/// Get the current connectivity, i.e. whether the device is connected to the IMAP server.
843+
/// One of:
844+
/// - DC_CONNECTIVITY_NOT_CONNECTED (1000-1999): Show e.g. the string "Not connected" or a red dot
845+
/// - DC_CONNECTIVITY_CONNECTING (2000-2999): Show e.g. the string "Connecting…" or a yellow dot
846+
/// - DC_CONNECTIVITY_WORKING (3000-3999): Show e.g. the string "Getting new messages" or a spinning wheel
847+
/// - DC_CONNECTIVITY_CONNECTED (>=4000): Show e.g. the string "Connected" or a green dot
848+
///
849+
/// We don't use exact values but ranges here so that we can split up
850+
/// states into multiple states in the future.
851+
///
852+
/// Meant as a rough overview that can be shown
853+
/// e.g. in the title of the main screen.
854+
///
855+
/// If the connectivity changes, a #DC_EVENT_CONNECTIVITY_CHANGED will be emitted.
856+
async fn get_connectivity(&self, account_id: u32) -> Result<u32> {
857+
let ctx = self.get_context(account_id).await?;
858+
Ok(ctx.get_connectivity().await as u32)
859+
}
860+
831861
// ---------------------------------------------
832862
// webxdc
833863
// ---------------------------------------------

deltachat-jsonrpc/typescript/generated/client.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export class RawClient {
273273
* If not set, the Setup-Contact protocol is offered in the QR code.
274274
* See https://countermitm.readthedocs.io/en/latest/new.html
275275
* for details about both protocols.
276-
*
276+
*
277277
* return format: `[code, svg]`
278278
*/
279279
public getChatSecurejoinQrCodeSvg(accountId: T.U32, chatId: (T.U32|null)): Promise<[string,string]> {
@@ -490,6 +490,34 @@ export class RawClient {
490490
return (this._transport.request('chat_get_media', [accountId, chatId, messageType, orMessageType2, orMessageType3] as RPC.Params)) as Promise<(T.U32)[]>;
491491
}
492492

493+
/**
494+
* Indicate that the network likely has come back.
495+
* or just that the network connditions might have changed
496+
*/
497+
public maybeNetwork(): Promise<null> {
498+
return (this._transport.request('maybe_network', [] as RPC.Params)) as Promise<null>;
499+
}
500+
501+
/**
502+
* Get the current connectivity, i.e. whether the device is connected to the IMAP server.
503+
* One of:
504+
* - DC_CONNECTIVITY_NOT_CONNECTED (1000-1999): Show e.g. the string "Not connected" or a red dot
505+
* - DC_CONNECTIVITY_CONNECTING (2000-2999): Show e.g. the string "Connecting…" or a yellow dot
506+
* - DC_CONNECTIVITY_WORKING (3000-3999): Show e.g. the string "Getting new messages" or a spinning wheel
507+
* - DC_CONNECTIVITY_CONNECTED (>=4000): Show e.g. the string "Connected" or a green dot
508+
*
509+
* We don't use exact values but ranges here so that we can split up
510+
* states into multiple states in the future.
511+
*
512+
* Meant as a rough overview that can be shown
513+
* e.g. in the title of the main screen.
514+
*
515+
* If the connectivity changes, a #DC_EVENT_CONNECTIVITY_CHANGED will be emitted.
516+
*/
517+
public getConnectivity(accountId: T.U32): Promise<T.U32> {
518+
return (this._transport.request('get_connectivity', [accountId] as RPC.Params)) as Promise<T.U32>;
519+
}
520+
493521

494522
public webxdcSendStatusUpdate(accountId: T.U32, instanceMsgId: T.U32, updateStr: string, description: string): Promise<null> {
495523
return (this._transport.request('webxdc_send_status_update', [accountId, instanceMsgId, updateStr, description] as RPC.Params)) as Promise<null>;

deltachat-jsonrpc/typescript/generated/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,4 @@ export type WebxdcMessageInfo={
138138
export type DownloadState=("Done"|"Available"|"Failure"|"InProgress");
139139
export type Message={"id":U32;"chatId":U32;"fromId":U32;"quote":(MessageQuote|null);"parentId":(U32|null);"text":(string|null);"hasLocation":boolean;"hasHtml":boolean;"viewType":Viewtype;"state":U32;"timestamp":I64;"sortTimestamp":I64;"receivedTimestamp":I64;"hasDeviatingTimestamp":boolean;"subject":string;"showPadlock":boolean;"isSetupmessage":boolean;"isInfo":boolean;"isForwarded":boolean;"duration":I32;"dimensionsHeight":I32;"dimensionsWidth":I32;"videochatType":(U32|null);"videochatUrl":(string|null);"overrideSenderName":(string|null);"sender":Contact;"setupCodeBegin":(string|null);"file":(string|null);"fileMime":(string|null);"fileBytes":U64;"fileName":(string|null);"webxdcInfo":(WebxdcMessageInfo|null);"downloadState":DownloadState;};
140140
export type F64=number;
141-
export type __AllTyps=[string,boolean,Record<string,string>,U32,U32,null,(U32)[],U32,null,(U32|null),(Account)[],U32,Account,U32,string,(ProviderInfo|null),U32,boolean,U32,Record<string,string>,U32,string,(string|null),null,U32,Record<string,(string|null)>,null,U32,string,null,U32,string,Qr,U32,string,(string|null),U32,(string)[],Record<string,(string|null)>,U32,null,U32,null,U32,(U32)[],U32,U32,Usize,U32,string,U32,U32,string,null,U32,(U32|null),(string|null),(U32|null),(ChatListEntry)[],U32,(ChatListEntry)[],Record<U32,ChatListItemFetchResult>,U32,U32,FullChat,U32,U32,BasicChat,U32,U32,null,U32,U32,null,U32,U32,null,U32,U32,string,U32,(U32|null),[string,string],U32,U32,null,U32,U32,U32,null,U32,U32,U32,null,U32,string,string,U32,U32,U32,null,U32,U32,(U32|null),U32,U32,MuteDuration,null,U32,U32,boolean,U32,(U32)[],null,U32,U32,U32,(U32)[],U32,U32,Message,U32,(U32)[],Record<U32,Message>,U32,(U32)[],null,U32,U32,string,U32,U32,Contact,U32,string,(string|null),U32,U32,U32,U32,U32,U32,null,U32,U32,null,U32,(Contact)[],U32,U32,(string|null),(U32)[],U32,U32,(string|null),(Contact)[],U32,(U32)[],Record<U32,Contact>,U32,(U32|null),Viewtype,(Viewtype|null),(Viewtype|null),(U32)[],U32,U32,string,string,null,U32,U32,U32,string,U32,U32,WebxdcMessageInfo,U32,(U32)[],U32,null,U32,U32,null,U32,U32,(Message|null),U32,string,U32,U32,U32,U32,(string|null),(string|null),([F64,F64]|null),(U32|null),[U32,Message],U32,U32,(string|null),(string|null),(U32|null),null];
141+
export type __AllTyps=[string,boolean,Record<string,string>,U32,U32,null,(U32)[],U32,null,(U32|null),(Account)[],U32,Account,U32,string,(ProviderInfo|null),U32,boolean,U32,Record<string,string>,U32,string,(string|null),null,U32,Record<string,(string|null)>,null,U32,string,null,U32,string,Qr,U32,string,(string|null),U32,(string)[],Record<string,(string|null)>,U32,null,U32,null,U32,(U32)[],U32,U32,Usize,U32,string,U32,U32,string,null,U32,(U32|null),(string|null),(U32|null),(ChatListEntry)[],U32,(ChatListEntry)[],Record<U32,ChatListItemFetchResult>,U32,U32,FullChat,U32,U32,BasicChat,U32,U32,null,U32,U32,null,U32,U32,null,U32,U32,string,U32,(U32|null),[string,string],U32,U32,null,U32,U32,U32,null,U32,U32,U32,null,U32,string,string,U32,U32,U32,null,U32,U32,(U32|null),U32,U32,MuteDuration,null,U32,U32,boolean,U32,(U32)[],null,U32,U32,U32,(U32)[],U32,U32,Message,U32,(U32)[],Record<U32,Message>,U32,(U32)[],null,U32,U32,string,U32,U32,Contact,U32,string,(string|null),U32,U32,U32,U32,U32,U32,null,U32,U32,null,U32,(Contact)[],U32,U32,(string|null),(U32)[],U32,U32,(string|null),(Contact)[],U32,(U32)[],Record<U32,Contact>,U32,(U32|null),Viewtype,(Viewtype|null),(Viewtype|null),(U32)[],null,U32,U32,U32,U32,string,string,null,U32,U32,U32,string,U32,U32,WebxdcMessageInfo,U32,(U32)[],U32,null,U32,U32,null,U32,U32,(Message|null),U32,string,U32,U32,U32,U32,(string|null),(string|null),([F64,F64]|null),(U32|null),[U32,Message],U32,U32,(string|null),(string|null),(U32|null),null];

0 commit comments

Comments
 (0)