1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::protocol::commands::FileNode;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EventResponseNodes {
#[serde(rename = "f")]
pub files: Vec<FileNode>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct NodeCreatedEventResponse {
/// The idempotence token of the operation for which this event is emitted.
#[serde(rename = "i")]
pub i: Option<String>,
/// The owner of the nodes.
#[serde(rename = "ou")]
pub owner: String,
/// The batch of created nodes.
#[serde(rename = "t")]
pub nodes: EventResponseNodes,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct NodeUpdatedEventResponse {
/// The idempotence token of the operation for which this event is emitted.
#[serde(rename = "i")]
pub i: Option<String>,
/// The handle of the updated node.
#[serde(rename = "n")]
pub handle: String,
/// The user handle of the new owner of the node.
#[serde(rename = "u")]
pub owner: String,
/// The new encoded attributes for the node.
#[serde(rename = "at")]
pub attr: String,
// /// The updated key for the node.
// ///
// /// Key updates are no longer supported by MEGA, but still transmitted for backwards compatibility.
// #[serde(rename = "k")]
// pub key: String,
/// The new creation date for the node.
#[serde(rename = "ts")]
pub ts: i64,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct NodeDeletedEventResponse {
/// The idempotence token of the operation for which this event is emitted.
#[serde(rename = "i")]
pub i: Option<String>,
/// The handle of the deleted node.
#[serde(rename = "n")]
pub handle: String,
/// This field is set to `1` if this event is due to a moved node.
#[serde(rename = "m")]
pub mov: Option<i32>,
/// The owner of the deleted node.
#[serde(rename = "ou")]
pub owner: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UnknownEventResponse {
#[serde(flatten)]
pub other: HashMap<String, json::Value>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "a")]
pub enum EventResponseKind {
/// One (or more) new nodes have been created.
#[serde(rename = "t")]
NodeCreated(NodeCreatedEventResponse),
/// A node's attributes have been updated.
#[serde(rename = "u")]
NodeUpdated(NodeUpdatedEventResponse),
/// One node (or more, if it had children) have been deleted.
#[serde(rename = "d")]
NodeDeleted(NodeDeletedEventResponse),
// TODO: "s": share addition/update/revocation
// TODO: "s2": share addition/update/revocation
// TODO: "c": contact addition/update
// TODO: "k": crypto key request
// TODO: "fa": file attribute update
// TODO: "ua": user attribute update
// TODO: "psts": account updated
// TODO: "ipc": incoming pending contact request (to us)
// TODO: "opc": outgoing pending contact request (from us)
// TODO: "upci": incoming pending contact request update (accept/deny/ignore)
// TODO: "upco": outgoing pending contact request update (from them, accept/deny/ignore)
// TODO: "ph": public links handles
// TODO: "se": set email
// TODO: "mcc": chat creation / peer's invitation / peer's removal
// TODO: "mcna": granted / revoked access to a node
// TODO: "uac": user access control
#[serde(other)]
UnknownEvent,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EventResponse {
#[serde(flatten)]
pub kind: EventResponseKind,
#[serde(flatten)]
pub other: HashMap<String, json::Value>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EventBatchResponseReady {
#[serde(rename = "sn")]
pub sn: String,
#[serde(rename = "a")]
pub events: Vec<json::Value>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EventBatchResponseWait {
#[serde(rename = "w")]
pub wait_url: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EventBatchResponse {
Ready(EventBatchResponseReady),
Wait(EventBatchResponseWait),
}