|
|
|
@ -7,8 +7,42 @@ use chrono::offset::LocalResult;
|
|
|
|
|
|
|
|
|
|
use crate::structs::{ACL, ConnectionState, CwtchEvent};
|
|
|
|
|
|
|
|
|
|
pub type Identity = String;
|
|
|
|
|
pub type Handle = String;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct ProfileIdentity(String);
|
|
|
|
|
|
|
|
|
|
impl Into<String> for ProfileIdentity {
|
|
|
|
|
fn into(self) -> String {
|
|
|
|
|
self.0.clone()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<String> for ProfileIdentity {
|
|
|
|
|
fn from(x: String) -> Self {
|
|
|
|
|
ProfileIdentity(x)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct ContactIdentity(String);
|
|
|
|
|
|
|
|
|
|
impl From<String> for ContactIdentity {
|
|
|
|
|
fn from(x: String) -> Self {
|
|
|
|
|
ContactIdentity(x)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct ServerIdentity(String);
|
|
|
|
|
|
|
|
|
|
impl From<String> for ServerIdentity {
|
|
|
|
|
fn from(x: String) -> Self {
|
|
|
|
|
ServerIdentity(x)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub type ConversationID = i32;
|
|
|
|
|
pub type FileKey = String;
|
|
|
|
|
|
|
|
|
@ -104,7 +138,7 @@ pub enum Event {
|
|
|
|
|
CwtchStarted,
|
|
|
|
|
/// A new peer has been loaded, details of peer. Identity should be stored so further API calls can be made
|
|
|
|
|
NewPeer {
|
|
|
|
|
identity: Identity,
|
|
|
|
|
identity: ProfileIdentity,
|
|
|
|
|
tag: String,
|
|
|
|
|
created: bool,
|
|
|
|
|
name: String,
|
|
|
|
@ -152,7 +186,7 @@ pub enum Event {
|
|
|
|
|
|
|
|
|
|
/// A new server has been loaded
|
|
|
|
|
NewServer {
|
|
|
|
|
onion: Identity,
|
|
|
|
|
onion: ServerIdentity,
|
|
|
|
|
server_bundle: String,
|
|
|
|
|
description: String,
|
|
|
|
|
storage_type: ServerStorageType,
|
|
|
|
@ -161,18 +195,18 @@ pub enum Event {
|
|
|
|
|
},
|
|
|
|
|
/// Response to request for server intent change, indicating the server is indending the new state
|
|
|
|
|
ServerIntentUpdate {
|
|
|
|
|
identity: Identity,
|
|
|
|
|
identity: ServerIdentity,
|
|
|
|
|
intent: ServerIntent
|
|
|
|
|
},
|
|
|
|
|
/// Notice a server was deleted (in response to an API call) and is no longer usable
|
|
|
|
|
ServerDeleted {
|
|
|
|
|
identity: Identity,
|
|
|
|
|
identity: ServerIdentity,
|
|
|
|
|
success: bool,
|
|
|
|
|
error: Option<String>,
|
|
|
|
|
},
|
|
|
|
|
/// Stats info for a server, periodically emited
|
|
|
|
|
ServerStatsUpdate {
|
|
|
|
|
identity: Identity,
|
|
|
|
|
identity: ServerIdentity,
|
|
|
|
|
total_messages: i32,
|
|
|
|
|
connections: i32,
|
|
|
|
|
},
|
|
|
|
@ -192,7 +226,7 @@ pub enum Event {
|
|
|
|
|
/// A new contact has been created (imported, added, or contacted by)
|
|
|
|
|
ContactCreated {
|
|
|
|
|
conversation_id: i32,
|
|
|
|
|
remote_peer: Identity,
|
|
|
|
|
remote_peer: ContactIdentity,
|
|
|
|
|
nick: String,
|
|
|
|
|
status: ConnectionState,
|
|
|
|
|
unread: i32,
|
|
|
|
@ -208,18 +242,18 @@ pub enum Event {
|
|
|
|
|
},
|
|
|
|
|
/// A peer has changed state
|
|
|
|
|
PeerStateChange {
|
|
|
|
|
remote_peer: Identity,
|
|
|
|
|
remote_peer: ContactIdentity,
|
|
|
|
|
connection_state: ConnectionState,
|
|
|
|
|
},
|
|
|
|
|
/// Notice from the network check plugin, a profile self check test by attempting to connecting to itself
|
|
|
|
|
NetworkStatus {
|
|
|
|
|
address: Identity,
|
|
|
|
|
address: ProfileIdentity,
|
|
|
|
|
error: String,
|
|
|
|
|
status: NetworkCheckStatus,
|
|
|
|
|
},
|
|
|
|
|
/// Information from the ACN about a peer
|
|
|
|
|
ACNInfo {
|
|
|
|
|
handle: Identity,
|
|
|
|
|
handle: ContactIdentity,
|
|
|
|
|
key: String,
|
|
|
|
|
data: String,
|
|
|
|
|
},
|
|
|
|
@ -237,20 +271,20 @@ pub enum Event {
|
|
|
|
|
IndexedFailure {
|
|
|
|
|
conversation_id: i32,
|
|
|
|
|
index: i32,
|
|
|
|
|
handle: Identity,
|
|
|
|
|
handle: ContactIdentity,
|
|
|
|
|
error: String
|
|
|
|
|
},
|
|
|
|
|
/// a peer has acked a message
|
|
|
|
|
PeerAcknowledgement {
|
|
|
|
|
event_id: String,
|
|
|
|
|
remote_peer: Identity,
|
|
|
|
|
remote_peer: ContactIdentity,
|
|
|
|
|
conversation_id: i32,
|
|
|
|
|
},
|
|
|
|
|
/// New message received on a group
|
|
|
|
|
NewMessageFromGroup {
|
|
|
|
|
conversation_id: i32,
|
|
|
|
|
timestamp_sent: DateTime<FixedOffset>,
|
|
|
|
|
remote_peer: Identity,
|
|
|
|
|
remote_peer: ContactIdentity,
|
|
|
|
|
index: i32,
|
|
|
|
|
message: String,
|
|
|
|
|
content_hash: String,
|
|
|
|
@ -284,7 +318,7 @@ pub enum Event {
|
|
|
|
|
},
|
|
|
|
|
/// A getval call to a peer has returned a response
|
|
|
|
|
NewRetValMessageFromPeer {
|
|
|
|
|
remote_peer: Identity,
|
|
|
|
|
remote_peer: ContactIdentity,
|
|
|
|
|
scope: String,
|
|
|
|
|
path: String,
|
|
|
|
|
exists: bool,
|
|
|
|
@ -300,22 +334,22 @@ pub enum Event {
|
|
|
|
|
ManifestSizeReceived {
|
|
|
|
|
filekey: String,
|
|
|
|
|
manifest_size: i32,
|
|
|
|
|
handle: String,
|
|
|
|
|
handle: ContactIdentity,
|
|
|
|
|
},
|
|
|
|
|
/// An error has occured while trying to parse a peer sharefile
|
|
|
|
|
ManifestError {
|
|
|
|
|
handle: Identity,
|
|
|
|
|
handle: ContactIdentity,
|
|
|
|
|
filekey: String,
|
|
|
|
|
},
|
|
|
|
|
/// A peer message about a shared file has been received
|
|
|
|
|
ManifestReceived {
|
|
|
|
|
handle: Identity,
|
|
|
|
|
handle: ContactIdentity,
|
|
|
|
|
filekey: String,
|
|
|
|
|
serialized_manifest: String,
|
|
|
|
|
},
|
|
|
|
|
/// a received manfiest has been saved
|
|
|
|
|
ManifestSaved {
|
|
|
|
|
handle: Identity,
|
|
|
|
|
handle: ContactIdentity,
|
|
|
|
|
filekey: String,
|
|
|
|
|
serialized_manifest: String,
|
|
|
|
|
temp_file: String,
|
|
|
|
@ -343,7 +377,7 @@ impl From<&CwtchEvent> for Event {
|
|
|
|
|
match cwtch_event.event_type.as_str() {
|
|
|
|
|
"CwtchStarted" => Event::CwtchStarted,
|
|
|
|
|
"NewPeer" => Event::NewPeer {
|
|
|
|
|
identity: cwtch_event.data["Identity"].clone(),
|
|
|
|
|
identity: cwtch_event.data["Identity"].clone().into(),
|
|
|
|
|
tag: cwtch_event.data["tag"].clone(),
|
|
|
|
|
created: cwtch_event.data["Created"] == "true",
|
|
|
|
|
name: cwtch_event.data["name"].clone(),
|
|
|
|
@ -368,7 +402,7 @@ impl From<&CwtchEvent> for Event {
|
|
|
|
|
},
|
|
|
|
|
"ContactCreated" => Event::ContactCreated {
|
|
|
|
|
conversation_id: cwtch_event.data["ConversationID"].clone().parse().unwrap_or(-2),
|
|
|
|
|
remote_peer: cwtch_event.data["RemotePeer"].clone(),
|
|
|
|
|
remote_peer: cwtch_event.data["RemotePeer"].clone().into(),
|
|
|
|
|
unread: cwtch_event.data["unread"].clone().parse().unwrap_or(0),
|
|
|
|
|
picture: cwtch_event.data["picture"].clone(),
|
|
|
|
|
default_picture: cwtch_event.data["defaultPicture"].clone(),
|
|
|
|
@ -382,7 +416,7 @@ impl From<&CwtchEvent> for Event {
|
|
|
|
|
last_msg_time: DateTime::parse_from_rfc3339(cwtch_event.data["lastMsgTime"].as_str()).unwrap_or(DateTime::from(Utc::now())),
|
|
|
|
|
},
|
|
|
|
|
"PeerStateChange" => Event::PeerStateChange {
|
|
|
|
|
remote_peer: cwtch_event.data["RemotePeer"].clone(),
|
|
|
|
|
remote_peer: cwtch_event.data["RemotePeer"].clone().into(),
|
|
|
|
|
connection_state: ConnectionState::from(cwtch_event.data["ConnectionState"].as_str()),
|
|
|
|
|
},
|
|
|
|
|
"UpdateGlobalSettings" => Event::UpdateGlobalSettings {
|
|
|
|
@ -396,12 +430,12 @@ impl From<&CwtchEvent> for Event {
|
|
|
|
|
},
|
|
|
|
|
"ACNVersion" => Event::ACNVersion { verstion: cwtch_event.data["Data"].clone()},
|
|
|
|
|
"NetworkError" => Event::NetworkStatus {
|
|
|
|
|
address: cwtch_event.data["Onion"].clone(),
|
|
|
|
|
address: cwtch_event.data["Onion"].clone().into(),
|
|
|
|
|
error: cwtch_event.data["Error"].clone(),
|
|
|
|
|
status: NetworkCheckStatus::from(cwtch_event.data["Status"].clone())
|
|
|
|
|
},
|
|
|
|
|
"ACNInfo" => Event::ACNInfo {
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone(),
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone().into(),
|
|
|
|
|
key: cwtch_event.data["Key"].clone(),
|
|
|
|
|
data: cwtch_event.data["Data"].clone(),
|
|
|
|
|
},
|
|
|
|
@ -416,7 +450,7 @@ impl From<&CwtchEvent> for Event {
|
|
|
|
|
"IndexedAcknowledgement" => Event::IndexedFailure {
|
|
|
|
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-1),
|
|
|
|
|
index: cwtch_event.data["Index"].parse().unwrap_or(-1),
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone(),
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone().into(),
|
|
|
|
|
error: cwtch_event.data["Error"].clone(),
|
|
|
|
|
},
|
|
|
|
|
"ShareManifest" => Event::ShareManifest {
|
|
|
|
@ -424,7 +458,7 @@ impl From<&CwtchEvent> for Event {
|
|
|
|
|
serializedManifest: cwtch_event.data["SerializedManifest"].clone(),
|
|
|
|
|
},
|
|
|
|
|
"NewServer" => Event::NewServer {
|
|
|
|
|
onion: cwtch_event.data["Onion"].clone(),
|
|
|
|
|
onion: cwtch_event.data["Onion"].clone().into(),
|
|
|
|
|
server_bundle: cwtch_event.data["ServerBundle"].clone(),
|
|
|
|
|
description: cwtch_event.data["Description"].clone(),
|
|
|
|
|
storage_type: ServerStorageType::from(cwtch_event.data["StorageType"].clone()),
|
|
|
|
@ -432,11 +466,11 @@ impl From<&CwtchEvent> for Event {
|
|
|
|
|
running: cwtch_event.data["Running"].parse().unwrap_or(false),
|
|
|
|
|
},
|
|
|
|
|
"ServerIntentUpdate" => Event::ServerIntentUpdate {
|
|
|
|
|
identity: cwtch_event.data["Identity"].clone(),
|
|
|
|
|
identity: cwtch_event.data["Identity"].clone().into(),
|
|
|
|
|
intent: ServerIntent::from(cwtch_event.data["Intent"].clone())
|
|
|
|
|
},
|
|
|
|
|
"ServerDeleted" => Event::ServerDeleted {
|
|
|
|
|
identity: cwtch_event.data["Identity"].clone(),
|
|
|
|
|
identity: cwtch_event.data["Identity"].clone().into(),
|
|
|
|
|
success: cwtch_event.data["Status"].clone() == "success",
|
|
|
|
|
error: match cwtch_event.data.get("Error") {
|
|
|
|
|
Some(e) => Some(e.clone()),
|
|
|
|
@ -444,26 +478,26 @@ impl From<&CwtchEvent> for Event {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"ServerStatsUpdate" => Event::ServerStatsUpdate {
|
|
|
|
|
identity: cwtch_event.data["Identity"].clone(),
|
|
|
|
|
identity: cwtch_event.data["Identity"].clone().into(),
|
|
|
|
|
total_messages: cwtch_event.data["TotalMessages"].parse().unwrap_or(0),
|
|
|
|
|
connections: cwtch_event.data["Connections"].parse().unwrap_or(0),
|
|
|
|
|
},
|
|
|
|
|
"ManifestSizeReceived" => Event::ManifestSizeReceived {
|
|
|
|
|
filekey: cwtch_event.data["FileKey"].clone(),
|
|
|
|
|
manifest_size: cwtch_event.data["ManifestSize"].parse().unwrap_or(0),
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone(),
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone().into(),
|
|
|
|
|
},
|
|
|
|
|
"ManifestError" => Event::ManifestError {
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone(),
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone().into(),
|
|
|
|
|
filekey: cwtch_event.data["FileKey"].clone(),
|
|
|
|
|
},
|
|
|
|
|
"ManifestReceived" => Event::ManifestReceived {
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone(),
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone().into(),
|
|
|
|
|
filekey: cwtch_event.data["FileKey"].clone(),
|
|
|
|
|
serialized_manifest: cwtch_event.data["SerializedManifest"].clone(),
|
|
|
|
|
},
|
|
|
|
|
"ManifestSaved" => Event::ManifestSaved {
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone(),
|
|
|
|
|
handle: cwtch_event.data["Handle"].clone().into(),
|
|
|
|
|
filekey: cwtch_event.data["FileKey"].clone(),
|
|
|
|
|
serialized_manifest: cwtch_event.data["SerializedManifest"].clone(),
|
|
|
|
|
temp_file: cwtch_event.data["TempFile"].clone(),
|
|
|
|
@ -477,7 +511,7 @@ impl From<&CwtchEvent> for Event {
|
|
|
|
|
},
|
|
|
|
|
"PeerAcknowledgement" => Event::PeerAcknowledgement {
|
|
|
|
|
event_id: cwtch_event.data["EventId"].clone(),
|
|
|
|
|
remote_peer: cwtch_event.data["RemotePeer"].clone(),
|
|
|
|
|
remote_peer: cwtch_event.data["RemotePeer"].clone().into(),
|
|
|
|
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(0)
|
|
|
|
|
},
|
|
|
|
|
"NewMessageFromGroup" => Event::NewMessageFromGroup {
|
|
|
|
@ -485,7 +519,7 @@ impl From<&CwtchEvent> for Event {
|
|
|
|
|
index: cwtch_event.data["RemotePeer"].parse().unwrap_or(-1),
|
|
|
|
|
content_hash: cwtch_event.data["ContentHash"].clone(),
|
|
|
|
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2),
|
|
|
|
|
remote_peer: cwtch_event.data["RemotePeer"].clone(),
|
|
|
|
|
remote_peer: cwtch_event.data["RemotePeer"].clone().into(),
|
|
|
|
|
nick: cwtch_event.data["Nick"].clone(),
|
|
|
|
|
message: cwtch_event.data["Data"].clone(),
|
|
|
|
|
notification: MessageNotification::from(cwtch_event.data["notification"].clone()),
|
|
|
|
@ -513,7 +547,7 @@ impl From<&CwtchEvent> for Event {
|
|
|
|
|
state: ConnectionState::from(cwtch_event.data["ConnectionState"].as_str()),
|
|
|
|
|
},
|
|
|
|
|
"NewRetValMessageFromPeer" => Event::NewRetValMessageFromPeer {
|
|
|
|
|
remote_peer: cwtch_event.data["RemotePeer"].clone(),
|
|
|
|
|
remote_peer: cwtch_event.data["RemotePeer"].clone().into(),
|
|
|
|
|
scope: cwtch_event.data["Scope"].clone(),
|
|
|
|
|
path: cwtch_event.data["Path"].clone(),
|
|
|
|
|
exists: cwtch_event.data["Exists"].parse().unwrap_or(false),
|
|
|
|
|