jsonrpc: use camel-case for Event struct and move events.rs to types folder (#4372)

* use camel-case for Event struct and move events.rs to types folder

---------

Co-authored-by: link2xt <link2xt@testrun.org>
This commit is contained in:
Asiel Díaz Benítez
2023-05-08 12:49:19 +02:00
committed by GitHub
parent 3efbe5b1ef
commit 5c3df7e452
6 changed files with 9 additions and 9 deletions

View File

@@ -35,13 +35,13 @@ use tokio::sync::{watch, Mutex, RwLock};
use walkdir::WalkDir; use walkdir::WalkDir;
use yerpc::rpc; use yerpc::rpc;
pub mod events;
pub mod types; pub mod types;
use num_traits::FromPrimitive; use num_traits::FromPrimitive;
use types::account::Account; use types::account::Account;
use types::chat::FullChat; use types::chat::FullChat;
use types::contact::ContactObject; use types::contact::ContactObject;
use types::events::Event;
use types::http::HttpResponse; use types::http::HttpResponse;
use types::message::MessageData; use types::message::MessageData;
use types::message::MessageObject; use types::message::MessageObject;
@@ -49,7 +49,6 @@ use types::provider_info::ProviderInfo;
use types::reactions::JSONRPCReactions; use types::reactions::JSONRPCReactions;
use types::webxdc::WebxdcMessageInfo; use types::webxdc::WebxdcMessageInfo;
use self::events::Event;
use self::types::message::MessageLoadResult; use self::types::message::MessageLoadResult;
use self::types::{ use self::types::{
chat::{BasicChat, JSONRPCChatVisibility, MuteDuration}, chat::{BasicChat, JSONRPCChatVisibility, MuteDuration},

View File

@@ -3,6 +3,7 @@ use serde::Serialize;
use typescript_type_def::TypeDef; use typescript_type_def::TypeDef;
#[derive(Serialize, TypeDef)] #[derive(Serialize, TypeDef)]
#[serde(rename_all = "camelCase")]
pub struct Event { pub struct Event {
/// Event payload. /// Event payload.
event: EventType, event: EventType,

View File

@@ -2,6 +2,7 @@ pub mod account;
pub mod chat; pub mod chat;
pub mod chat_list; pub mod chat_list;
pub mod contact; pub mod contact;
pub mod events;
pub mod http; pub mod http;
pub mod location; pub mod location;
pub mod message; pub mod message;

View File

@@ -1,5 +1,4 @@
pub mod api; pub mod api;
pub use api::events;
pub use yerpc; pub use yerpc;
#[cfg(test)] #[cfg(test)]

View File

@@ -50,16 +50,16 @@ export class BaseDeltaChat<
async eventLoop(): Promise<void> { async eventLoop(): Promise<void> {
while (true) { while (true) {
const event = await this.rpc.getNextEvent(); const event = await this.rpc.getNextEvent();
this.emit(event.event.type, event.context_id, event.event as any); this.emit(event.event.type, event.contextId, event.event as any);
this.emit("ALL", event.context_id, event.event as any); this.emit("ALL", event.contextId, event.event as any);
if (this.contextEmitters[event.context_id]) { if (this.contextEmitters[event.contextId]) {
this.contextEmitters[event.context_id].emit( this.contextEmitters[event.contextId].emit(
event.event.type, event.event.type,
//@ts-ignore //@ts-ignore
event.event as any event.event as any
); );
this.contextEmitters[event.context_id].emit("ALL", event.event as any); this.contextEmitters[event.contextId].emit("ALL", event.event as any);
} }
} }
} }

View File

@@ -79,7 +79,7 @@ class Rpc:
if self.closing: if self.closing:
return return
event = await self.get_next_event() event = await self.get_next_event()
account_id = event["context_id"] account_id = event["contextId"]
queue = await self.get_queue(account_id) queue = await self.get_queue(account_id)
await queue.put(event["event"]) await queue.put(event["event"])