address PR comments

This commit is contained in:
Dan Ballard 2022-07-15 14:39:32 -07:00
parent 907af56eac
commit 752d2967e0
1 changed files with 31 additions and 34 deletions

View File

@ -1,13 +1,10 @@
use std::borrow::Borrow;
use std::collections::HashMap;
use chrono::{DateTime, FixedOffset};
use chrono::format::Fixed::TimezoneOffset;
use chrono::prelude::*;
use chrono::offset::LocalResult;
use std::convert::From;
use crate::structs::{ACL, ConnectionState, CwtchEvent};
use crate::structs::{ACL, ConnectionState, CwtchEvent, Message, Profile};
#[derive(Debug)]
/// Profile ID used to refer to profiles in Cwtch
@ -211,10 +208,8 @@ pub enum Event {
picture: String,
/// is the profile online
online: String,
/// json of the contacts
contacts_json: String,
/// json of known servers
server_json: String, //ServerList
/// The deserialized profile with contacts and server info
profile_data: Result<Profile, String>,
},
/// Cwtch had an error at the app level (not profile level), usually in response to an API call
AppError {
@ -243,7 +238,7 @@ pub enum Event {
/// the percent of ACN boot (-1 to 100)
progress: i8,
/// an associated status message from the ACN
status: String
status: String,
},
/// Version of the ACN (currently tor)
ACNVersion {
@ -277,7 +272,7 @@ pub enum Event {
/// identity of server
server: ServerIdentity,
/// intent of the server to be running or not
intent: ServerIntent
intent: ServerIntent,
},
/// Notice a server was deleted (in response to an API call) and is no longer usable
ServerDeleted {
@ -313,7 +308,7 @@ pub enum Event {
/// time message was received
timestamp_received: DateTime<FixedOffset>,
/// the message
message: String,
message: Result<Message, serde_json::Error>,
/// notification instructions (based on settings)
notification: MessageNotification,
/// path to picture for the contact
@ -363,7 +358,8 @@ pub enum Event {
/// Notice from the network check plugin, a profile self check test by attempting to connecting to itself
NetworkStatus {
/// profile the check was performed on
profile: ProfileIdentity, // it's technically a profile self check
profile: ProfileIdentity,
// it's technically a profile self check
/// error if there was one (can be empty)
error: String,
/// status of profile self connection check
@ -409,7 +405,7 @@ pub enum Event {
/// contact id
contact: ContactIdentity,
/// error string
error: String
error: String,
},
/// a peer has acked a message
PeerAcknowledgement {
@ -435,7 +431,7 @@ pub enum Event {
/// message index
index: i32,
/// the message
message: String,
message: Result<Message, serde_json::Error>,
/// hash of the message
content_hash: String,
/// path to picture for sender
@ -488,7 +484,7 @@ pub enum Event {
/// server the group is on
group_server: String,
/// state of connection to server
state: ConnectionState
state: ConnectionState,
},
/// A getval call to a peer has returned a response
NewRetValMessageFromPeer {
@ -505,7 +501,7 @@ pub enum Event {
/// value
data: String,
/// optional filepath if there was a downloaded component
file_path: Option<String>
file_path: Option<String>,
},
/// result of a call to share a file, the filekey and manifest to operate on it
ShareManifest {
@ -514,7 +510,7 @@ pub enum Event {
/// filekey
filekey: FileKey,
/// serialized manifest of the share
serializedManifest: String,
serialized_manifest: String,
},
/// Information on a peer fileshare has been received
ManifestSizeReceived {
@ -592,15 +588,21 @@ impl From<&CwtchEvent> for Event {
match cwtch_event.event_type.as_str() {
"CwtchStarted" => Event::CwtchStarted,
"NewPeer" => Event::NewPeer {
profile: cwtch_event.data["Identity"].clone().into(),
tag: cwtch_event.data["tag"].clone(),
created: cwtch_event.data["Created"] == "true",
name: cwtch_event.data["name"].clone(),
default_picture: cwtch_event.data["defaultPicture"].clone(),
picture: cwtch_event.data["picture"].clone(),
online: cwtch_event.data["Online"].clone(),
contacts_json: cwtch_event.data["ContactsJson"].clone(),
server_json: cwtch_event.data["ServerList"].clone(),
profile: cwtch_event.data["Identity"].clone().into(),
tag: cwtch_event.data["tag"].clone(),
created: cwtch_event.data["Created"] == "true",
name: cwtch_event.data["name"].clone(),
default_picture: cwtch_event.data["defaultPicture"].clone(),
picture: cwtch_event.data["picture"].clone(),
online: cwtch_event.data["Online"].clone(),
profile_data: Profile::new(
&cwtch_event.data["Identity"],
&cwtch_event.data["name"],
&cwtch_event.data["picture"],
&cwtch_event.data["ContactsJson"],
&cwtch_event.data["ServerList"],
)
},
"NewMessageFromPeer" => Event::NewMessageFromPeer {
profile: cwtch_event.data["ProfileOnion"].clone().into(),
@ -608,7 +610,7 @@ impl From<&CwtchEvent> for Event {
contact: cwtch_event.data["RemotePeer"].clone().into(),
nick: cwtch_event.data["Nick"].clone(),
timestamp_received: DateTime::parse_from_rfc3339(cwtch_event.data["TimestampReceived"].as_str()).unwrap_or( DateTime::from(Utc::now())),
message: cwtch_event.data["Data"].clone(),
message: serde_json::from_str(&cwtch_event.data["Data"]),
notification: MessageNotification::from(cwtch_event.data["notification"].clone()),
picture: cwtch_event.data["Picture"].clone(),
},
@ -663,11 +665,6 @@ impl From<&CwtchEvent> for Event {
key: cwtch_event.data["Key"].clone(),
value: cwtch_event.data["Data"].clone(),
},
"IndexedAcknowledgement" => Event::IndexedAcknowledgement {
profile: cwtch_event.data["ProfileOnion"].clone().into(),
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-1),
index: cwtch_event.data["Index"].parse().unwrap_or(-1),
},
"IndexedAcknowledgement" => Event::IndexedFailure {
profile: cwtch_event.data["ProfileOnion"].clone().into(),
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-1).into(),
@ -678,7 +675,7 @@ impl From<&CwtchEvent> for Event {
"ShareManifest" => Event::ShareManifest {
profile: cwtch_event.data["ProfileOnion"].clone().into(),
filekey: cwtch_event.data["FileKey"].clone().into(),
serializedManifest: cwtch_event.data["SerializedManifest"].clone(),
serialized_manifest: cwtch_event.data["SerializedManifest"].clone(),
},
"NewServer" => Event::NewServer {
server: cwtch_event.data["Onion"].clone().into(),
@ -751,7 +748,7 @@ impl From<&CwtchEvent> for Event {
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2).into(),
contact: cwtch_event.data["RemotePeer"].clone().into(),
nick: cwtch_event.data["Nick"].clone(),
message: cwtch_event.data["Data"].clone(),
message: serde_json::from_str(&cwtch_event.data["Data"]),
notification: MessageNotification::from(cwtch_event.data["notification"].clone()),
picture: cwtch_event.data["Picture"].clone(),
},