mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
* integrate json-rpc repo https://github.com/deltachat/deltachat-jsonrpc * get target dir from cargo * fix clippy * use node 16 in ci use `npm i` instead of `npm ci` try fix ci script and fix a doc comment * fix get_provider_info docs * refactor function name * fix formatting make test pass fix clippy * update .gitignore * change now returns event names as id directly, no conversion method or number ids anymore also longer timeout for requesting test accounts from mailadm * fix compile after rebase * add json api to cffi and expose it in dc node * add some files to npm ignore that don't need to be in the npm package * add jsonrpc crate to set_core_version * add jsonrpc feature flag * call a jsonrpc function in segfault example * break loop on empty response * fix closing segfault thanks again to link2xt for figguring this out * activate other tests again * remove selectAccount from highlevel client * put jsonrpc stuff in own module * disable jsonrpc by default * add @deltachat/jsonrpc-client to make sure its dependencies are installed, too whwn installing dc-node * commit types.ts that dc-node has everything it needs to provide @deltachat/jsonrpc-client without an extra ts compile step * improve naming * Changes for tokio compat, upgrade to yerpc 0.3 This also changes the webserver binary to use axum in place of tide. * Improvements to typescript package * Improve docs. * improve docs, fix example * Fix CFFI for JSON-RPC changes * use stable toolchain not 1.56.0 * fix ci * try to fix ci * remove emtpy file allow unused code for new_from_arc * expose anyhow errors feature name was wrong * use multi-threaded runtime in JSON-RPC webserver * improve test setup and code style * don't wait for IO on webserver start * Bump yerpc to 0.3.1 with fix for axum server * update todo document remove specific api stuff for now, we now have the an incremental aproach on moving not the all at-once effort I though it would be * remove debug logs * changelog entry about the jsonrpc * Fix method name casings and cleanups * Improve JSON-RPC CI, no need to build things multiple times * Naming consistency: Use DeltaChat not Deltachat * Improve documentation * fix docs * adress dig's comments - description in cargo.toml - impl From<EventType> for EventTypeName - rename `CommandApi::new_from_arc` -> `CommandApi::from_arc` - pre-allocate if we know the entry count already - remove unused enumerate - remove unused serde attribute comment - rename `FullChat::from_dc_chat_id` -> `FullChat::try_from_dc_chat_id` * make it more idiomatic: rename `ContactObject::from_dc_contact -> `ContactObject::try_from_dc_contact` * apply link2xt's suggestions: - unref jsonrpc_instance in same thread it was created in - increase `max_queue_size` from 1 to 1000 * reintroduce segfault test script * remove unneeded context thanks to link2xt for pointing that out * Update deltachat-ffi/deltachat.h Co-authored-by: bjoern <r10s@b44t.com> * Update deltachat-ffi/deltachat.h Co-authored-by: bjoern <r10s@b44t.com> * make sure to use dc_str_unref instead of free on cstrings returned/owned by rust * Increase online test timeouts for CI * fix the typos thanks to ralphtheninja for finding them * restore same configure behaviour as desktop: make configure restart io with the old configuration if it had one on error * found another segfault: this time in batch_set_config * remove print from test * make dcn_json_rpc_request return undefined instead of not returning this might have been the cause for the second segfault * add set_config_from_qr to jsonrpc * add `add_device_message` to jsonrpc * jsonrpc: add `get_fresh_msgs` and `get_fresh_msg_cnt` * jsonrpc: add dm_chat_contact to ChatListItemFetchResult * add webxdc methods to jsonrpc: - `webxdc_send_status_update` - `webxdc_get_status_updates` - `message_get_webxdc_info` * add `chat_get_media` to jsonrpc also add viewtype wrapper enum and use it in `MessageObject`, additionally to using it in `chat_get_media` * use camelCase in all js object properties * Add check_qr function to jsonrpc * Fixed clippy errors and formatting * Fixed formatting * fix changelog ordering after rebase * fix compile after merging in master branch Co-authored-by: Simon Laux <mobile.info@simonlaux.de> Co-authored-by: Simon Laux <Simon-Laux@users.noreply.github.com> Co-authored-by: bjoern <r10s@b44t.com> Co-authored-by: flipsimon <28535045+flipsimon@users.noreply.github.com>
93 lines
3.6 KiB
Rust
93 lines
3.6 KiB
Rust
pub mod api;
|
|
pub use api::events;
|
|
pub use yerpc;
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::api::{Accounts, CommandApi};
|
|
use async_channel::unbounded;
|
|
use futures::StreamExt;
|
|
use tempfile::TempDir;
|
|
use yerpc::{RpcClient, RpcSession};
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
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 = CommandApi::new(accounts);
|
|
|
|
let (sender, mut receiver) = unbounded::<String>();
|
|
|
|
let (client, mut rx) = RpcClient::new();
|
|
let session = RpcSession::new(client, api);
|
|
tokio::spawn({
|
|
async move {
|
|
while let Some(message) = rx.next().await {
|
|
let message = serde_json::to_string(&message)?;
|
|
sender.send(message).await?;
|
|
}
|
|
let res: Result<(), anyhow::Error> = Ok(());
|
|
res
|
|
}
|
|
});
|
|
|
|
{
|
|
let request = r#"{"jsonrpc":"2.0","method":"add_account","params":[],"id":1}"#;
|
|
let response = r#"{"jsonrpc":"2.0","id":1,"result":1}"#;
|
|
session.handle_incoming(request).await;
|
|
let result = receiver.next().await;
|
|
println!("{:?}", result);
|
|
assert_eq!(result, Some(response.to_owned()));
|
|
}
|
|
{
|
|
let request = r#"{"jsonrpc":"2.0","method":"get_all_account_ids","params":[],"id":2}"#;
|
|
let response = r#"{"jsonrpc":"2.0","id":2,"result":[1]}"#;
|
|
session.handle_incoming(request).await;
|
|
let result = receiver.next().await;
|
|
println!("{:?}", result);
|
|
assert_eq!(result, Some(response.to_owned()));
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
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 = CommandApi::new(accounts);
|
|
|
|
let (sender, mut receiver) = unbounded::<String>();
|
|
|
|
let (client, mut rx) = RpcClient::new();
|
|
let session = RpcSession::new(client, api);
|
|
tokio::spawn({
|
|
async move {
|
|
while let Some(message) = rx.next().await {
|
|
let message = serde_json::to_string(&message)?;
|
|
sender.send(message).await?;
|
|
}
|
|
let res: Result<(), anyhow::Error> = Ok(());
|
|
res
|
|
}
|
|
});
|
|
|
|
{
|
|
let request = r#"{"jsonrpc":"2.0","method":"add_account","params":[],"id":1}"#;
|
|
let response = r#"{"jsonrpc":"2.0","id":1,"result":1}"#;
|
|
session.handle_incoming(request).await;
|
|
let result = receiver.next().await;
|
|
assert_eq!(result, Some(response.to_owned()));
|
|
}
|
|
{
|
|
let request = r#"{"jsonrpc":"2.0","method":"batch_set_config","id":2,"params":[1,{"addr":"","mail_user":"","mail_pw":"","mail_server":"","mail_port":"","mail_security":"","imap_certificate_checks":"","send_user":"","send_pw":"","send_server":"","send_port":"","send_security":"","smtp_certificate_checks":"","socks5_enabled":"0","socks5_host":"","socks5_port":"","socks5_user":"","socks5_password":""}]}"#;
|
|
let response = r#"{"jsonrpc":"2.0","id":2,"result":null}"#;
|
|
session.handle_incoming(request).await;
|
|
let result = receiver.next().await;
|
|
assert_eq!(result, Some(response.to_owned()));
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|