mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 14:36:29 +03:00
use event name instead of event id
This commit is contained in:
@@ -109,7 +109,27 @@ pub struct Event {
|
|||||||
pub typ: EventType,
|
pub typ: EventType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
impl Deref for Event {
|
||||||
|
type Target = EventType;
|
||||||
|
|
||||||
|
fn deref(&self) -> &EventType {
|
||||||
|
&self.typ
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventType {
|
||||||
|
/// Returns the corresponding Event ID.
|
||||||
|
///
|
||||||
|
/// These are the IDs used in the `DC_EVENT_*` constants in `deltachat.h`.
|
||||||
|
pub fn as_id(&self) -> i32 {
|
||||||
|
self.get_str("id")
|
||||||
|
.expect("missing id")
|
||||||
|
.parse()
|
||||||
|
.expect("invalid id")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, EnumProperty, Display)]
|
||||||
pub enum EventType {
|
pub enum EventType {
|
||||||
/// The library-user may write an informational string to the log.
|
/// The library-user may write an informational string to the log.
|
||||||
///
|
///
|
||||||
@@ -327,7 +347,7 @@ impl EventType {
|
|||||||
pub fn to_json(&self, timestamp: Option<i64>) -> Value {
|
pub fn to_json(&self, timestamp: Option<i64>) -> Value {
|
||||||
let mut tree: serde_json::Map<String, Value> = serde_json::Map::new();
|
let mut tree: serde_json::Map<String, Value> = serde_json::Map::new();
|
||||||
|
|
||||||
tree.insert("event_type".to_string(), Value::Number(self.as_id().into()));
|
tree.insert("event_type".to_string(), Value::String(self.to_string()));
|
||||||
|
|
||||||
let (data1, data2) = match &self {
|
let (data1, data2) = match &self {
|
||||||
EventType::Info(data1)
|
EventType::Info(data1)
|
||||||
|
|||||||
Reference in New Issue
Block a user