diff --git a/deltachat-jsonrpc/src/api/mod.rs b/deltachat-jsonrpc/src/api/mod.rs index 0bfe14693..7eccf14fa 100644 --- a/deltachat-jsonrpc/src/api/mod.rs +++ b/deltachat-jsonrpc/src/api/mod.rs @@ -8,6 +8,7 @@ use deltachat::{ message::{Message, MsgId, Viewtype}, provider::get_provider_info, qr, + webxdc::StatusUpdateSerial, }; use std::collections::BTreeMap; use std::sync::Arc; @@ -28,6 +29,7 @@ use types::chat_list::ChatListEntry; use types::contact::ContactObject; use types::message::MessageObject; use types::provider_info::ProviderInfo; +use types::webxdc::WebxdcMessageInfo; #[derive(Clone, Debug)] pub struct CommandApi { @@ -556,6 +558,46 @@ impl CommandApi { Ok(contacts) } + // --------------------------------------------- + // webxdc + // --------------------------------------------- + + async fn webxdc_send_status_update( + &self, + account_id: u32, + instance_msg_id: u32, + update_str: String, + description: String, + ) -> Result<()> { + let ctx = self.get_context(account_id).await?; + ctx.send_webxdc_status_update(MsgId::new(instance_msg_id), &update_str, &description) + .await + } + + async fn webxdc_get_status_updates( + &self, + account_id: u32, + instance_msg_id: u32, + last_known_serial: u32, + ) -> Result { + let ctx = self.get_context(account_id).await?; + ctx.get_webxdc_status_updates( + MsgId::new(instance_msg_id), + StatusUpdateSerial::new(last_known_serial), + ) + .await + } + + /// Get info from a webxdc message + async fn message_get_webxdc_info( + &self, + account_id: u32, + instance_msg_id: u32, + ) -> Result { + let ctx = self.get_context(account_id).await?; + WebxdcMessageInfo::get_for_message(&ctx, MsgId::new(instance_msg_id)).await + } + // --------------------------------------------- // misc prototyping functions // that might get removed later again diff --git a/deltachat-jsonrpc/src/api/types/mod.rs b/deltachat-jsonrpc/src/api/types/mod.rs index 1e524e0d4..cb9d63f09 100644 --- a/deltachat-jsonrpc/src/api/types/mod.rs +++ b/deltachat-jsonrpc/src/api/types/mod.rs @@ -4,7 +4,16 @@ pub mod chat_list; pub mod contact; pub mod message; pub mod provider_info; +pub mod webxdc; pub fn color_int_to_hex_string(color: u32) -> String { format!("{:#08x}", color).replace("0x", "#") } + +fn maybe_empty_string_to_option(string: String) -> Option { + if string.is_empty() { + None + } else { + Some(string) + } +} diff --git a/deltachat-jsonrpc/src/api/types/webxdc.rs b/deltachat-jsonrpc/src/api/types/webxdc.rs new file mode 100644 index 000000000..3adb24023 --- /dev/null +++ b/deltachat-jsonrpc/src/api/types/webxdc.rs @@ -0,0 +1,60 @@ +use deltachat::{ + context::Context, + message::{Message, MsgId}, + webxdc::WebxdcInfo, +}; +use serde::Serialize; +use typescript_type_def::TypeDef; + +use super::maybe_empty_string_to_option; + +#[derive(Serialize, TypeDef)] +#[serde(rename = "WebxdcMessageInfo")] +pub struct 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: Option, + /// short string describing the state of the app, + /// sth. as "2 votes", "Highscore: 123", + /// can be changed by the apps + summary: Option, + /// 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. + source_code_url: Option, +} + +impl WebxdcMessageInfo { + pub async fn get_for_message( + context: &Context, + instance_message_id: MsgId, + ) -> anyhow::Result { + let message = Message::load_from_db(context, instance_message_id).await?; + let WebxdcInfo { + name, + icon, + document, + summary, + source_code_url, + } = message.get_webxdc_info(context).await?; + + Ok(Self { + name, + icon, + document: maybe_empty_string_to_option(document), + summary: maybe_empty_string_to_option(summary), + source_code_url: maybe_empty_string_to_option(source_code_url), + }) + } +} diff --git a/deltachat-jsonrpc/typescript/generated/client.ts b/deltachat-jsonrpc/typescript/generated/client.ts index 26008653d..89aec72f1 100644 --- a/deltachat-jsonrpc/typescript/generated/client.ts +++ b/deltachat-jsonrpc/typescript/generated/client.ts @@ -287,6 +287,23 @@ export class RawClient { return (this._transport.request('contacts_get_contacts_by_ids', [accountId, ids] as RPC.Params)) as Promise>; } + + public webxdcSendStatusUpdate(accountId: T.U32, instanceMsgId: T.U32, updateStr: string, description: string): Promise { + return (this._transport.request('webxdc_send_status_update', [accountId, instanceMsgId, updateStr, description] as RPC.Params)) as Promise; + } + + + public webxdcGetStatusUpdates(accountId: T.U32, instanceMsgId: T.U32, lastKnownSerial: T.U32): Promise { + return (this._transport.request('webxdc_get_status_updates', [accountId, instanceMsgId, lastKnownSerial] as RPC.Params)) as Promise; + } + + /** + * Get info from a webxdc message + */ + public messageGetWebxdcInfo(accountId: T.U32, instanceMsgId: T.U32): Promise { + return (this._transport.request('message_get_webxdc_info', [accountId, instanceMsgId] as RPC.Params)) as Promise; + } + /** * Returns the messageid of the sent message */ diff --git a/deltachat-jsonrpc/typescript/generated/types.ts b/deltachat-jsonrpc/typescript/generated/types.ts index f4a4f9287..7e22055d6 100644 --- a/deltachat-jsonrpc/typescript/generated/types.ts +++ b/deltachat-jsonrpc/typescript/generated/types.ts @@ -16,4 +16,37 @@ export type FullChat={"id":U32;"name":string;"is_protected":boolean;"profile_ima export type I32=number; export type U64=number; export type Message={"id":U32;"chat_id":U32;"from_id":U32;"quoted_text":(string|null);"quoted_message_id":(U32|null);"text":(string|null);"has_location":boolean;"has_html":boolean;"view_type":U32;"state":U32;"timestamp":I64;"sort_timestamp":I64;"received_timestamp":I64;"has_deviating_timestamp":boolean;"subject":string;"show_padlock":boolean;"is_setupmessage":boolean;"is_info":boolean;"is_forwarded":boolean;"duration":I32;"dimensions_height":I32;"dimensions_width":I32;"videochat_type":(U32|null);"videochat_url":(string|null);"override_sender_name":(string|null);"sender":Contact;"setup_code_begin":(string|null);"file":(string|null);"file_mime":(string|null);"file_bytes":U64;"file_name":(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,string,U32,U32]; +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. + */ +"source_code_url":(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,string,string,null,U32,U32,U32,string,U32,U32,WebxdcMessageInfo,U32,string,U32,U32];