typed IDs for most things, docs for all
This commit is contained in:
parent
bd5d3f7e5f
commit
384c5880b2
375
src/event.rs
375
src/event.rs
|
@ -4,13 +4,69 @@ use chrono::{DateTime, FixedOffset};
|
||||||
use chrono::format::Fixed::TimezoneOffset;
|
use chrono::format::Fixed::TimezoneOffset;
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use chrono::offset::LocalResult;
|
use chrono::offset::LocalResult;
|
||||||
|
use std::convert::From;
|
||||||
|
|
||||||
use crate::structs::{ACL, ConnectionState, CwtchEvent};
|
use crate::structs::{ACL, ConnectionState, CwtchEvent};
|
||||||
|
|
||||||
pub type Identity = String;
|
#[derive(Debug)]
|
||||||
pub type Handle = String;
|
/// Profile ID used to refer to profiles in Cwtch
|
||||||
pub type ConversationID = i32;
|
pub struct ProfileIdentity(String);
|
||||||
pub type FileKey = String;
|
|
||||||
|
impl From<String> for ProfileIdentity {
|
||||||
|
fn from(x: String) -> Self {
|
||||||
|
ProfileIdentity(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// Contact ID used to refer to contacts in Cwtch
|
||||||
|
pub struct ContactIdentity(String);
|
||||||
|
|
||||||
|
impl From<String> for ContactIdentity {
|
||||||
|
fn from(x: String) -> Self {
|
||||||
|
ContactIdentity(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// Conversation ID user to refer to a conversation with a Contact or Group in Cwtch
|
||||||
|
pub struct ConversationID(i32) ;
|
||||||
|
|
||||||
|
impl From<i32> for ConversationID {
|
||||||
|
fn from(x: i32) -> Self {
|
||||||
|
ConversationID(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// Group ID used to refer to a Group in Cwtch
|
||||||
|
pub struct GroupID(String) ;
|
||||||
|
|
||||||
|
impl From<String> for GroupID {
|
||||||
|
fn from(x: String) -> Self {
|
||||||
|
GroupID(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// Server ID user to refer to a server in Cwtch
|
||||||
|
pub struct ServerIdentity(String);
|
||||||
|
|
||||||
|
impl From<String> for ServerIdentity {
|
||||||
|
fn from(x: String) -> Self {
|
||||||
|
ServerIdentity(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// FileKey ID user to refer to a file share in Cwtch
|
||||||
|
pub struct FileKey(String);
|
||||||
|
|
||||||
|
impl From<String> for FileKey {
|
||||||
|
fn from(x: String) -> Self {
|
||||||
|
FileKey(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
/// Enum for type of notification a UI/client should emit for a new message
|
/// Enum for type of notification a UI/client should emit for a new message
|
||||||
|
@ -104,31 +160,44 @@ 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 field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// optional client specified tag
|
||||||
tag: String,
|
tag: String,
|
||||||
|
/// is this a newly created profile event, or a load
|
||||||
created: bool,
|
created: bool,
|
||||||
|
/// user supplied name of the profile
|
||||||
name: String,
|
name: String,
|
||||||
|
/// default picture path
|
||||||
default_picture: String,
|
default_picture: String,
|
||||||
|
/// user supplied picture path
|
||||||
picture: String,
|
picture: String,
|
||||||
|
/// is the profile online
|
||||||
online: String,
|
online: String,
|
||||||
|
/// json of the contacts
|
||||||
contacts_json: String,
|
contacts_json: String,
|
||||||
|
/// json of known servers
|
||||||
server_json: String, //ServerList
|
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 {
|
||||||
|
/// details of the app error that occured
|
||||||
error: String
|
error: String
|
||||||
},
|
},
|
||||||
/// Global settings being emited from lcg, usually in response to them being sent to be saved by client
|
/// Global settings being emited from lcg, usually in response to them being sent to be saved by client
|
||||||
UpdateGlobalSettings {
|
UpdateGlobalSettings {
|
||||||
|
/// map of setting names to values (https://git.openprivacy.ca/cwtch.im/libcwtch-go/src/branch/trunk/utils/settings.go)
|
||||||
settings: HashMap<String, String>,
|
settings: HashMap<String, String>,
|
||||||
},
|
},
|
||||||
/// A profile has an error, usually emited in response to an API call
|
/// A profile has an error, usually emited in response to an API call
|
||||||
PeerError {
|
PeerError {
|
||||||
|
/// details of the peer error that occured
|
||||||
error: String
|
error: String
|
||||||
},
|
},
|
||||||
/// A profile was successfully deleted, it is no longer usable
|
/// A profile was successfully deleted, it is no longer usable
|
||||||
PeerDeleted {
|
PeerDeleted {
|
||||||
identity: String
|
/// identity of deleted peer
|
||||||
|
profile: ProfileIdentity
|
||||||
},
|
},
|
||||||
/// Cwtch is shutting down, stop making API calls
|
/// Cwtch is shutting down, stop making API calls
|
||||||
Shutdown,
|
Shutdown,
|
||||||
|
@ -141,7 +210,8 @@ pub enum Event {
|
||||||
},
|
},
|
||||||
/// Version of the ACN (currently tor)
|
/// Version of the ACN (currently tor)
|
||||||
ACNVersion {
|
ACNVersion {
|
||||||
verstion: String,
|
/// version string from ACN app
|
||||||
|
version: String,
|
||||||
},
|
},
|
||||||
/// Notice from libCwtch that before completing load of a profile a storage migration is occuring so Start will take longer
|
/// Notice from libCwtch that before completing load of a profile a storage migration is occuring so Start will take longer
|
||||||
StartingStorageMiragtion,
|
StartingStorageMiragtion,
|
||||||
|
@ -152,28 +222,42 @@ pub enum Event {
|
||||||
|
|
||||||
/// A new server has been loaded
|
/// A new server has been loaded
|
||||||
NewServer {
|
NewServer {
|
||||||
onion: Identity,
|
/// identity of server
|
||||||
|
server: ServerIdentity,
|
||||||
|
/// sharable / importable server bundle
|
||||||
server_bundle: String,
|
server_bundle: String,
|
||||||
|
/// user supplied description
|
||||||
description: String,
|
description: String,
|
||||||
|
/// storage mode the server is using
|
||||||
storage_type: ServerStorageType,
|
storage_type: ServerStorageType,
|
||||||
|
/// does/should the server auto start on cwtch start
|
||||||
autostart: bool,
|
autostart: bool,
|
||||||
|
/// is the server running
|
||||||
running: bool,
|
running: bool,
|
||||||
},
|
},
|
||||||
/// 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 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
|
/// Notice a server was deleted (in response to an API call) and is no longer usable
|
||||||
ServerDeleted {
|
ServerDeleted {
|
||||||
identity: Identity,
|
/// identity of server
|
||||||
|
server: ServerIdentity,
|
||||||
|
/// was deletion a success
|
||||||
success: bool,
|
success: bool,
|
||||||
|
/// optional error string in case of failure to delete
|
||||||
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 of server
|
||||||
|
server: ServerIdentity,
|
||||||
|
/// count of total messages on the server
|
||||||
total_messages: i32,
|
total_messages: i32,
|
||||||
|
/// count of total current connections to the server
|
||||||
connections: i32,
|
connections: i32,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -181,151 +265,277 @@ pub enum Event {
|
||||||
|
|
||||||
/// A new message was received
|
/// A new message was received
|
||||||
NewMessageFromPeer {
|
NewMessageFromPeer {
|
||||||
conversation_id: i32,
|
/// identity field
|
||||||
handle: String,
|
profile: ProfileIdentity,
|
||||||
|
/// conversation id
|
||||||
|
conversation_id: ConversationID,
|
||||||
|
/// contact id
|
||||||
|
contact: ContactIdentity,
|
||||||
|
/// name of contact
|
||||||
nick: String,
|
nick: String,
|
||||||
|
/// time message was received
|
||||||
timestamp_received: DateTime<FixedOffset>,
|
timestamp_received: DateTime<FixedOffset>,
|
||||||
|
/// the message
|
||||||
message: String,
|
message: String,
|
||||||
|
/// notification instructions (based on settings)
|
||||||
notification: MessageNotification,
|
notification: MessageNotification,
|
||||||
|
/// path to picture for the contact
|
||||||
picture: String,
|
picture: String,
|
||||||
},
|
},
|
||||||
/// 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,
|
/// identity field
|
||||||
remote_peer: Identity,
|
profile: ProfileIdentity,
|
||||||
|
/// conversation id
|
||||||
|
conversation_id: ConversationID,
|
||||||
|
/// contact id
|
||||||
|
contact: ContactIdentity,
|
||||||
|
/// name of group
|
||||||
nick: String,
|
nick: String,
|
||||||
|
/// connection status to group server
|
||||||
status: ConnectionState,
|
status: ConnectionState,
|
||||||
|
/// number of unread messages in group
|
||||||
unread: i32,
|
unread: i32,
|
||||||
|
/// path to picture for group
|
||||||
picture: String,
|
picture: String,
|
||||||
|
/// path to default picture for group
|
||||||
default_picture: String,
|
default_picture: String,
|
||||||
|
/// total number of messages in group
|
||||||
num_messages: i32,
|
num_messages: i32,
|
||||||
|
/// has the user accepted the group
|
||||||
accepted: bool,
|
accepted: bool,
|
||||||
|
/// ACL for the group
|
||||||
access_control_list: ACL,
|
access_control_list: ACL,
|
||||||
|
/// is the group blocked
|
||||||
blocked: bool,
|
blocked: bool,
|
||||||
|
/// is the group syncing
|
||||||
loading: bool,
|
loading: bool,
|
||||||
|
/// time of last message from the group
|
||||||
last_msg_time: DateTime<FixedOffset>,
|
last_msg_time: DateTime<FixedOffset>,
|
||||||
|
|
||||||
},
|
},
|
||||||
/// A peer has changed state
|
/// A peer has changed state
|
||||||
PeerStateChange {
|
PeerStateChange {
|
||||||
remote_peer: Identity,
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// contact id
|
||||||
|
contact: ContactIdentity,
|
||||||
|
/// connection status to contact
|
||||||
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,
|
/// profile the check was performed on
|
||||||
|
profile: ProfileIdentity, // it's technically a profile self check
|
||||||
|
/// error if there was one (can be empty)
|
||||||
error: String,
|
error: String,
|
||||||
|
/// status of profile self connection check
|
||||||
status: NetworkCheckStatus,
|
status: NetworkCheckStatus,
|
||||||
},
|
},
|
||||||
/// Information from the ACN about a peer
|
/// Information from the ACN about a peer
|
||||||
ACNInfo {
|
ACNInfo {
|
||||||
handle: Identity,
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// contact id
|
||||||
|
contact: ContactIdentity,
|
||||||
|
/// key of info
|
||||||
key: String,
|
key: String,
|
||||||
|
/// data of info
|
||||||
data: String,
|
data: String,
|
||||||
},
|
},
|
||||||
/// a profile attribute has been updated with a new value
|
/// a profile attribute has been updated with a new value
|
||||||
UpdatedProfileAttribute {
|
UpdatedProfileAttribute {
|
||||||
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// attribute key
|
||||||
key: String,
|
key: String,
|
||||||
|
/// attribute new value
|
||||||
value: String,
|
value: String,
|
||||||
},
|
},
|
||||||
/// emited to confirm ack of a message succeeded
|
/// emited to confirm ack of a message succeeded
|
||||||
IndexedAcknowledgement {
|
IndexedAcknowledgement {
|
||||||
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// conversation id
|
||||||
conversation_id: i32,
|
conversation_id: i32,
|
||||||
|
/// index of message acked
|
||||||
index: i32,
|
index: i32,
|
||||||
},
|
},
|
||||||
/// emited to signal failure to ack a message
|
/// emited to signal failure to ack a message
|
||||||
IndexedFailure {
|
IndexedFailure {
|
||||||
conversation_id: i32,
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// conversation id
|
||||||
|
conversation_id: ConversationID,
|
||||||
|
/// index of failure of message to ack
|
||||||
index: i32,
|
index: i32,
|
||||||
handle: Identity,
|
/// contact id
|
||||||
|
contact: ContactIdentity,
|
||||||
|
/// error string
|
||||||
error: String
|
error: String
|
||||||
},
|
},
|
||||||
/// a peer has acked a message
|
/// a peer has acked a message
|
||||||
PeerAcknowledgement {
|
PeerAcknowledgement {
|
||||||
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// message id this is an ack to
|
||||||
event_id: String,
|
event_id: String,
|
||||||
remote_peer: Identity,
|
/// contact id
|
||||||
|
contact: ContactIdentity,
|
||||||
|
/// conversation id
|
||||||
conversation_id: i32,
|
conversation_id: i32,
|
||||||
},
|
},
|
||||||
/// New message received on a group
|
/// New message received on a group
|
||||||
NewMessageFromGroup {
|
NewMessageFromGroup {
|
||||||
conversation_id: i32,
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// conversation id
|
||||||
|
conversation_id: ConversationID,
|
||||||
|
/// time of message
|
||||||
timestamp_sent: DateTime<FixedOffset>,
|
timestamp_sent: DateTime<FixedOffset>,
|
||||||
remote_peer: Identity,
|
/// contact id
|
||||||
|
contact: ContactIdentity,
|
||||||
|
/// message index
|
||||||
index: i32,
|
index: i32,
|
||||||
|
/// the message
|
||||||
message: String,
|
message: String,
|
||||||
|
/// hash of the message
|
||||||
content_hash: String,
|
content_hash: String,
|
||||||
|
/// path to picture for sender
|
||||||
picture: String,
|
picture: String,
|
||||||
|
/// name of sender
|
||||||
nick: String,
|
nick: String,
|
||||||
|
/// notification policy (based on settings)
|
||||||
notification: MessageNotification,
|
notification: MessageNotification,
|
||||||
},
|
},
|
||||||
/// notice a group has been created
|
/// notice a group has been created
|
||||||
GroupCreated {
|
GroupCreated {
|
||||||
conversation_id: i32,
|
/// identity field
|
||||||
group_id: String,
|
profile: ProfileIdentity,
|
||||||
|
/// conversation id
|
||||||
|
conversation_id: ConversationID,
|
||||||
|
/// group id
|
||||||
|
group_id: GroupID,
|
||||||
|
/// server the group is on
|
||||||
group_server: String,
|
group_server: String,
|
||||||
|
/// name of group
|
||||||
group_name: String,
|
group_name: String,
|
||||||
|
/// path to picture for group
|
||||||
picture: String,
|
picture: String,
|
||||||
|
/// Access Control List for group
|
||||||
access_control_list: ACL,
|
access_control_list: ACL,
|
||||||
},
|
},
|
||||||
/// notice a new group exists
|
/// notice a new group exists
|
||||||
NewGroup {
|
NewGroup {
|
||||||
conversation_id: i32,
|
/// identity field
|
||||||
group_id: String,
|
profile: ProfileIdentity,
|
||||||
|
/// conversation id
|
||||||
|
conversation_id: ConversationID,
|
||||||
|
/// group id
|
||||||
|
group_id: GroupID,
|
||||||
|
/// server the group is on
|
||||||
group_server: String,
|
group_server: String,
|
||||||
|
/// invite string
|
||||||
group_invite: String,
|
group_invite: String,
|
||||||
|
/// group name
|
||||||
group_name: String,
|
group_name: String,
|
||||||
|
/// path to group picture
|
||||||
picture: String,
|
picture: String,
|
||||||
|
/// Access Control List for group
|
||||||
access_control_list: ACL,
|
access_control_list: ACL,
|
||||||
},
|
},
|
||||||
/// a server connection state has changed
|
/// a server connection state has changed
|
||||||
ServerStateChange {
|
ServerStateChange {
|
||||||
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// server the group is on
|
||||||
group_server: String,
|
group_server: String,
|
||||||
|
/// 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 {
|
||||||
remote_peer: Identity,
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// conversation id
|
||||||
|
contact: ContactIdentity,
|
||||||
|
/// scope of the val
|
||||||
scope: String,
|
scope: String,
|
||||||
|
/// path of the val (zone.key)
|
||||||
path: String,
|
path: String,
|
||||||
|
/// does the queried for value exist
|
||||||
exists: bool,
|
exists: bool,
|
||||||
|
/// value
|
||||||
data: String,
|
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
|
/// result of a call to share a file, the filekey and manifest to operate on it
|
||||||
ShareManifest {
|
ShareManifest {
|
||||||
filekey: String,
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// filekey
|
||||||
|
filekey: FileKey,
|
||||||
|
/// serialized manifest of the share
|
||||||
serializedManifest: String,
|
serializedManifest: String,
|
||||||
},
|
},
|
||||||
/// Information on a peer fileshare has been received
|
/// Information on a peer fileshare has been received
|
||||||
ManifestSizeReceived {
|
ManifestSizeReceived {
|
||||||
filekey: String,
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// filekey
|
||||||
|
filekey: FileKey,
|
||||||
|
/// size of manifest received for a share
|
||||||
manifest_size: i32,
|
manifest_size: i32,
|
||||||
handle: String,
|
/// contact id
|
||||||
|
contact: 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,
|
/// identity field
|
||||||
filekey: String,
|
profile: ProfileIdentity,
|
||||||
|
/// contact id
|
||||||
|
contact: ContactIdentity,
|
||||||
|
/// filekey
|
||||||
|
filekey: FileKey,
|
||||||
},
|
},
|
||||||
/// A peer message about a shared file has been received
|
/// A peer message about a shared file has been received
|
||||||
ManifestReceived {
|
ManifestReceived {
|
||||||
handle: Identity,
|
/// identity field
|
||||||
filekey: String,
|
profile: ProfileIdentity,
|
||||||
|
/// contact id
|
||||||
|
contact: ContactIdentity,
|
||||||
|
/// filekey
|
||||||
|
filekey: FileKey,
|
||||||
|
/// serialized manifest
|
||||||
serialized_manifest: String,
|
serialized_manifest: String,
|
||||||
},
|
},
|
||||||
/// a received manfiest has been saved
|
/// a received manfiest has been saved
|
||||||
ManifestSaved {
|
ManifestSaved {
|
||||||
handle: Identity,
|
/// identity field
|
||||||
filekey: String,
|
profile: ProfileIdentity,
|
||||||
|
/// contact id
|
||||||
|
contact: ContactIdentity,
|
||||||
|
/// filekey
|
||||||
|
filekey: FileKey,
|
||||||
|
/// serialized manifest
|
||||||
serialized_manifest: String,
|
serialized_manifest: String,
|
||||||
|
/// temporary storage path for share download
|
||||||
temp_file: String,
|
temp_file: String,
|
||||||
|
/// contact suggested share file name
|
||||||
name_suggestion: String,
|
name_suggestion: String,
|
||||||
},
|
},
|
||||||
/// periodically emited status updates about an active download of a shared file
|
/// periodically emited status updates about an active download of a shared file
|
||||||
FileDownloadProgressUpdate {
|
FileDownloadProgressUpdate {
|
||||||
filekey: String,
|
/// identity field
|
||||||
|
profile: ProfileIdentity,
|
||||||
|
/// filekey
|
||||||
|
filekey: FileKey,
|
||||||
|
/// progress of download of share in chunks
|
||||||
progress: i32,
|
progress: i32,
|
||||||
|
/// size of share in chunks
|
||||||
filesize_in_chunks: i32,
|
filesize_in_chunks: i32,
|
||||||
|
/// contact suggested name for file
|
||||||
name_suggestion: String,
|
name_suggestion: String,
|
||||||
},
|
},
|
||||||
// FileDownloaded, ??
|
// FileDownloaded, ??
|
||||||
|
@ -333,7 +543,9 @@ pub enum Event {
|
||||||
/// Indicates an event was sent from libCwtch that we don't handle/didn't anticipate
|
/// Indicates an event was sent from libCwtch that we don't handle/didn't anticipate
|
||||||
/// still passing it on giving the user a chance to react, but should be reported so we can handle it properly
|
/// still passing it on giving the user a chance to react, but should be reported so we can handle it properly
|
||||||
ErrUnhandled {
|
ErrUnhandled {
|
||||||
|
/// name of unhandled event
|
||||||
name: String,
|
name: String,
|
||||||
|
/// map of key:val attributes of unhandled event
|
||||||
data: HashMap<String, String>,
|
data: HashMap<String, String>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -343,7 +555,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(),
|
profile: 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(),
|
||||||
|
@ -354,8 +566,9 @@ impl From<&CwtchEvent> for Event {
|
||||||
server_json: cwtch_event.data["ServerList"].clone(),
|
server_json: cwtch_event.data["ServerList"].clone(),
|
||||||
},
|
},
|
||||||
"NewMessageFromPeer" => Event::NewMessageFromPeer {
|
"NewMessageFromPeer" => Event::NewMessageFromPeer {
|
||||||
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
handle: cwtch_event.data["RemotePeer"].clone(),
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2).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: cwtch_event.data["Data"].clone(),
|
||||||
|
@ -367,8 +580,9 @@ impl From<&CwtchEvent> for Event {
|
||||||
error: cwtch_event.data["Error"].clone(),
|
error: cwtch_event.data["Error"].clone(),
|
||||||
},
|
},
|
||||||
"ContactCreated" => Event::ContactCreated {
|
"ContactCreated" => Event::ContactCreated {
|
||||||
conversation_id: cwtch_event.data["ConversationID"].clone().parse().unwrap_or(-2),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
remote_peer: cwtch_event.data["RemotePeer"].clone(),
|
conversation_id: cwtch_event.data["ConversationID"].clone().parse().unwrap_or(-2).into(),
|
||||||
|
contact: 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,49 +596,55 @@ 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(),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
|
contact: 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 {
|
||||||
settings: serde_json::from_str(cwtch_event.data["Data"].as_str()).unwrap_or(HashMap::new()),
|
settings: serde_json::from_str(cwtch_event.data["Data"].as_str()).unwrap_or(HashMap::new()),
|
||||||
},
|
},
|
||||||
"PeerDeleted" => Event::PeerDeleted { identity: cwtch_event.data["Identity"].clone() },
|
"PeerDeleted" => Event::PeerDeleted { profile: cwtch_event.data["Identity"].clone().into() },
|
||||||
|
|
||||||
"ACNStatus" => Event::ACNStatus {
|
"ACNStatus" => Event::ACNStatus {
|
||||||
progress: cwtch_event.data["Progress"].parse().unwrap_or(0),
|
progress: cwtch_event.data["Progress"].parse().unwrap_or(0),
|
||||||
status: cwtch_event.data["Status"].clone(),
|
status: cwtch_event.data["Status"].clone(),
|
||||||
},
|
},
|
||||||
"ACNVersion" => Event::ACNVersion { verstion: cwtch_event.data["Data"].clone()},
|
"ACNVersion" => Event::ACNVersion { version: cwtch_event.data["Data"].clone()},
|
||||||
"NetworkError" => Event::NetworkStatus {
|
"NetworkError" => Event::NetworkStatus {
|
||||||
address: cwtch_event.data["Onion"].clone(),
|
profile: 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(),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
|
contact: 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(),
|
||||||
},
|
},
|
||||||
"UpdatedProfileAttribute" => Event::UpdatedProfileAttribute {
|
"UpdatedProfileAttribute" => Event::UpdatedProfileAttribute {
|
||||||
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
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 {
|
"IndexedAcknowledgement" => Event::IndexedAcknowledgement {
|
||||||
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
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),
|
||||||
},
|
},
|
||||||
"IndexedAcknowledgement" => Event::IndexedFailure {
|
"IndexedAcknowledgement" => Event::IndexedFailure {
|
||||||
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-1),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-1).into(),
|
||||||
index: cwtch_event.data["Index"].parse().unwrap_or(-1),
|
index: cwtch_event.data["Index"].parse().unwrap_or(-1),
|
||||||
handle: cwtch_event.data["Handle"].clone(),
|
contact: cwtch_event.data["Handle"].clone().into(),
|
||||||
error: cwtch_event.data["Error"].clone(),
|
error: cwtch_event.data["Error"].clone(),
|
||||||
},
|
},
|
||||||
"ShareManifest" => Event::ShareManifest {
|
"ShareManifest" => Event::ShareManifest {
|
||||||
filekey: cwtch_event.data["FileKey"].clone(),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
||||||
serializedManifest: cwtch_event.data["SerializedManifest"].clone(),
|
serializedManifest: cwtch_event.data["SerializedManifest"].clone(),
|
||||||
},
|
},
|
||||||
"NewServer" => Event::NewServer {
|
"NewServer" => Event::NewServer {
|
||||||
onion: cwtch_event.data["Onion"].clone(),
|
server: 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 +652,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(),
|
server: 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(),
|
server: 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,64 +664,73 @@ impl From<&CwtchEvent> for Event {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ServerStatsUpdate" => Event::ServerStatsUpdate {
|
"ServerStatsUpdate" => Event::ServerStatsUpdate {
|
||||||
identity: cwtch_event.data["Identity"].clone(),
|
server: 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(),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
||||||
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(),
|
contact: cwtch_event.data["Handle"].clone().into(),
|
||||||
},
|
},
|
||||||
"ManifestError" => Event::ManifestError {
|
"ManifestError" => Event::ManifestError {
|
||||||
handle: cwtch_event.data["Handle"].clone(),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
filekey: cwtch_event.data["FileKey"].clone(),
|
contact: cwtch_event.data["Handle"].clone().into(),
|
||||||
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
||||||
},
|
},
|
||||||
"ManifestReceived" => Event::ManifestReceived {
|
"ManifestReceived" => Event::ManifestReceived {
|
||||||
handle: cwtch_event.data["Handle"].clone(),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
filekey: cwtch_event.data["FileKey"].clone(),
|
contact: cwtch_event.data["Handle"].clone().into(),
|
||||||
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
||||||
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(),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
filekey: cwtch_event.data["FileKey"].clone(),
|
contact: cwtch_event.data["Handle"].clone().into(),
|
||||||
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
||||||
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(),
|
||||||
name_suggestion: cwtch_event.data["NameSuggestion"].clone(),
|
name_suggestion: cwtch_event.data["NameSuggestion"].clone(),
|
||||||
},
|
},
|
||||||
"FileDownloadProgressUpdate" => Event::FileDownloadProgressUpdate {
|
"FileDownloadProgressUpdate" => Event::FileDownloadProgressUpdate {
|
||||||
filekey: cwtch_event.data["FileKey"].clone(),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
||||||
progress: cwtch_event.data["Progress"].parse().unwrap_or(0),
|
progress: cwtch_event.data["Progress"].parse().unwrap_or(0),
|
||||||
filesize_in_chunks: cwtch_event.data["FileSizeInChunks"].parse().unwrap_or(0),
|
filesize_in_chunks: cwtch_event.data["FileSizeInChunks"].parse().unwrap_or(0),
|
||||||
name_suggestion: cwtch_event.data["NameSuggestion"].clone(),
|
name_suggestion: cwtch_event.data["NameSuggestion"].clone(),
|
||||||
},
|
},
|
||||||
"PeerAcknowledgement" => Event::PeerAcknowledgement {
|
"PeerAcknowledgement" => Event::PeerAcknowledgement {
|
||||||
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
event_id: cwtch_event.data["EventId"].clone(),
|
event_id: cwtch_event.data["EventId"].clone(),
|
||||||
remote_peer: cwtch_event.data["RemotePeer"].clone(),
|
contact: 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 {
|
||||||
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
timestamp_sent: DateTime::parse_from_rfc3339(cwtch_event.data["TimestampSent"].as_str()).unwrap_or( DateTime::from(Utc::now())),
|
timestamp_sent: DateTime::parse_from_rfc3339(cwtch_event.data["TimestampSent"].as_str()).unwrap_or( DateTime::from(Utc::now())),
|
||||||
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).into(),
|
||||||
remote_peer: cwtch_event.data["RemotePeer"].clone(),
|
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: cwtch_event.data["Data"].clone(),
|
||||||
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(),
|
||||||
},
|
},
|
||||||
"GroupCreated" => Event::GroupCreated {
|
"GroupCreated" => Event::GroupCreated {
|
||||||
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
group_id: cwtch_event.data["GroupID"].clone(),
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2).into(),
|
||||||
|
group_id: cwtch_event.data["GroupID"].clone().into(),
|
||||||
group_server: cwtch_event.data["GroupServer"].clone(),
|
group_server: cwtch_event.data["GroupServer"].clone(),
|
||||||
group_name: cwtch_event.data["GroupName"].clone(),
|
group_name: cwtch_event.data["GroupName"].clone(),
|
||||||
picture: cwtch_event.data["picture"].clone(),
|
picture: cwtch_event.data["picture"].clone(),
|
||||||
access_control_list: serde_json::from_str(cwtch_event.data["accessControlList"].as_str()).unwrap_or(ACL::new()),
|
access_control_list: serde_json::from_str(cwtch_event.data["accessControlList"].as_str()).unwrap_or(ACL::new()),
|
||||||
},
|
},
|
||||||
"NewGroup" => Event::NewGroup {
|
"NewGroup" => Event::NewGroup {
|
||||||
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
group_id: cwtch_event.data["GroupID"].clone(),
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2).into(),
|
||||||
|
group_id: cwtch_event.data["GroupID"].clone().into(),
|
||||||
group_server: cwtch_event.data["GroupServer"].clone(),
|
group_server: cwtch_event.data["GroupServer"].clone(),
|
||||||
group_invite: cwtch_event.data["GroupInvite"].clone(),
|
group_invite: cwtch_event.data["GroupInvite"].clone(),
|
||||||
group_name: cwtch_event.data["GroupName"].clone(),
|
group_name: cwtch_event.data["GroupName"].clone(),
|
||||||
|
@ -509,11 +738,13 @@ impl From<&CwtchEvent> for Event {
|
||||||
access_control_list: serde_json::from_str(cwtch_event.data["accessControlList"].as_str()).unwrap_or(ACL::new()),
|
access_control_list: serde_json::from_str(cwtch_event.data["accessControlList"].as_str()).unwrap_or(ACL::new()),
|
||||||
},
|
},
|
||||||
"ServerStateChange" => Event::ServerStateChange {
|
"ServerStateChange" => Event::ServerStateChange {
|
||||||
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
group_server: cwtch_event.data["GroupServer"].clone(),
|
group_server: cwtch_event.data["GroupServer"].clone(),
|
||||||
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(),
|
profile: cwtch_event.data["ProfileOnion"].clone().into(),
|
||||||
|
contact: 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),
|
||||||
|
|
|
@ -10,6 +10,7 @@ mod cwtchlib_go;
|
||||||
|
|
||||||
/// Basic structs using data from Cwtch and for deserializing JSON and serializing to JSON to communicate with Cwtch
|
/// Basic structs using data from Cwtch and for deserializing JSON and serializing to JSON to communicate with Cwtch
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
|
/// Additional structs for advnaced event handling and converstion helpers
|
||||||
pub mod event;
|
pub mod event;
|
||||||
|
|
||||||
/// Error type for Cwtch lib related errors, intended for use with Result
|
/// Error type for Cwtch lib related errors, intended for use with Result
|
||||||
|
|
Loading…
Reference in New Issue