starting to type fields

This commit is contained in:
Dan Ballard 2022-07-07 14:30:20 -07:00
parent 577d8999cf
commit bd5d3f7e5f
1 changed files with 80 additions and 23 deletions

View File

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