mirror of
https://github.com/chatmail/core.git
synced 2026-07-01 12:04:57 +03:00
Compare commits
5 Commits
jsonrpc-ap
...
jsonrpc_bl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54c30145e5 | ||
|
|
091eac2e91 | ||
|
|
fbcc402dfd | ||
|
|
b913c141d2 | ||
|
|
05629fe814 |
@@ -4442,40 +4442,28 @@ pub unsafe extern "C" fn dc_accounts_get_next_event(
|
||||
#[cfg(feature = "jsonrpc")]
|
||||
mod jsonrpc {
|
||||
use super::*;
|
||||
use deltachat_jsonrpc::api::DeltaChatApiV0;
|
||||
use deltachat_jsonrpc::api::CommandApi;
|
||||
use deltachat_jsonrpc::yerpc::{OutReceiver, RpcClient, RpcSession};
|
||||
|
||||
pub struct dc_jsonrpc_instance_t {
|
||||
receiver: OutReceiver,
|
||||
handle: RpcSession<DeltaChatApiV0>,
|
||||
handle: RpcSession<CommandApi>,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_jsonrpc_init(
|
||||
account_manager: *mut dc_accounts_t,
|
||||
api_version: *const libc::c_char,
|
||||
) -> *mut dc_jsonrpc_instance_t {
|
||||
if account_manager.is_null() {
|
||||
eprintln!("ignoring careless call to dc_jsonrpc_init()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
let api_version = to_string_lossy(api_version);
|
||||
|
||||
let rpc_api = match api_version.as_str() {
|
||||
"v0" => {
|
||||
deltachat_jsonrpc::api::DeltaChatApiV0::from_arc((*account_manager).inner.clone())
|
||||
}
|
||||
version => {
|
||||
eprintln!(
|
||||
"Error initializing JSON-RPC API: API version {} is not supported.",
|
||||
version
|
||||
);
|
||||
return ptr::null_mut();
|
||||
}
|
||||
};
|
||||
let cmd_api =
|
||||
deltachat_jsonrpc::api::CommandApi::from_arc((*account_manager).inner.clone());
|
||||
|
||||
let (request_handle, receiver) = RpcClient::new();
|
||||
let handle = RpcSession::new(request_handle, rpc_api);
|
||||
let handle = RpcSession::new(request_handle, cmd_api);
|
||||
|
||||
let instance = dc_jsonrpc_instance_t { receiver, handle };
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -34,20 +35,20 @@ use types::webxdc::WebxdcMessageInfo;
|
||||
use self::types::message::MessageViewtype;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DeltaChatApiV0 {
|
||||
pub struct CommandApi {
|
||||
pub(crate) accounts: Arc<RwLock<Accounts>>,
|
||||
}
|
||||
|
||||
impl DeltaChatApiV0 {
|
||||
impl CommandApi {
|
||||
pub fn new(accounts: Accounts) -> Self {
|
||||
DeltaChatApiV0 {
|
||||
CommandApi {
|
||||
accounts: Arc::new(RwLock::new(accounts)),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn from_arc(accounts: Arc<RwLock<Accounts>>) -> Self {
|
||||
DeltaChatApiV0 { accounts }
|
||||
CommandApi { accounts }
|
||||
}
|
||||
|
||||
async fn get_context(&self, id: u32) -> Result<deltachat::context::Context> {
|
||||
@@ -63,7 +64,7 @@ impl DeltaChatApiV0 {
|
||||
}
|
||||
|
||||
#[rpc(all_positional, ts_outdir = "typescript/generated")]
|
||||
impl DeltaChatApiV0 {
|
||||
impl CommandApi {
|
||||
// ---------------------------------------------
|
||||
// Misc top level functions
|
||||
// ---------------------------------------------
|
||||
@@ -202,6 +203,13 @@ impl DeltaChatApiV0 {
|
||||
qr::set_config_from_qr(&ctx, &qr_content).await
|
||||
}
|
||||
|
||||
async fn check_qr(&self, account_id: u32, qr_content: String) -> Result<QrObject> {
|
||||
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<Option<String>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
get_config(&ctx, &key).await
|
||||
|
||||
@@ -15,6 +15,7 @@ pub struct ContactObject {
|
||||
status: String,
|
||||
display_name: String,
|
||||
id: u32,
|
||||
last_seen: i64,
|
||||
name: String,
|
||||
profile_image: Option<String>, // BLOBS
|
||||
name_and_addr: String,
|
||||
@@ -40,6 +41,7 @@ impl ContactObject {
|
||||
status: contact.get_status().to_owned(),
|
||||
display_name: contact.get_display_name().to_owned(),
|
||||
id: contact.id.to_u32(),
|
||||
last_seen: contact.last_seen(),
|
||||
name: contact.get_name().to_owned(),
|
||||
profile_image, //BLOBS
|
||||
name_and_addr: contact.get_name_n_addr(),
|
||||
|
||||
@@ -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<String> {
|
||||
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<u32>,
|
||||
},
|
||||
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<Qr> 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
pub mod api;
|
||||
pub use api::events;
|
||||
pub use api::{Accounts, DeltaChatApiV0};
|
||||
pub use yerpc;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::api::{Accounts, DeltaChatApiV0};
|
||||
use super::api::{Accounts, CommandApi};
|
||||
use async_channel::unbounded;
|
||||
use futures::StreamExt;
|
||||
use tempfile::TempDir;
|
||||
@@ -15,7 +14,7 @@ mod tests {
|
||||
async fn basic_json_rpc_functionality() -> anyhow::Result<()> {
|
||||
let tmp_dir = TempDir::new().unwrap().path().into();
|
||||
let accounts = Accounts::new(tmp_dir).await?;
|
||||
let api = DeltaChatApiV0::new(accounts);
|
||||
let api = CommandApi::new(accounts);
|
||||
|
||||
let (sender, mut receiver) = unbounded::<String>();
|
||||
|
||||
@@ -56,7 +55,7 @@ mod tests {
|
||||
async fn test_batch_set_config() -> anyhow::Result<()> {
|
||||
let tmp_dir = TempDir::new().unwrap().path().into();
|
||||
let accounts = Accounts::new(tmp_dir).await?;
|
||||
let api = DeltaChatApiV0::new(accounts);
|
||||
let api = CommandApi::new(accounts);
|
||||
|
||||
let (sender, mut receiver) = unbounded::<String>();
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use yerpc::{RpcClient, RpcSession};
|
||||
|
||||
mod api;
|
||||
use api::events::event_to_json_rpc_notification;
|
||||
use api::{Accounts, DeltaChatApiV0};
|
||||
use api::{Accounts, CommandApi};
|
||||
|
||||
const DEFAULT_PORT: u16 = 20808;
|
||||
|
||||
@@ -20,10 +20,10 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
.unwrap_or(DEFAULT_PORT);
|
||||
log::info!("Starting with accounts directory `{path}`.");
|
||||
let accounts = Accounts::new(PathBuf::from(&path)).await.unwrap();
|
||||
let state = DeltaChatApiV0::new(accounts);
|
||||
let state = CommandApi::new(accounts);
|
||||
|
||||
let app = Router::new()
|
||||
.route("/rpc/v0", get(handler))
|
||||
.route("/ws", get(handler))
|
||||
.layer(Extension(state.clone()));
|
||||
|
||||
tokio::spawn(async move {
|
||||
@@ -40,7 +40,7 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handler(ws: WebSocketUpgrade, Extension(api): Extension<DeltaChatApiV0>) -> Response {
|
||||
async fn handler(ws: WebSocketUpgrade, Extension(api): Extension<CommandApi>) -> Response {
|
||||
let (client, out_receiver) = RpcClient::new();
|
||||
let session = RpcSession::new(client.clone(), api.clone());
|
||||
tokio::spawn(async move {
|
||||
|
||||
@@ -123,6 +123,11 @@ export class RawClient {
|
||||
}
|
||||
|
||||
|
||||
public checkQr(accountId: T.U32, qrContent: string): Promise<T.Qr> {
|
||||
return (this._transport.request('check_qr', [accountId, qrContent] as RPC.Params)) as Promise<T.Qr>;
|
||||
}
|
||||
|
||||
|
||||
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)>;
|
||||
}
|
||||
|
||||
@@ -1,97 +1,386 @@
|
||||
// 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<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,(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,null,U32,U32,null,U32,string,string,U32,U32,U32,U32,(U32)[],U32,U32,Message,U32,(U32)[],Record<U32,Message>,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,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;
|
||||
lastSeen: I64;
|
||||
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<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,
|
||||
null,
|
||||
U32,
|
||||
U32,
|
||||
null,
|
||||
U32,
|
||||
string,
|
||||
string,
|
||||
U32,
|
||||
U32,
|
||||
U32,
|
||||
U32,
|
||||
U32[],
|
||||
U32,
|
||||
U32,
|
||||
Message,
|
||||
U32,
|
||||
U32[],
|
||||
Record<U32, Message>,
|
||||
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,
|
||||
Viewtype,
|
||||
Viewtype | null,
|
||||
Viewtype | null,
|
||||
U32[],
|
||||
U32,
|
||||
U32,
|
||||
string,
|
||||
string,
|
||||
null,
|
||||
U32,
|
||||
U32,
|
||||
U32,
|
||||
string,
|
||||
U32,
|
||||
U32,
|
||||
WebxdcMessageInfo,
|
||||
U32,
|
||||
string,
|
||||
U32,
|
||||
U32
|
||||
];
|
||||
|
||||
@@ -115,7 +115,7 @@ export class AccountManager extends EventEmitter {
|
||||
debug('Started event handler')
|
||||
}
|
||||
|
||||
startJsonRpcHandler(callback: ((response: string) => void) | null, apiVersion: string = "v0") {
|
||||
startJsonRpcHandler(callback: ((response: string) => void) | null) {
|
||||
if (this.dcn_accounts === null) {
|
||||
throw new Error('dcn_account is null')
|
||||
}
|
||||
@@ -126,7 +126,7 @@ export class AccountManager extends EventEmitter {
|
||||
throw new Error('jsonrpc was started already')
|
||||
}
|
||||
|
||||
binding.dcn_accounts_start_jsonrpc(this.dcn_accounts, apiVersion, callback.bind(this))
|
||||
binding.dcn_accounts_start_jsonrpc(this.dcn_accounts, callback.bind(this))
|
||||
debug('Started JSON-RPC handler')
|
||||
this.jsonRpcStarted = true
|
||||
}
|
||||
|
||||
@@ -3313,10 +3313,9 @@ static void call_accounts_js_jsonrpc_handler(napi_env env, napi_value js_callbac
|
||||
}
|
||||
|
||||
NAPI_METHOD(dcn_accounts_start_jsonrpc) {
|
||||
NAPI_ARGV(3);
|
||||
NAPI_ARGV(2);
|
||||
NAPI_DCN_ACCOUNTS();
|
||||
NAPI_ARGV_UTF8_MALLOC(api_version, 1);
|
||||
napi_value callback = argv[2];
|
||||
napi_value callback = argv[1];
|
||||
|
||||
TRACE("calling..");
|
||||
napi_value async_resource_name;
|
||||
@@ -3339,7 +3338,7 @@ NAPI_METHOD(dcn_accounts_start_jsonrpc) {
|
||||
TRACE("done");
|
||||
|
||||
dcn_accounts->gc = 0;
|
||||
dcn_accounts->jsonrpc_instance = dc_jsonrpc_init(dcn_accounts->dc_accounts, api_version);
|
||||
dcn_accounts->jsonrpc_instance = dc_jsonrpc_init(dcn_accounts->dc_accounts);
|
||||
|
||||
TRACE("creating uv thread..");
|
||||
uv_thread_create(&dcn_accounts->jsonrpc_thread, accounts_jsonrpc_thread_func, dcn_accounts);
|
||||
|
||||
Reference in New Issue
Block a user