starting to type fields
This commit is contained in:
parent
577d8999cf
commit
bd5d3f7e5f
103
src/event.rs
103
src/event.rs
|
@ -7,13 +7,19 @@ use chrono::offset::LocalResult;
|
||||||
|
|
||||||
use crate::structs::{ACL, ConnectionState, CwtchEvent};
|
use crate::structs::{ACL, ConnectionState, CwtchEvent};
|
||||||
|
|
||||||
|
pub type Identity = String;
|
||||||
|
pub type Handle = String;
|
||||||
|
pub type ConversationID = i32;
|
||||||
|
pub type FileKey = String;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
/// Enum for type of notification a UI/client should emit for a new message
|
||||||
pub enum MessageNotification {
|
pub enum MessageNotification {
|
||||||
// NotificationNone enum for message["notification"] that means no notification
|
/// means no notification
|
||||||
None,
|
None,
|
||||||
// NotificationEvent enum for message["notification"] that means emit a notification that a message event happened only
|
/// means emit a notification that a message event happened only
|
||||||
SimpleEvent,
|
SimpleEvent,
|
||||||
// NotificationConversation enum for message["notification"] that means emit a notification event with Conversation handle included
|
/// means emit a notification event with Conversation handle included
|
||||||
ContactInfo,
|
ContactInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +35,11 @@ impl From<String> for MessageNotification {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
/// Enum for results from NetworkCheck plugin on profiles
|
||||||
pub enum NetworkCheckStatus {
|
pub enum NetworkCheckStatus {
|
||||||
|
/// There was an error, this profile cannot connect to itself
|
||||||
Error,
|
Error,
|
||||||
|
/// Success connecting to self, profile is "online"
|
||||||
Success
|
Success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +54,13 @@ impl From<String> for NetworkCheckStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
/// Enum denoting server storage mode
|
||||||
pub enum ServerStorageType {
|
pub enum ServerStorageType {
|
||||||
|
/// indicates some app supplied default password is being used on this server for storage encryption
|
||||||
DefaultPassword,
|
DefaultPassword,
|
||||||
|
/// indicates a user supplied password is being used on this server for storage encryption
|
||||||
Password,
|
Password,
|
||||||
|
/// indicates no password and no encryption is being used on server storage
|
||||||
NoPassword
|
NoPassword
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +76,11 @@ impl From<String> for ServerStorageType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
/// Enum used by servers to declare their intent to be running or stopped
|
||||||
pub enum ServerIntent {
|
pub enum ServerIntent {
|
||||||
|
/// a server intends to be running
|
||||||
Running,
|
Running,
|
||||||
|
/// a server intends to be stopped
|
||||||
Stopped
|
Stopped
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,13 +95,16 @@ impl From<String> for ServerIntent {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
/// Enum for events from Cwtch appbus
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
|
|
||||||
// App events
|
// App events
|
||||||
|
|
||||||
|
/// Emited by libcwtch once Cwtch.Start() has been completed successfully, you can start making API calls, lcg is initialized
|
||||||
CwtchStarted,
|
CwtchStarted,
|
||||||
|
/// A new peer has been loaded, details of peer. Identity should be stored so further API calls can be made
|
||||||
NewPeer {
|
NewPeer {
|
||||||
identity: String,
|
identity: Identity,
|
||||||
tag: String,
|
tag: String,
|
||||||
created: bool,
|
created: bool,
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -95,60 +114,72 @@ pub enum Event {
|
||||||
contacts_json: String,
|
contacts_json: String,
|
||||||
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
|
||||||
AppError {
|
AppError {
|
||||||
error: String
|
error: String
|
||||||
},
|
},
|
||||||
|
/// Global settings being emited from lcg, usually in response to them being sent to be saved by client
|
||||||
UpdateGlobalSettings {
|
UpdateGlobalSettings {
|
||||||
settings: HashMap<String, String>,
|
settings: HashMap<String, String>,
|
||||||
},
|
},
|
||||||
ErrUnhandled {
|
/// A profile has an error, usually emited in response to an API call
|
||||||
name: String,
|
|
||||||
data: HashMap<String, String>,
|
|
||||||
},
|
|
||||||
PeerError {
|
PeerError {
|
||||||
error: String
|
error: String
|
||||||
},
|
},
|
||||||
|
/// A profile was successfully deleted, it is no longer usable
|
||||||
PeerDeleted {
|
PeerDeleted {
|
||||||
identity: String
|
identity: String
|
||||||
},
|
},
|
||||||
|
/// Cwtch is shutting down, stop making API calls
|
||||||
Shutdown,
|
Shutdown,
|
||||||
|
/// indicates status of the ACN (tor), usually during boot.
|
||||||
ACNStatus {
|
ACNStatus {
|
||||||
|
/// the percent of ACN boot (-1 to 100)
|
||||||
progress: i8,
|
progress: i8,
|
||||||
|
/// an associated status message from the ACN
|
||||||
status: String
|
status: String
|
||||||
},
|
},
|
||||||
|
/// Version of the ACN (currently tor)
|
||||||
ACNVersion {
|
ACNVersion {
|
||||||
verstion: String,
|
verstion: String,
|
||||||
},
|
},
|
||||||
|
/// Notice from libCwtch that before completing load of a profile a storage migration is occuring so Start will take longer
|
||||||
StartingStorageMiragtion,
|
StartingStorageMiragtion,
|
||||||
|
/// Notice from libCwtch that the storage migration is complete, profile being loaded resuming
|
||||||
DoneStorageMigration,
|
DoneStorageMigration,
|
||||||
|
|
||||||
// app server events
|
// app server events
|
||||||
|
|
||||||
|
/// A new server has been loaded
|
||||||
NewServer {
|
NewServer {
|
||||||
onion: String,
|
onion: Identity,
|
||||||
server_bundle: String,
|
server_bundle: String,
|
||||||
description: String,
|
description: String,
|
||||||
storage_type: ServerStorageType,
|
storage_type: ServerStorageType,
|
||||||
autostart: bool,
|
autostart: bool,
|
||||||
running: bool,
|
running: bool,
|
||||||
},
|
},
|
||||||
|
/// Response to request for server intent change, indicating the server is indending the new state
|
||||||
ServerIntentUpdate {
|
ServerIntentUpdate {
|
||||||
identity: String,
|
identity: Identity,
|
||||||
intent: ServerIntent
|
intent: ServerIntent
|
||||||
},
|
},
|
||||||
|
/// Notice a server was deleted (in response to an API call) and is no longer usable
|
||||||
ServerDeleted {
|
ServerDeleted {
|
||||||
identity: String,
|
identity: Identity,
|
||||||
success: bool,
|
success: bool,
|
||||||
error: Option<String>,
|
error: Option<String>,
|
||||||
},
|
},
|
||||||
|
/// Stats info for a server, periodically emited
|
||||||
ServerStatsUpdate {
|
ServerStatsUpdate {
|
||||||
identity: String,
|
identity: Identity,
|
||||||
total_messages: i32,
|
total_messages: i32,
|
||||||
connections: i32,
|
connections: i32,
|
||||||
},
|
},
|
||||||
|
|
||||||
// profile events
|
// profile events
|
||||||
|
|
||||||
|
/// A new message was received
|
||||||
NewMessageFromPeer {
|
NewMessageFromPeer {
|
||||||
conversation_id: i32,
|
conversation_id: i32,
|
||||||
handle: String,
|
handle: String,
|
||||||
|
@ -158,9 +189,10 @@ pub enum Event {
|
||||||
notification: MessageNotification,
|
notification: MessageNotification,
|
||||||
picture: String,
|
picture: String,
|
||||||
},
|
},
|
||||||
|
/// A new contact has been created (imported, added, or contacted by)
|
||||||
ContactCreated {
|
ContactCreated {
|
||||||
conversation_id: i32,
|
conversation_id: i32,
|
||||||
remote_peer: String,
|
remote_peer: Identity,
|
||||||
nick: String,
|
nick: String,
|
||||||
status: ConnectionState,
|
status: ConnectionState,
|
||||||
unread: i32,
|
unread: i32,
|
||||||
|
@ -174,43 +206,51 @@ pub enum Event {
|
||||||
last_msg_time: DateTime<FixedOffset>,
|
last_msg_time: DateTime<FixedOffset>,
|
||||||
|
|
||||||
},
|
},
|
||||||
|
/// A peer has changed state
|
||||||
PeerStateChange {
|
PeerStateChange {
|
||||||
remote_peer: String,
|
remote_peer: Identity,
|
||||||
connection_state: ConnectionState,
|
connection_state: ConnectionState,
|
||||||
},
|
},
|
||||||
|
/// Notice from the network check plugin, a profile self check test by attempting to connecting to itself
|
||||||
NetworkStatus {
|
NetworkStatus {
|
||||||
address: String,
|
address: Identity,
|
||||||
error: String,
|
error: String,
|
||||||
status: NetworkCheckStatus,
|
status: NetworkCheckStatus,
|
||||||
},
|
},
|
||||||
|
/// Information from the ACN about a peer
|
||||||
ACNInfo {
|
ACNInfo {
|
||||||
handle: String,
|
handle: Identity,
|
||||||
key: String,
|
key: String,
|
||||||
data: String,
|
data: String,
|
||||||
},
|
},
|
||||||
|
/// a profile attribute has been updated with a new value
|
||||||
UpdatedProfileAttribute {
|
UpdatedProfileAttribute {
|
||||||
key: String,
|
key: String,
|
||||||
value: String,
|
value: String,
|
||||||
},
|
},
|
||||||
|
/// emited to confirm ack of a message succeeded
|
||||||
IndexedAcknowledgement {
|
IndexedAcknowledgement {
|
||||||
conversation_id: i32,
|
conversation_id: i32,
|
||||||
index: i32,
|
index: i32,
|
||||||
},
|
},
|
||||||
|
/// emited to signal failure to ack a message
|
||||||
IndexedFailure {
|
IndexedFailure {
|
||||||
conversation_id: i32,
|
conversation_id: i32,
|
||||||
index: i32,
|
index: i32,
|
||||||
handle: String,
|
handle: Identity,
|
||||||
error: String
|
error: String
|
||||||
},
|
},
|
||||||
|
/// a peer has acked a message
|
||||||
PeerAcknowledgement {
|
PeerAcknowledgement {
|
||||||
event_id: String,
|
event_id: String,
|
||||||
remote_peer: String,
|
remote_peer: Identity,
|
||||||
conversation_id: i32,
|
conversation_id: i32,
|
||||||
},
|
},
|
||||||
|
/// New message received on a group
|
||||||
NewMessageFromGroup {
|
NewMessageFromGroup {
|
||||||
conversation_id: i32,
|
conversation_id: i32,
|
||||||
timestamp_sent: DateTime<FixedOffset>,
|
timestamp_sent: DateTime<FixedOffset>,
|
||||||
remote_peer: String,
|
remote_peer: Identity,
|
||||||
index: i32,
|
index: i32,
|
||||||
message: String,
|
message: String,
|
||||||
content_hash: String,
|
content_hash: String,
|
||||||
|
@ -218,6 +258,7 @@ pub enum Event {
|
||||||
nick: String,
|
nick: String,
|
||||||
notification: MessageNotification,
|
notification: MessageNotification,
|
||||||
},
|
},
|
||||||
|
/// notice a group has been created
|
||||||
GroupCreated {
|
GroupCreated {
|
||||||
conversation_id: i32,
|
conversation_id: i32,
|
||||||
group_id: String,
|
group_id: String,
|
||||||
|
@ -226,6 +267,7 @@ pub enum Event {
|
||||||
picture: String,
|
picture: String,
|
||||||
access_control_list: ACL,
|
access_control_list: ACL,
|
||||||
},
|
},
|
||||||
|
/// notice a new group exists
|
||||||
NewGroup {
|
NewGroup {
|
||||||
conversation_id: i32,
|
conversation_id: i32,
|
||||||
group_id: String,
|
group_id: String,
|
||||||
|
@ -235,43 +277,51 @@ pub enum Event {
|
||||||
picture: String,
|
picture: String,
|
||||||
access_control_list: ACL,
|
access_control_list: ACL,
|
||||||
},
|
},
|
||||||
|
/// a server connection state has changed
|
||||||
ServerStateChange {
|
ServerStateChange {
|
||||||
group_server: String,
|
group_server: String,
|
||||||
state: ConnectionState
|
state: ConnectionState
|
||||||
},
|
},
|
||||||
|
/// A getval call to a peer has returned a response
|
||||||
NewRetValMessageFromPeer {
|
NewRetValMessageFromPeer {
|
||||||
remote_peer: String,
|
remote_peer: Identity,
|
||||||
scope: String,
|
scope: String,
|
||||||
path: String,
|
path: String,
|
||||||
exists: bool,
|
exists: bool,
|
||||||
data: String,
|
data: String,
|
||||||
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 {
|
ShareManifest {
|
||||||
filekey: String,
|
filekey: String,
|
||||||
serializedManifest: String,
|
serializedManifest: String,
|
||||||
},
|
},
|
||||||
|
/// Information on a peer fileshare has been received
|
||||||
ManifestSizeReceived {
|
ManifestSizeReceived {
|
||||||
filekey: String,
|
filekey: String,
|
||||||
manifest_size: i32,
|
manifest_size: i32,
|
||||||
handle: String,
|
handle: String,
|
||||||
},
|
},
|
||||||
|
/// An error has occured while trying to parse a peer sharefile
|
||||||
ManifestError {
|
ManifestError {
|
||||||
handle: String,
|
handle: Identity,
|
||||||
filekey: String,
|
filekey: String,
|
||||||
},
|
},
|
||||||
|
/// A peer message about a shared file has been received
|
||||||
ManifestReceived {
|
ManifestReceived {
|
||||||
handle: String,
|
handle: Identity,
|
||||||
filekey: String,
|
filekey: String,
|
||||||
serialized_manifest: String,
|
serialized_manifest: String,
|
||||||
},
|
},
|
||||||
|
/// a received manfiest has been saved
|
||||||
ManifestSaved {
|
ManifestSaved {
|
||||||
handle: String,
|
handle: Identity,
|
||||||
filekey: String,
|
filekey: String,
|
||||||
serialized_manifest: String,
|
serialized_manifest: String,
|
||||||
temp_file: String,
|
temp_file: String,
|
||||||
name_suggestion: String,
|
name_suggestion: String,
|
||||||
},
|
},
|
||||||
|
/// periodically emited status updates about an active download of a shared file
|
||||||
FileDownloadProgressUpdate {
|
FileDownloadProgressUpdate {
|
||||||
filekey: String,
|
filekey: String,
|
||||||
progress: i32,
|
progress: i32,
|
||||||
|
@ -279,6 +329,13 @@ pub enum Event {
|
||||||
name_suggestion: String,
|
name_suggestion: String,
|
||||||
},
|
},
|
||||||
// FileDownloaded, ??
|
// FileDownloaded, ??
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
ErrUnhandled {
|
||||||
|
name: String,
|
||||||
|
data: HashMap<String, String>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&CwtchEvent> for Event {
|
impl From<&CwtchEvent> for Event {
|
||||||
|
|
Loading…
Reference in New Issue