diff --git a/deltachat-jsonrpc/src/api/mod.rs b/deltachat-jsonrpc/src/api/mod.rs index a54f19e0d..20bc39bb7 100644 --- a/deltachat-jsonrpc/src/api/mod.rs +++ b/deltachat-jsonrpc/src/api/mod.rs @@ -22,6 +22,7 @@ pub mod events; pub mod types; use crate::api::types::chat_list::{get_chat_list_item_by_id, ChatListItemFetchResult}; +use crate::api::types::QrObject; use types::account::Account; use types::chat::FullChat; @@ -202,6 +203,13 @@ impl CommandApi { qr::set_config_from_qr(&ctx, &qr_content).await } + async fn check_qr(&self, account_id: u32, qr_content: String) -> Result { + let ctx = self.get_context(account_id).await?; + let qr = qr::check_qr(&ctx, &qr_content).await?; + let qr_object = QrObject::from(qr); + Ok(qr_object) + } + async fn get_config(&self, account_id: u32, key: String) -> Result> { let ctx = self.get_context(account_id).await?; get_config(&ctx, &key).await diff --git a/deltachat-jsonrpc/src/api/types/account.rs b/deltachat-jsonrpc/src/api/types/account.rs index 9a2d88100..8e0f80aef 100644 --- a/deltachat-jsonrpc/src/api/types/account.rs +++ b/deltachat-jsonrpc/src/api/types/account.rs @@ -19,9 +19,7 @@ pub enum Account { color: String, }, #[serde(rename_all = "camelCase")] - Unconfigured { - id: u32, - }, + Unconfigured { id: u32 }, } impl Account { diff --git a/deltachat-jsonrpc/src/api/types/mod.rs b/deltachat-jsonrpc/src/api/types/mod.rs index cb9d63f09..59440de83 100644 --- a/deltachat-jsonrpc/src/api/types/mod.rs +++ b/deltachat-jsonrpc/src/api/types/mod.rs @@ -1,3 +1,7 @@ +use deltachat::qr::Qr; +use serde::Serialize; +use typescript_type_def::TypeDef; + pub mod account; pub mod chat; pub mod chat_list; @@ -17,3 +21,208 @@ fn maybe_empty_string_to_option(string: String) -> Option { Some(string) } } + +#[derive(Serialize, TypeDef)] +#[serde(rename = "Qr", rename_all = "camelCase")] +#[serde(tag = "type")] +pub enum QrObject { + AskVerifyContact { + contact_id: u32, + fingerprint: String, + invitenumber: String, + authcode: String, + }, + AskVerifyGroup { + grpname: String, + grpid: String, + contact_id: u32, + fingerprint: String, + invitenumber: String, + authcode: String, + }, + FprOk { + contact_id: u32, + }, + FprMismatch { + contact_id: Option, + }, + FprWithoutAddr { + fingerprint: String, + }, + Account { + domain: String, + }, + WebrtcInstance { + domain: String, + instance_pattern: String, + }, + Addr { + contact_id: u32, + }, + Url { + url: String, + }, + Text { + text: String, + }, + WithdrawVerifyContact { + contact_id: u32, + fingerprint: String, + invitenumber: String, + authcode: String, + }, + WithdrawVerifyGroup { + grpname: String, + grpid: String, + contact_id: u32, + fingerprint: String, + invitenumber: String, + authcode: String, + }, + ReviveVerifyContact { + contact_id: u32, + fingerprint: String, + invitenumber: String, + authcode: String, + }, + ReviveVerifyGroup { + grpname: String, + grpid: String, + contact_id: u32, + fingerprint: String, + invitenumber: String, + authcode: String, + }, +} + +impl From for QrObject { + fn from(qr: Qr) -> Self { + match qr { + Qr::AskVerifyContact { + contact_id, + fingerprint, + invitenumber, + authcode, + } => { + let contact_id = contact_id.to_u32(); + let fingerprint = fingerprint.to_string(); + QrObject::AskVerifyContact { + contact_id, + fingerprint, + invitenumber, + authcode, + } + } + Qr::AskVerifyGroup { + grpname, + grpid, + contact_id, + fingerprint, + invitenumber, + authcode, + } => { + let contact_id = contact_id.to_u32(); + let fingerprint = fingerprint.to_string(); + QrObject::AskVerifyGroup { + grpname, + grpid, + contact_id, + fingerprint, + invitenumber, + authcode, + } + } + Qr::FprOk { contact_id } => { + let contact_id = contact_id.to_u32(); + QrObject::FprOk { contact_id } + } + Qr::FprMismatch { contact_id } => { + let contact_id = contact_id.map(|contact_id| contact_id.to_u32()); + QrObject::FprMismatch { contact_id } + } + Qr::FprWithoutAddr { fingerprint } => QrObject::FprWithoutAddr { fingerprint }, + Qr::Account { domain } => QrObject::Account { domain }, + Qr::WebrtcInstance { + domain, + instance_pattern, + } => QrObject::WebrtcInstance { + domain, + instance_pattern, + }, + Qr::Addr { contact_id } => { + let contact_id = contact_id.to_u32(); + QrObject::Addr { contact_id } + } + Qr::Url { url } => QrObject::Url { url }, + Qr::Text { text } => QrObject::Text { text }, + Qr::WithdrawVerifyContact { + contact_id, + fingerprint, + invitenumber, + authcode, + } => { + let contact_id = contact_id.to_u32(); + let fingerprint = fingerprint.to_string(); + QrObject::WithdrawVerifyContact { + contact_id, + fingerprint, + invitenumber, + authcode, + } + } + Qr::WithdrawVerifyGroup { + grpname, + grpid, + contact_id, + fingerprint, + invitenumber, + authcode, + } => { + let contact_id = contact_id.to_u32(); + let fingerprint = fingerprint.to_string(); + QrObject::WithdrawVerifyGroup { + grpname, + grpid, + contact_id, + fingerprint, + invitenumber, + authcode, + } + } + Qr::ReviveVerifyContact { + contact_id, + fingerprint, + invitenumber, + authcode, + } => { + let contact_id = contact_id.to_u32(); + let fingerprint = fingerprint.to_string(); + QrObject::ReviveVerifyContact { + contact_id, + fingerprint, + invitenumber, + authcode, + } + } + Qr::ReviveVerifyGroup { + grpname, + grpid, + contact_id, + fingerprint, + invitenumber, + authcode, + } => { + let contact_id = contact_id.to_u32(); + let fingerprint = fingerprint.to_string(); + QrObject::ReviveVerifyGroup { + grpname, + grpid, + contact_id, + fingerprint, + invitenumber, + authcode, + } + } + } + } +} diff --git a/deltachat-jsonrpc/typescript/generated/client.ts b/deltachat-jsonrpc/typescript/generated/client.ts index 5b3fcbeed..c278417da 100644 --- a/deltachat-jsonrpc/typescript/generated/client.ts +++ b/deltachat-jsonrpc/typescript/generated/client.ts @@ -123,6 +123,11 @@ export class RawClient { } + public checkQr(accountId: T.U32, qrContent: string): Promise { + return (this._transport.request('check_qr', [accountId, qrContent] as RPC.Params)) as Promise; + } + + public getConfig(accountId: T.U32, key: string): Promise<(string|null)> { return (this._transport.request('get_config', [accountId, key] as RPC.Params)) as Promise<(string|null)>; } diff --git a/deltachat-jsonrpc/typescript/generated/types.ts b/deltachat-jsonrpc/typescript/generated/types.ts index 9d07b0036..076541d45 100644 --- a/deltachat-jsonrpc/typescript/generated/types.ts +++ b/deltachat-jsonrpc/typescript/generated/types.ts @@ -1,97 +1,385 @@ // AUTO-GENERATED by typescript-type-def -export type U32=number; -export type Account=(({"type":"Configured";}&{"id":U32;"displayName":(string|null);"addr":(string|null);"profileImage":(string|null);"color":string;})|({"type":"Unconfigured";}&{"id":U32;})); -export type ProviderInfo={"beforeLoginHint":string;"overviewPage":string;"status":U32;}; -export type Usize=number; -export type ChatListEntry=[U32,U32]; -export type I64=number; -export type ChatListItemFetchResult=(({"type":"ChatListItem";}&{"id":U32;"name":string;"avatarPath":(string|null);"color":string;"lastUpdated":(I64|null);"summaryText1":string;"summaryText2":string;"summaryStatus":U32;"isProtected":boolean;"isGroup":boolean;"freshMessageCounter":Usize;"isSelfTalk":boolean;"isDeviceTalk":boolean;"isSendingLocation":boolean;"isSelfInGroup":boolean;"isArchived":boolean;"isPinned":boolean;"isMuted":boolean;"isContactRequest":boolean; -/** - * contact id if this is a dm chat (for view profile entry in context menu) - */ -"dmChatContact":(U32|null);})|{"type":"ArchiveLink";}|({"type":"Error";}&{"id":U32;"error":string;})); -export type Contact={"address":string;"color":string;"authName":string;"status":string;"displayName":string;"id":U32;"name":string;"profileImage":(string|null);"nameAndAddr":string;"isBlocked":boolean;"isVerified":boolean;}; -export type FullChat={"id":U32;"name":string;"isProtected":boolean;"profileImage":(string|null);"archived":boolean;"chatType":U32;"isUnpromoted":boolean;"isSelfTalk":boolean;"contacts":(Contact)[];"contactIds":(U32)[];"color":string;"freshMessageCounter":Usize;"isContactRequest":boolean;"isDeviceChat":boolean;"selfInGroup":boolean;"isMuted":boolean;"ephemeralTimer":U32;"canSend":boolean;}; -export type Viewtype=("Unknown"| -/** - * Text message. - */ -"Text"| -/** - * Image message. - * If the image is an animated GIF, the type `Viewtype.Gif` should be used. - */ -"Image"| -/** - * Animated GIF message. - */ -"Gif"| -/** - * Message containing a sticker, similar to image. - * If possible, the ui should display the image without borders in a transparent way. - * A click on a sticker will offer to install the sticker set in some future. - */ -"Sticker"| -/** - * Message containing an Audio file. - */ -"Audio"| -/** - * A voice message that was directly recorded by the user. - * For all other audio messages, the type `Viewtype.Audio` should be used. - */ -"Voice"| -/** - * Video messages. - */ -"Video"| -/** - * Message containing any file, eg. a PDF. - */ -"File"| -/** - * Message is an invitation to a videochat. - */ -"VideochatInvitation"| -/** - * Message is an webxdc instance. - */ -"Webxdc"); -export type I32=number; -export type U64=number; -export type Message={"id":U32;"chatId":U32;"fromId":U32;"quotedText":(string|null);"quotedMessageId":(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);}; -export type WebxdcMessageInfo={ -/** - * The name of the app. - * - * Defaults to the filename if not set in the manifest. - */ -"name":string; -/** - * App icon file name. - * Defaults to an standard icon if nothing is set in the manifest. - * - * To get the file, use dc_msg_get_webxdc_blob(). (not yet in jsonrpc, use rust api or cffi for it) - * - * App icons should should be square, - * the implementations will add round corners etc. as needed. - */ -"icon":string; -/** - * if the Webxdc represents a document, then this is the name of the document - */ -"document":(string|null); -/** - * short string describing the state of the app, - * sth. as "2 votes", "Highscore: 123", - * can be changed by the apps - */ -"summary":(string|null); -/** - * URL where the source code of the Webxdc and other information can be found; - * defaults to an empty string. - * Implementations may offer an menu or a button to open this URL. - */ -"sourceCodeUrl":(string|null);}; -export type __AllTyps=[string,boolean,Record,U32,U32,null,(U32)[],U32,null,(U32|null),(Account)[],U32,Account,U32,string,(ProviderInfo|null),U32,boolean,U32,Record,U32,string,(string|null),null,U32,Record,null,U32,string,null,U32,string,(string|null),U32,(string)[],Record,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,U32,FullChat,U32,U32,null,U32,U32,null,U32,string,string,U32,U32,U32,U32,(U32)[],U32,U32,Message,U32,(U32)[],Record,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,U32,Viewtype,(Viewtype|null),(Viewtype|null),(U32)[],U32,U32,string,string,null,U32,U32,U32,string,U32,U32,WebxdcMessageInfo,U32,string,U32,U32]; +export type U32 = number; +export type Account = + | ({ type: "Configured" } & { + id: U32; + displayName: string | null; + addr: string | null; + profileImage: string | null; + color: string; + }) + | ({ type: "Unconfigured" } & { id: U32 }); +export type ProviderInfo = { + beforeLoginHint: string; + overviewPage: string; + status: U32; +}; +export type Qr = + | ({ type: "askVerifyContact" } & { + contact_id: U32; + fingerprint: string; + invitenumber: string; + authcode: string; + }) + | ({ type: "askVerifyGroup" } & { + grpname: string; + grpid: string; + contact_id: U32; + fingerprint: string; + invitenumber: string; + authcode: string; + }) + | ({ type: "fprOk" } & { contact_id: U32 }) + | ({ type: "fprMismatch" } & { contact_id: U32 | null }) + | ({ type: "fprWithoutAddr" } & { fingerprint: string }) + | ({ type: "account" } & { domain: string }) + | ({ type: "webrtcInstance" } & { domain: string; instance_pattern: string }) + | ({ type: "addr" } & { contact_id: U32 }) + | ({ type: "url" } & { url: string }) + | ({ type: "text" } & { text: string }) + | ({ type: "withdrawVerifyContact" } & { + contact_id: U32; + fingerprint: string; + invitenumber: string; + authcode: string; + }) + | ({ type: "withdrawVerifyGroup" } & { + grpname: string; + grpid: string; + contact_id: U32; + fingerprint: string; + invitenumber: string; + authcode: string; + }) + | ({ type: "reviveVerifyContact" } & { + contact_id: U32; + fingerprint: string; + invitenumber: string; + authcode: string; + }) + | ({ type: "reviveVerifyGroup" } & { + grpname: string; + grpid: string; + contact_id: U32; + fingerprint: string; + invitenumber: string; + authcode: string; + }); +export type Usize = number; +export type ChatListEntry = [U32, U32]; +export type I64 = number; +export type ChatListItemFetchResult = + | ({ type: "ChatListItem" } & { + id: U32; + name: string; + avatarPath: string | null; + color: string; + lastUpdated: I64 | null; + summaryText1: string; + summaryText2: string; + summaryStatus: U32; + isProtected: boolean; + isGroup: boolean; + freshMessageCounter: Usize; + isSelfTalk: boolean; + isDeviceTalk: boolean; + isSendingLocation: boolean; + isSelfInGroup: boolean; + isArchived: boolean; + isPinned: boolean; + isMuted: boolean; + isContactRequest: boolean; + /** + * contact id if this is a dm chat (for view profile entry in context menu) + */ + dmChatContact: U32 | null; + }) + | { type: "ArchiveLink" } + | ({ type: "Error" } & { id: U32; error: string }); +export type Contact = { + address: string; + color: string; + authName: string; + status: string; + displayName: string; + id: U32; + name: string; + profileImage: string | null; + nameAndAddr: string; + isBlocked: boolean; + isVerified: boolean; +}; +export type FullChat = { + id: U32; + name: string; + isProtected: boolean; + profileImage: string | null; + archived: boolean; + chatType: U32; + isUnpromoted: boolean; + isSelfTalk: boolean; + contacts: Contact[]; + contactIds: U32[]; + color: string; + freshMessageCounter: Usize; + isContactRequest: boolean; + isDeviceChat: boolean; + selfInGroup: boolean; + isMuted: boolean; + ephemeralTimer: U32; + canSend: boolean; +}; +export type Viewtype = + | "Unknown" + /** + * Text message. + */ + | "Text" + /** + * Image message. + * If the image is an animated GIF, the type `Viewtype.Gif` should be used. + */ + | "Image" + /** + * Animated GIF message. + */ + | "Gif" + /** + * Message containing a sticker, similar to image. + * If possible, the ui should display the image without borders in a transparent way. + * A click on a sticker will offer to install the sticker set in some future. + */ + | "Sticker" + /** + * Message containing an Audio file. + */ + | "Audio" + /** + * A voice message that was directly recorded by the user. + * For all other audio messages, the type `Viewtype.Audio` should be used. + */ + | "Voice" + /** + * Video messages. + */ + | "Video" + /** + * Message containing any file, eg. a PDF. + */ + | "File" + /** + * Message is an invitation to a videochat. + */ + | "VideochatInvitation" + /** + * Message is an webxdc instance. + */ + | "Webxdc"; +export type I32 = number; +export type U64 = number; +export type Message = { + id: U32; + chatId: U32; + fromId: U32; + quotedText: string | null; + quotedMessageId: 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; +}; +export type WebxdcMessageInfo = { + /** + * The name of the app. + * + * Defaults to the filename if not set in the manifest. + */ + name: string; + /** + * App icon file name. + * Defaults to an standard icon if nothing is set in the manifest. + * + * To get the file, use dc_msg_get_webxdc_blob(). (not yet in jsonrpc, use rust api or cffi for it) + * + * App icons should should be square, + * the implementations will add round corners etc. as needed. + */ + icon: string; + /** + * if the Webxdc represents a document, then this is the name of the document + */ + document: string | null; + /** + * short string describing the state of the app, + * sth. as "2 votes", "Highscore: 123", + * can be changed by the apps + */ + summary: string | null; + /** + * URL where the source code of the Webxdc and other information can be found; + * defaults to an empty string. + * Implementations may offer an menu or a button to open this URL. + */ + sourceCodeUrl: string | null; +}; +export type __AllTyps = [ + string, + boolean, + Record, + U32, + U32, + null, + U32[], + U32, + null, + U32 | null, + Account[], + U32, + Account, + U32, + string, + ProviderInfo | null, + U32, + boolean, + U32, + Record, + U32, + string, + string | null, + null, + U32, + Record, + null, + U32, + string, + null, + U32, + string, + Qr, + U32, + string, + string | null, + U32, + string[], + Record, + 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, + U32, + FullChat, + U32, + U32, + null, + U32, + U32, + null, + U32, + string, + string, + U32, + U32, + U32, + U32, + U32[], + U32, + U32, + Message, + U32, + U32[], + Record, + 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, + U32, + Viewtype, + Viewtype | null, + Viewtype | null, + U32[], + U32, + U32, + string, + string, + null, + U32, + U32, + U32, + string, + U32, + U32, + WebxdcMessageInfo, + U32, + string, + U32, + U32 +];