mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 23:06:32 +03:00
Fix method name casings and cleanups
This commit is contained in:
committed by
Simon Laux
parent
69d9d48ae4
commit
e7da0672ae
@@ -10,20 +10,20 @@
|
|||||||
- `void dc_jsonrpc_request(dc_jsonrpc_instance_t* jsonrpc_instance, char* request);`
|
- `void dc_jsonrpc_request(dc_jsonrpc_instance_t* jsonrpc_instance, char* request);`
|
||||||
- `char* dc_jsonrpc_next_response(dc_jsonrpc_instance_t* jsonrpc_instance);`
|
- `char* dc_jsonrpc_next_response(dc_jsonrpc_instance_t* jsonrpc_instance);`
|
||||||
- node: json rpc methods #3463:
|
- node: json rpc methods #3463:
|
||||||
- `AccountManager.prototype.startJSONRPCHandler(callback: ((response: string) => void)): void`
|
- `AccountManager.prototype.startJsonRpcHandler(callback: ((response: string) => void)): void`
|
||||||
- `AccountManager.prototype.jsonRPCRequest(message: string): void`
|
- `AccountManager.prototype.jsonRpcRequest(message: string): void`
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
- Implemented "Automatic e-mail address Porting" (AEAP). You can
|
- Implemented "Automatic e-mail address Porting" (AEAP). You can
|
||||||
configure a new address in DC now, and when receivers get messages
|
configure a new address in DC now, and when receivers get messages
|
||||||
they will automatically recognize your moving to a new address. #3385
|
they will automatically recognize your moving to a new address. #3385
|
||||||
|
- added a JSON RPC API, accessible through a WebSocket server, the CFFI bindings and the Node.js bindings #3463
|
||||||
- switch from `async-std` to `tokio` as the async runtime #3449
|
- switch from `async-std` to `tokio` as the async runtime #3449
|
||||||
- upgrade to `pgp@0.8.0` #3467
|
- upgrade to `pgp@0.8.0` #3467
|
||||||
- add IMAP ID extension support #3468
|
- add IMAP ID extension support #3468
|
||||||
- configure DeltaChat folder by selecting it, so it is configured even if not LISTed #3371
|
- configure DeltaChat folder by selecting it, so it is configured even if not LISTed #3371
|
||||||
- build PyPy wheels #6683
|
- build PyPy wheels #6683
|
||||||
- improve default error if NDN does not provide an error #3456
|
- improve default error if NDN does not provide an error #3456
|
||||||
- integrate [deltachat-jsonrpc](https://github.com/deltachat/deltachat-jsonrpc) into this repo and into cffi and node-bindings #3463
|
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- mailing list: remove square-brackets only for first name #3452
|
- mailing list: remove square-brackets only for first name #3452
|
||||||
|
|||||||
@@ -12,23 +12,18 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn basic_json_rpc_functionality() -> anyhow::Result<()> {
|
async fn basic_json_rpc_functionality() -> anyhow::Result<()> {
|
||||||
// println!("{}", "");
|
|
||||||
let tmp_dir = TempDir::new().unwrap().path().into();
|
let tmp_dir = TempDir::new().unwrap().path().into();
|
||||||
println!("tmp_dir: {:?}", tmp_dir);
|
|
||||||
|
|
||||||
let accounts = Accounts::new(tmp_dir).await?;
|
let accounts = Accounts::new(tmp_dir).await?;
|
||||||
let cmd_api = CommandApi::new(accounts);
|
let api = CommandApi::new(accounts);
|
||||||
|
|
||||||
let (sender, mut receiver) = unbounded::<String>();
|
let (sender, mut receiver) = unbounded::<String>();
|
||||||
|
|
||||||
let (client, mut rx) = RpcClient::new();
|
let (client, mut rx) = RpcClient::new();
|
||||||
let session = cmd_api;
|
let session = RpcSession::new(client, api);
|
||||||
let handle = RpcSession::new(client, session);
|
|
||||||
tokio::spawn({
|
tokio::spawn({
|
||||||
async move {
|
async move {
|
||||||
while let Some(message) = rx.next().await {
|
while let Some(message) = rx.next().await {
|
||||||
let message = serde_json::to_string(&message)?;
|
let message = serde_json::to_string(&message)?;
|
||||||
// Abort serialization on error.
|
|
||||||
sender.send(message).await?;
|
sender.send(message).await?;
|
||||||
}
|
}
|
||||||
let res: Result<(), anyhow::Error> = Ok(());
|
let res: Result<(), anyhow::Error> = Ok(());
|
||||||
@@ -39,7 +34,7 @@ mod tests {
|
|||||||
{
|
{
|
||||||
let request = r#"{"jsonrpc":"2.0","method":"add_account","params":[],"id":1}"#;
|
let request = r#"{"jsonrpc":"2.0","method":"add_account","params":[],"id":1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","id":1,"result":1}"#;
|
let response = r#"{"jsonrpc":"2.0","id":1,"result":1}"#;
|
||||||
handle.handle_incoming(request).await;
|
session.handle_incoming(request).await;
|
||||||
let result = receiver.next().await;
|
let result = receiver.next().await;
|
||||||
println!("{:?}", result);
|
println!("{:?}", result);
|
||||||
assert_eq!(result, Some(response.to_owned()));
|
assert_eq!(result, Some(response.to_owned()));
|
||||||
@@ -47,7 +42,7 @@ mod tests {
|
|||||||
{
|
{
|
||||||
let request = r#"{"jsonrpc":"2.0","method":"get_all_account_ids","params":[],"id":2}"#;
|
let request = r#"{"jsonrpc":"2.0","method":"get_all_account_ids","params":[],"id":2}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","id":2,"result":[1]}"#;
|
let response = r#"{"jsonrpc":"2.0","id":2,"result":[1]}"#;
|
||||||
handle.handle_incoming(request).await;
|
session.handle_incoming(request).await;
|
||||||
let result = receiver.next().await;
|
let result = receiver.next().await;
|
||||||
println!("{:?}", result);
|
println!("{:?}", result);
|
||||||
assert_eq!(result, Some(response.to_owned()));
|
assert_eq!(result, Some(response.to_owned()));
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ export class AccountManager extends EventEmitter {
|
|||||||
debug('Started event handler')
|
debug('Started event handler')
|
||||||
}
|
}
|
||||||
|
|
||||||
startJSONRPCHandler(callback: ((response: string) => void) | null) {
|
startJsonRpcHandler(callback: ((response: string) => void) | null) {
|
||||||
if (this.dcn_accounts === null) {
|
if (this.dcn_accounts === null) {
|
||||||
throw new Error('dcn_account is null')
|
throw new Error('dcn_account is null')
|
||||||
}
|
}
|
||||||
@@ -127,14 +127,14 @@ export class AccountManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.dcn_accounts_start_jsonrpc(this.dcn_accounts, callback.bind(this))
|
binding.dcn_accounts_start_jsonrpc(this.dcn_accounts, callback.bind(this))
|
||||||
debug('Started jsonrpc handler')
|
debug('Started JSON-RPC handler')
|
||||||
this.jsonRpcStarted = true
|
this.jsonRpcStarted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonRPCRequest(message: string) {
|
jsonRpcRequest(message: string) {
|
||||||
if (!this.jsonRpcStarted) {
|
if (!this.jsonRpcStarted) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'jsonrpc is not active, start it with startJSONRPCHandler first'
|
'jsonrpc is not active, start it with startJsonRpcHandler first'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
binding.dcn_json_rpc_request(this.dcn_accounts, message)
|
binding.dcn_json_rpc_request(this.dcn_accounts, message)
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ describe('JSON RPC', function () {
|
|||||||
const promise = new Promise((res, _rej) => {
|
const promise = new Promise((res, _rej) => {
|
||||||
promise_resolve = res
|
promise_resolve = res
|
||||||
})
|
})
|
||||||
dc.startJSONRPCHandler(promise_resolve)
|
dc.startJsonRpcHandler(promise_resolve)
|
||||||
dc.jsonRPCRequest(
|
dc.jsonRpcRequest(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
method: 'get_all_account_ids',
|
method: 'get_all_account_ids',
|
||||||
@@ -115,13 +115,13 @@ describe('JSON RPC', function () {
|
|||||||
const { dc } = DeltaChat.newTemporary()
|
const { dc } = DeltaChat.newTemporary()
|
||||||
|
|
||||||
const promises = {}
|
const promises = {}
|
||||||
dc.startJSONRPCHandler((msg) => {
|
dc.startJsonRpcHandler((msg) => {
|
||||||
const response = JSON.parse(msg)
|
const response = JSON.parse(msg)
|
||||||
promises[response.id](response)
|
promises[response.id](response)
|
||||||
delete promises[response.id]
|
delete promises[response.id]
|
||||||
})
|
})
|
||||||
const call = (request) => {
|
const call = (request) => {
|
||||||
dc.jsonRPCRequest(JSON.stringify(request))
|
dc.jsonRpcRequest(JSON.stringify(request))
|
||||||
return new Promise((res, _rej) => {
|
return new Promise((res, _rej) => {
|
||||||
promises[request.id] = res
|
promises[request.id] = res
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user