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