Compare commits

...

1 Commits

Author SHA1 Message Date
Sarah Jamie Lewis 8a13fe4ad9 Some Ideas 2022-07-07 15:13:36 -07:00
3 changed files with 72 additions and 37 deletions

View File

@ -50,6 +50,7 @@ macro_rules! c_bind {
} }
} }
}; };
// String return // String return
($func_name:ident ($($str1:ident: &str),* ; $($args:ident: $t:ty),* ; $($str2:ident: &str),*) $bind_fn:ident -> String) => { ($func_name:ident ($($str1:ident: &str),* ; $($args:ident: $t:ty),* ; $($str2:ident: &str),*) $bind_fn:ident -> String) => {
fn $func_name(&self, $($str1: &str, )* $($args: $t, )* $($str2: &str, )*) -> String { fn $func_name(&self, $($str1: &str, )* $($args: $t, )* $($str2: &str, )*) -> String {

View File

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

View File

@ -1,7 +1,7 @@
#![doc = include_str!( "../README.md" )] #![doc = include_str!( "../README.md" )]
#![doc(html_logo_url = "https://git.openprivacy.ca/cwtch.im/cwtch-ui/media/branch/trunk/cwtch.png")] #![doc(html_logo_url = "https://git.openprivacy.ca/cwtch.im/cwtch-ui/media/branch/trunk/cwtch.png")]
#![doc(html_root_url = "https://git.openprivacy.ca/cwtch.im/libcwtch-rs")] #![doc(html_root_url = "https://git.openprivacy.ca/cwtch.im/libcwtch-rs")]
#![deny(missing_docs)]
use crate::event::Event; use crate::event::Event;