2022-07-07 06:52:30 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2022-07-07 06:52:30 +00:00
|
|
|
use chrono::{DateTime, FixedOffset};
|
|
|
|
use chrono::prelude::*;
|
2022-07-14 23:33:41 +00:00
|
|
|
use std::convert::From;
|
2022-07-07 06:52:30 +00:00
|
|
|
|
2023-05-07 18:21:14 +00:00
|
|
|
use crate::structs::{ACL, ConnectionState, CwtchEvent, MessageWrapper, Profile, Settings};
|
2022-07-07 06:52:30 +00:00
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq)]
|
2022-07-14 23:33:41 +00:00
|
|
|
/// Profile ID used to refer to profiles in Cwtch
|
|
|
|
pub struct ProfileIdentity(String);
|
|
|
|
|
|
|
|
impl From<String> for ProfileIdentity {
|
|
|
|
fn from(x: String) -> Self {
|
|
|
|
ProfileIdentity(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-15 19:23:13 +00:00
|
|
|
impl From<ProfileIdentity> for String {
|
|
|
|
fn from(x: ProfileIdentity) -> Self {
|
|
|
|
x.into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&str> for ProfileIdentity {
|
|
|
|
fn from(x: &str) -> Self {
|
|
|
|
ProfileIdentity(x.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
impl From<&ProfileIdentity> for String {
|
|
|
|
fn from(x: &ProfileIdentity) -> Self {
|
|
|
|
x.0.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ProfileIdentity {
|
|
|
|
/// Get &str of ProfileIdentity String
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
|
|
self.0.as_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq)]
|
2022-07-14 23:33:41 +00:00
|
|
|
/// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
impl ContactIdentity {
|
|
|
|
/// Get &str of ContactIdentity String
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
|
|
self.0.as_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Hash, Eq, PartialEq)]
|
2022-07-14 23:33:41 +00:00
|
|
|
/// Conversation ID user to refer to a conversation with a Contact or Group in Cwtch
|
2022-07-21 08:04:21 +00:00
|
|
|
pub struct ConversationID(pub i32) ;
|
2022-07-14 23:33:41 +00:00
|
|
|
|
|
|
|
impl From<i32> for ConversationID {
|
|
|
|
fn from(x: i32) -> Self {
|
|
|
|
ConversationID(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-15 19:23:13 +00:00
|
|
|
impl From<ConversationID> for i32 {
|
|
|
|
fn from(x: ConversationID) -> Self {
|
|
|
|
x.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq)]
|
2022-07-14 23:33:41 +00:00
|
|
|
/// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq)]
|
2022-07-14 23:33:41 +00:00
|
|
|
/// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-15 19:23:13 +00:00
|
|
|
impl From<&str> for ServerIdentity {
|
|
|
|
fn from(x: &str) -> Self {
|
|
|
|
ServerIdentity(x.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-15 19:43:27 +00:00
|
|
|
impl From<ServerIdentity> for String {
|
2022-07-15 19:23:13 +00:00
|
|
|
fn from(x: ServerIdentity) -> Self {
|
2022-07-15 19:43:27 +00:00
|
|
|
x.into()
|
2022-07-15 19:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq)]
|
2022-07-14 23:33:41 +00:00
|
|
|
/// 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)
|
|
|
|
}
|
|
|
|
}
|
2022-07-07 21:30:20 +00:00
|
|
|
|
2022-07-15 19:43:27 +00:00
|
|
|
impl From<FileKey> for String {
|
|
|
|
fn from(x: FileKey) -> Self {
|
|
|
|
x.into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-07 18:21:14 +00:00
|
|
|
impl From<&FileKey> for String {
|
|
|
|
fn from(x: &FileKey) -> Self {
|
|
|
|
x.into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FileKey {
|
|
|
|
/// Get &str of FileKey String
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
|
|
self.0.as_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Enum for type of notification a UI/client should emit for a new message
|
2022-07-07 06:52:30 +00:00
|
|
|
pub enum MessageNotification {
|
2022-07-07 21:30:20 +00:00
|
|
|
/// means no notification
|
2022-07-07 06:52:30 +00:00
|
|
|
None,
|
2022-07-07 21:30:20 +00:00
|
|
|
/// means emit a notification that a message event happened only
|
2022-07-07 06:52:30 +00:00
|
|
|
SimpleEvent,
|
2022-07-07 21:30:20 +00:00
|
|
|
/// means emit a notification event with Conversation handle included
|
2022-07-07 06:52:30 +00:00
|
|
|
ContactInfo,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for MessageNotification {
|
|
|
|
fn from(str: String) -> MessageNotification {
|
|
|
|
match str.as_str() {
|
|
|
|
"None" => MessageNotification::None,
|
|
|
|
"SimpleEvent" => MessageNotification::SimpleEvent,
|
|
|
|
"ContactInfo" => MessageNotification::ContactInfo,
|
|
|
|
_ => MessageNotification::None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Enum for results from NetworkCheck plugin on profiles
|
2022-07-07 06:52:30 +00:00
|
|
|
pub enum NetworkCheckStatus {
|
2022-07-07 21:30:20 +00:00
|
|
|
/// There was an error, this profile cannot connect to itself
|
2022-07-07 06:52:30 +00:00
|
|
|
Error,
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Success connecting to self, profile is "online"
|
2022-07-07 06:52:30 +00:00
|
|
|
Success
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for NetworkCheckStatus {
|
|
|
|
fn from(str: String) -> NetworkCheckStatus {
|
|
|
|
match str.as_str() {
|
|
|
|
"Error" => NetworkCheckStatus::Error,
|
|
|
|
"Success" => NetworkCheckStatus::Success,
|
|
|
|
_ => NetworkCheckStatus::Error,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Enum denoting server storage mode
|
2022-07-07 06:52:30 +00:00
|
|
|
pub enum ServerStorageType {
|
2022-07-07 21:30:20 +00:00
|
|
|
/// indicates some app supplied default password is being used on this server for storage encryption
|
2022-07-07 06:52:30 +00:00
|
|
|
DefaultPassword,
|
2022-07-07 21:30:20 +00:00
|
|
|
/// indicates a user supplied password is being used on this server for storage encryption
|
2022-07-07 06:52:30 +00:00
|
|
|
Password,
|
2022-07-07 21:30:20 +00:00
|
|
|
/// indicates no password and no encryption is being used on server storage
|
2022-07-07 06:52:30 +00:00
|
|
|
NoPassword
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for ServerStorageType {
|
|
|
|
fn from(str: String) -> ServerStorageType {
|
|
|
|
match str.as_str() {
|
|
|
|
"storage-default-password" => ServerStorageType::DefaultPassword,
|
|
|
|
"storage-password" => ServerStorageType::Password,
|
|
|
|
"storage-no-password" => ServerStorageType::NoPassword,
|
|
|
|
_ => ServerStorageType::DefaultPassword,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Enum used by servers to declare their intent to be running or stopped
|
2022-07-07 06:52:30 +00:00
|
|
|
pub enum ServerIntent {
|
2022-07-07 21:30:20 +00:00
|
|
|
/// a server intends to be running
|
2022-07-07 06:52:30 +00:00
|
|
|
Running,
|
2022-07-07 21:30:20 +00:00
|
|
|
/// a server intends to be stopped
|
2022-07-07 06:52:30 +00:00
|
|
|
Stopped
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for ServerIntent {
|
|
|
|
fn from(str: String) -> ServerIntent {
|
|
|
|
match str.as_str() {
|
|
|
|
"running" => ServerIntent::Running,
|
|
|
|
"stopped" => ServerIntent::Stopped,
|
|
|
|
_ => ServerIntent::Stopped,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 08:04:21 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Enum for events from Cwtch appbus
|
2022-07-07 06:52:30 +00:00
|
|
|
pub enum Event {
|
|
|
|
|
|
|
|
// App events
|
|
|
|
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Emited by libcwtch once Cwtch.Start() has been completed successfully, you can start making API calls, lcg is initialized
|
2022-07-07 06:52:30 +00:00
|
|
|
CwtchStarted,
|
2022-07-07 21:30:20 +00:00
|
|
|
/// A new peer has been loaded, details of peer. Identity should be stored so further API calls can be made
|
2022-07-07 06:52:30 +00:00
|
|
|
NewPeer {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// optional client specified tag
|
2022-07-07 06:52:30 +00:00
|
|
|
tag: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// is this a newly created profile event, or a load
|
2022-07-07 06:52:30 +00:00
|
|
|
created: bool,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// user supplied name of the profile
|
2022-07-07 06:52:30 +00:00
|
|
|
name: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// default picture path
|
2022-07-07 06:52:30 +00:00
|
|
|
default_picture: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// user supplied picture path
|
2022-07-07 06:52:30 +00:00
|
|
|
picture: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// is the profile online
|
2022-07-07 06:52:30 +00:00
|
|
|
online: String,
|
2022-07-15 21:39:32 +00:00
|
|
|
/// The deserialized profile with contacts and server info
|
|
|
|
profile_data: Result<Profile, String>,
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Cwtch had an error at the app level (not profile level), usually in response to an API call
|
2022-07-07 06:52:30 +00:00
|
|
|
AppError {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// details of the app error that occured
|
2023-09-23 06:11:03 +00:00
|
|
|
error: String,
|
|
|
|
/// possible data about the error
|
|
|
|
data: String
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Global settings being emited from lcg, usually in response to them being sent to be saved by client
|
2022-07-07 06:52:30 +00:00
|
|
|
UpdateGlobalSettings {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// map of setting names to values (https://git.openprivacy.ca/cwtch.im/libcwtch-go/src/branch/trunk/utils/settings.go)
|
2022-07-21 08:04:21 +00:00
|
|
|
settings: Settings,
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// A profile has an error, usually emited in response to an API call
|
2022-07-07 06:52:30 +00:00
|
|
|
PeerError {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// details of the peer error that occured
|
2022-07-07 06:52:30 +00:00
|
|
|
error: String
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// A profile was successfully deleted, it is no longer usable
|
2022-07-07 06:52:30 +00:00
|
|
|
PeerDeleted {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity of deleted peer
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Cwtch is shutting down, stop making API calls
|
2022-07-07 06:52:30 +00:00
|
|
|
Shutdown,
|
2022-07-07 21:30:20 +00:00
|
|
|
/// indicates status of the ACN (tor), usually during boot.
|
2022-07-07 06:52:30 +00:00
|
|
|
ACNStatus {
|
2022-07-07 21:30:20 +00:00
|
|
|
/// the percent of ACN boot (-1 to 100)
|
2022-07-07 06:52:30 +00:00
|
|
|
progress: i8,
|
2022-07-07 21:30:20 +00:00
|
|
|
/// an associated status message from the ACN
|
2022-07-15 21:39:32 +00:00
|
|
|
status: String,
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Version of the ACN (currently tor)
|
2022-07-07 06:52:30 +00:00
|
|
|
ACNVersion {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// version string from ACN app
|
|
|
|
version: String,
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Notice from libCwtch that before completing load of a profile a storage migration is occuring so Start will take longer
|
2022-07-07 06:52:30 +00:00
|
|
|
StartingStorageMiragtion,
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Notice from libCwtch that the storage migration is complete, profile being loaded resuming
|
2022-07-07 06:52:30 +00:00
|
|
|
DoneStorageMigration,
|
|
|
|
|
|
|
|
// app server events
|
|
|
|
|
2022-07-07 21:30:20 +00:00
|
|
|
/// A new server has been loaded
|
2022-07-07 06:52:30 +00:00
|
|
|
NewServer {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity of server
|
|
|
|
server: ServerIdentity,
|
|
|
|
/// sharable / importable server bundle
|
2022-07-07 06:52:30 +00:00
|
|
|
server_bundle: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// user supplied description
|
2022-07-07 06:52:30 +00:00
|
|
|
description: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// storage mode the server is using
|
2022-07-07 06:52:30 +00:00
|
|
|
storage_type: ServerStorageType,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// does/should the server auto start on cwtch start
|
2022-07-07 06:52:30 +00:00
|
|
|
autostart: bool,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// is the server running
|
2022-07-07 06:52:30 +00:00
|
|
|
running: bool,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Response to request for server intent change, indicating the server is indending the new state
|
2022-07-07 06:52:30 +00:00
|
|
|
ServerIntentUpdate {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity of server
|
|
|
|
server: ServerIdentity,
|
|
|
|
/// intent of the server to be running or not
|
2022-07-15 21:39:32 +00:00
|
|
|
intent: ServerIntent,
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Notice a server was deleted (in response to an API call) and is no longer usable
|
2022-07-07 06:52:30 +00:00
|
|
|
ServerDeleted {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity of server
|
|
|
|
server: ServerIdentity,
|
|
|
|
/// was deletion a success
|
2022-07-07 06:52:30 +00:00
|
|
|
success: bool,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// optional error string in case of failure to delete
|
2022-07-07 06:52:30 +00:00
|
|
|
error: Option<String>,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Stats info for a server, periodically emited
|
2022-07-07 06:52:30 +00:00
|
|
|
ServerStatsUpdate {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity of server
|
|
|
|
server: ServerIdentity,
|
|
|
|
/// count of total messages on the server
|
2022-07-07 06:52:30 +00:00
|
|
|
total_messages: i32,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// count of total current connections to the server
|
2022-07-07 06:52:30 +00:00
|
|
|
connections: i32,
|
|
|
|
},
|
|
|
|
|
|
|
|
// profile events
|
|
|
|
|
2022-07-07 21:30:20 +00:00
|
|
|
/// A new message was received
|
2022-07-07 06:52:30 +00:00
|
|
|
NewMessageFromPeer {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// conversation id
|
|
|
|
conversation_id: ConversationID,
|
|
|
|
/// contact id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// name of contact
|
2022-07-07 06:52:30 +00:00
|
|
|
nick: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// time message was received
|
2022-07-07 06:52:30 +00:00
|
|
|
timestamp_received: DateTime<FixedOffset>,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// the message
|
2023-05-07 18:21:14 +00:00
|
|
|
message: MessageWrapper,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// notification instructions (based on settings)
|
2022-07-07 06:52:30 +00:00
|
|
|
notification: MessageNotification,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// path to picture for the contact
|
2022-07-07 06:52:30 +00:00
|
|
|
picture: String,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// A new contact has been created (imported, added, or contacted by)
|
2022-07-07 06:52:30 +00:00
|
|
|
ContactCreated {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// conversation id
|
|
|
|
conversation_id: ConversationID,
|
|
|
|
/// contact id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// name of group
|
2022-07-07 06:52:30 +00:00
|
|
|
nick: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// connection status to group server
|
2022-07-07 06:52:30 +00:00
|
|
|
status: ConnectionState,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// number of unread messages in group
|
2022-07-07 06:52:30 +00:00
|
|
|
unread: i32,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// path to picture for group
|
2022-07-07 06:52:30 +00:00
|
|
|
picture: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// path to default picture for group
|
2022-07-07 06:52:30 +00:00
|
|
|
default_picture: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// total number of messages in group
|
2022-07-07 06:52:30 +00:00
|
|
|
num_messages: i32,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// has the user accepted the group
|
2022-07-07 06:52:30 +00:00
|
|
|
accepted: bool,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// ACL for the group
|
2022-07-07 06:52:30 +00:00
|
|
|
access_control_list: ACL,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// is the group blocked
|
2022-07-07 06:52:30 +00:00
|
|
|
blocked: bool,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// is the group syncing
|
2022-07-07 06:52:30 +00:00
|
|
|
loading: bool,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// time of last message from the group
|
2022-07-07 06:52:30 +00:00
|
|
|
last_msg_time: DateTime<FixedOffset>,
|
|
|
|
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// A peer has changed state
|
2022-07-07 06:52:30 +00:00
|
|
|
PeerStateChange {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// contact id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// connection status to contact
|
2022-07-07 06:52:30 +00:00
|
|
|
connection_state: ConnectionState,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Notice from the network check plugin, a profile self check test by attempting to connecting to itself
|
2022-07-07 06:52:30 +00:00
|
|
|
NetworkStatus {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// profile the check was performed on
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-15 21:39:32 +00:00
|
|
|
// it's technically a profile self check
|
2022-07-14 23:33:41 +00:00
|
|
|
/// error if there was one (can be empty)
|
2022-07-07 06:52:30 +00:00
|
|
|
error: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// status of profile self connection check
|
2022-07-07 06:52:30 +00:00
|
|
|
status: NetworkCheckStatus,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Information from the ACN about a peer
|
2022-07-07 06:52:30 +00:00
|
|
|
ACNInfo {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// contact id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// key of info
|
2022-07-07 06:52:30 +00:00
|
|
|
key: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// data of info
|
2022-07-07 06:52:30 +00:00
|
|
|
data: String,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// a profile attribute has been updated with a new value
|
2022-07-07 06:52:30 +00:00
|
|
|
UpdatedProfileAttribute {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// attribute key
|
2022-07-07 06:52:30 +00:00
|
|
|
key: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// attribute new value
|
2022-07-07 06:52:30 +00:00
|
|
|
value: String,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// emited to confirm ack of a message succeeded
|
2022-07-07 06:52:30 +00:00
|
|
|
IndexedAcknowledgement {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// conversation id
|
2022-07-07 06:52:30 +00:00
|
|
|
conversation_id: i32,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// index of message acked
|
2022-07-07 06:52:30 +00:00
|
|
|
index: i32,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// emited to signal failure to ack a message
|
2022-07-07 06:52:30 +00:00
|
|
|
IndexedFailure {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// conversation id
|
|
|
|
conversation_id: ConversationID,
|
|
|
|
/// index of failure of message to ack
|
2022-07-07 06:52:30 +00:00
|
|
|
index: i32,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// contact id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// error string
|
2022-07-15 21:39:32 +00:00
|
|
|
error: String,
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// a peer has acked a message
|
2022-07-07 06:52:30 +00:00
|
|
|
PeerAcknowledgement {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// message id this is an ack to
|
2022-07-07 06:52:30 +00:00
|
|
|
event_id: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// contact id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// conversation id
|
2022-07-07 06:52:30 +00:00
|
|
|
conversation_id: i32,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// New message received on a group
|
2022-07-07 06:52:30 +00:00
|
|
|
NewMessageFromGroup {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// conversation id
|
|
|
|
conversation_id: ConversationID,
|
|
|
|
/// time of message
|
2022-07-07 06:52:30 +00:00
|
|
|
timestamp_sent: DateTime<FixedOffset>,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// contact id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// message index
|
2022-07-07 06:52:30 +00:00
|
|
|
index: i32,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// the message
|
2023-05-07 18:21:14 +00:00
|
|
|
message: MessageWrapper,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// hash of the message
|
2022-07-07 06:52:30 +00:00
|
|
|
content_hash: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// path to picture for sender
|
2022-07-07 06:52:30 +00:00
|
|
|
picture: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// name of sender
|
2022-07-07 06:52:30 +00:00
|
|
|
nick: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// notification policy (based on settings)
|
2022-07-07 06:52:30 +00:00
|
|
|
notification: MessageNotification,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// notice a group has been created
|
2022-07-07 06:52:30 +00:00
|
|
|
GroupCreated {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// conversation id
|
|
|
|
conversation_id: ConversationID,
|
|
|
|
/// group id
|
|
|
|
group_id: GroupID,
|
|
|
|
/// server the group is on
|
2022-07-07 06:52:30 +00:00
|
|
|
group_server: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// name of group
|
2022-07-07 06:52:30 +00:00
|
|
|
group_name: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// path to picture for group
|
2022-07-07 06:52:30 +00:00
|
|
|
picture: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// Access Control List for group
|
2022-07-07 06:52:30 +00:00
|
|
|
access_control_list: ACL,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// notice a new group exists
|
2022-07-07 06:52:30 +00:00
|
|
|
NewGroup {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// conversation id
|
|
|
|
conversation_id: ConversationID,
|
|
|
|
/// group id
|
|
|
|
group_id: GroupID,
|
|
|
|
/// server the group is on
|
2022-07-07 06:52:30 +00:00
|
|
|
group_server: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// invite string
|
2022-07-07 06:52:30 +00:00
|
|
|
group_invite: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// group name
|
2022-07-07 06:52:30 +00:00
|
|
|
group_name: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// path to group picture
|
2022-07-07 06:52:30 +00:00
|
|
|
picture: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// Access Control List for group
|
2022-07-07 06:52:30 +00:00
|
|
|
access_control_list: ACL,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// a server connection state has changed
|
2022-07-07 06:52:30 +00:00
|
|
|
ServerStateChange {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// server the group is on
|
2022-07-07 06:52:30 +00:00
|
|
|
group_server: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// state of connection to server
|
2022-07-15 21:39:32 +00:00
|
|
|
state: ConnectionState,
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// A getval call to a peer has returned a response
|
2022-07-07 06:52:30 +00:00
|
|
|
NewRetValMessageFromPeer {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// conversation id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// scope of the val
|
2022-07-07 06:52:30 +00:00
|
|
|
scope: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// path of the val (zone.key)
|
2022-07-07 06:52:30 +00:00
|
|
|
path: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// does the queried for value exist
|
2022-07-07 06:52:30 +00:00
|
|
|
exists: bool,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// value
|
2022-07-07 06:52:30 +00:00
|
|
|
data: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// optional filepath if there was a downloaded component
|
2022-07-15 21:39:32 +00:00
|
|
|
file_path: Option<String>,
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// result of a call to share a file, the filekey and manifest to operate on it
|
2022-07-07 06:52:30 +00:00
|
|
|
ShareManifest {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// filekey
|
|
|
|
filekey: FileKey,
|
|
|
|
/// serialized manifest of the share
|
2022-07-15 21:39:32 +00:00
|
|
|
serialized_manifest: String,
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// Information on a peer fileshare has been received
|
2022-07-07 06:52:30 +00:00
|
|
|
ManifestSizeReceived {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// filekey
|
|
|
|
filekey: FileKey,
|
|
|
|
/// size of manifest received for a share
|
2022-07-07 06:52:30 +00:00
|
|
|
manifest_size: i32,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// contact id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// An error has occured while trying to parse a peer sharefile
|
2022-07-07 06:52:30 +00:00
|
|
|
ManifestError {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// contact id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// filekey
|
|
|
|
filekey: FileKey,
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// A peer message about a shared file has been received
|
2022-07-07 06:52:30 +00:00
|
|
|
ManifestReceived {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// contact id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// filekey
|
|
|
|
filekey: FileKey,
|
|
|
|
/// serialized manifest
|
2022-07-07 06:52:30 +00:00
|
|
|
serialized_manifest: String,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// a received manfiest has been saved
|
2022-07-07 06:52:30 +00:00
|
|
|
ManifestSaved {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// contact id
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: ContactIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// filekey
|
|
|
|
filekey: FileKey,
|
|
|
|
/// serialized manifest
|
2022-07-07 06:52:30 +00:00
|
|
|
serialized_manifest: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// temporary storage path for share download
|
2022-07-07 06:52:30 +00:00
|
|
|
temp_file: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// contact suggested share file name
|
2022-07-07 06:52:30 +00:00
|
|
|
name_suggestion: String,
|
|
|
|
},
|
2022-07-07 21:30:20 +00:00
|
|
|
/// periodically emited status updates about an active download of a shared file
|
2022-07-07 06:52:30 +00:00
|
|
|
FileDownloadProgressUpdate {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// identity field
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: ProfileIdentity,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// filekey
|
|
|
|
filekey: FileKey,
|
|
|
|
/// progress of download of share in chunks
|
2022-07-07 06:52:30 +00:00
|
|
|
progress: i32,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// size of share in chunks
|
2022-07-07 06:52:30 +00:00
|
|
|
filesize_in_chunks: i32,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// contact suggested name for file
|
2022-07-07 06:52:30 +00:00
|
|
|
name_suggestion: String,
|
|
|
|
},
|
|
|
|
// FileDownloaded, ??
|
2022-07-07 21:30:20 +00:00
|
|
|
|
|
|
|
/// 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 {
|
2022-07-14 23:33:41 +00:00
|
|
|
/// name of unhandled event
|
2022-07-07 21:30:20 +00:00
|
|
|
name: String,
|
2022-07-14 23:33:41 +00:00
|
|
|
/// map of key:val attributes of unhandled event
|
2022-07-07 21:30:20 +00:00
|
|
|
data: HashMap<String, String>,
|
|
|
|
},
|
2022-07-07 06:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&CwtchEvent> for Event {
|
|
|
|
fn from(cwtch_event: &CwtchEvent) -> Self {
|
2022-07-21 08:04:21 +00:00
|
|
|
println!("EVENT: {:?}", cwtch_event);
|
2022-07-07 06:52:30 +00:00
|
|
|
match cwtch_event.event_type.as_str() {
|
|
|
|
"CwtchStarted" => Event::CwtchStarted,
|
|
|
|
"NewPeer" => Event::NewPeer {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["Identity"].clone().into(),
|
2022-07-15 21:39:32 +00:00
|
|
|
tag: cwtch_event.data["tag"].clone(),
|
|
|
|
created: cwtch_event.data["Created"] == "true",
|
|
|
|
name: cwtch_event.data["name"].clone(),
|
|
|
|
default_picture: cwtch_event.data["defaultPicture"].clone(),
|
|
|
|
picture: cwtch_event.data["picture"].clone(),
|
|
|
|
online: cwtch_event.data["Online"].clone(),
|
|
|
|
profile_data: Profile::new(
|
2022-07-21 08:04:21 +00:00
|
|
|
cwtch_event.data["Identity"].clone().into(),
|
2022-07-15 21:39:32 +00:00
|
|
|
&cwtch_event.data["name"],
|
|
|
|
&cwtch_event.data["picture"],
|
|
|
|
&cwtch_event.data["ContactsJson"],
|
|
|
|
&cwtch_event.data["ServerList"],
|
|
|
|
)
|
|
|
|
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
|
|
|
"NewMessageFromPeer" => Event::NewMessageFromPeer {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-14 23:33:41 +00:00
|
|
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2).into(),
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: cwtch_event.data["RemotePeer"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
nick: cwtch_event.data["Nick"].clone(),
|
|
|
|
timestamp_received: DateTime::parse_from_rfc3339(cwtch_event.data["TimestampReceived"].as_str()).unwrap_or( DateTime::from(Utc::now())),
|
2023-05-07 18:21:14 +00:00
|
|
|
message: MessageWrapper::from_json(&cwtch_event.data["Data"]),
|
2022-07-07 06:52:30 +00:00
|
|
|
notification: MessageNotification::from(cwtch_event.data["notification"].clone()),
|
2022-07-21 08:04:21 +00:00
|
|
|
picture: cwtch_event.data["picture"].clone(),
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
|
|
|
"PeerError" => Event::PeerError { error: cwtch_event.data["Error"].clone() },
|
|
|
|
"AppError" => Event::AppError {
|
2023-09-23 06:11:03 +00:00
|
|
|
error: match cwtch_event.data.contains_key("Error") {
|
|
|
|
true => cwtch_event.data["Error"].clone(),
|
|
|
|
false => "".to_string()
|
|
|
|
},
|
|
|
|
data: match cwtch_event.data.contains_key("Data") {
|
|
|
|
true => cwtch_event.data["Data"].clone(),
|
|
|
|
false => "".to_string()
|
|
|
|
}
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
|
|
|
"ContactCreated" => Event::ContactCreated {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-14 23:33:41 +00:00
|
|
|
conversation_id: cwtch_event.data["ConversationID"].clone().parse().unwrap_or(-2).into(),
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: cwtch_event.data["RemotePeer"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
unread: cwtch_event.data["unread"].clone().parse().unwrap_or(0),
|
|
|
|
picture: cwtch_event.data["picture"].clone(),
|
|
|
|
default_picture: cwtch_event.data["defaultPicture"].clone(),
|
|
|
|
num_messages: cwtch_event.data["numMessages"].clone().parse().unwrap_or(0),
|
|
|
|
nick: cwtch_event.data["nick"].clone(),
|
|
|
|
accepted: cwtch_event.data["accepted"].clone().parse().unwrap_or(false),
|
|
|
|
status: ConnectionState::from(cwtch_event.data["status"].as_str()),
|
|
|
|
access_control_list: serde_json::from_str(cwtch_event.data["accessControlList"].as_str()).unwrap_or(ACL::new()),
|
|
|
|
blocked: cwtch_event.data["blocked"].clone().parse().unwrap_or(false),
|
|
|
|
loading: cwtch_event.data["loading"].clone().parse().unwrap_or(false),
|
|
|
|
last_msg_time: DateTime::parse_from_rfc3339(cwtch_event.data["lastMsgTime"].as_str()).unwrap_or(DateTime::from(Utc::now())),
|
|
|
|
},
|
|
|
|
"PeerStateChange" => Event::PeerStateChange {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
|
|
|
contact_id: cwtch_event.data["RemotePeer"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
connection_state: ConnectionState::from(cwtch_event.data["ConnectionState"].as_str()),
|
|
|
|
},
|
|
|
|
"UpdateGlobalSettings" => Event::UpdateGlobalSettings {
|
2022-07-21 08:04:21 +00:00
|
|
|
settings: serde_json::from_str(cwtch_event.data["Data"].as_str()).expect("could not parse settings from libCwtch-go"),
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
2022-07-21 08:04:21 +00:00
|
|
|
"PeerDeleted" => Event::PeerDeleted { profile_id: cwtch_event.data["Identity"].clone().into() },
|
2022-07-07 06:52:30 +00:00
|
|
|
|
|
|
|
"ACNStatus" => Event::ACNStatus {
|
|
|
|
progress: cwtch_event.data["Progress"].parse().unwrap_or(0),
|
|
|
|
status: cwtch_event.data["Status"].clone(),
|
|
|
|
},
|
2022-07-14 23:33:41 +00:00
|
|
|
"ACNVersion" => Event::ACNVersion { version: cwtch_event.data["Data"].clone()},
|
2022-07-07 06:52:30 +00:00
|
|
|
"NetworkError" => Event::NetworkStatus {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
error: cwtch_event.data["Error"].clone(),
|
|
|
|
status: NetworkCheckStatus::from(cwtch_event.data["Status"].clone())
|
|
|
|
},
|
|
|
|
"ACNInfo" => Event::ACNInfo {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
|
|
|
contact_id: cwtch_event.data["Handle"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
key: cwtch_event.data["Key"].clone(),
|
|
|
|
data: cwtch_event.data["Data"].clone(),
|
|
|
|
},
|
|
|
|
"UpdatedProfileAttribute" => Event::UpdatedProfileAttribute {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
key: cwtch_event.data["Key"].clone(),
|
|
|
|
value: cwtch_event.data["Data"].clone(),
|
|
|
|
},
|
2022-07-21 08:04:21 +00:00
|
|
|
"IndexedAcknowledgement" => Event::IndexedAcknowledgement {
|
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-14 23:33:41 +00:00
|
|
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-1).into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
index: cwtch_event.data["Index"].parse().unwrap_or(-1),
|
|
|
|
},
|
|
|
|
"ShareManifest" => Event::ShareManifest {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-14 23:33:41 +00:00
|
|
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
2022-07-15 21:39:32 +00:00
|
|
|
serialized_manifest: cwtch_event.data["SerializedManifest"].clone(),
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
|
|
|
"NewServer" => Event::NewServer {
|
2022-07-14 23:33:41 +00:00
|
|
|
server: cwtch_event.data["Onion"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
server_bundle: cwtch_event.data["ServerBundle"].clone(),
|
|
|
|
description: cwtch_event.data["Description"].clone(),
|
|
|
|
storage_type: ServerStorageType::from(cwtch_event.data["StorageType"].clone()),
|
|
|
|
autostart: cwtch_event.data["Autostart"].parse().unwrap_or(false),
|
|
|
|
running: cwtch_event.data["Running"].parse().unwrap_or(false),
|
|
|
|
},
|
|
|
|
"ServerIntentUpdate" => Event::ServerIntentUpdate {
|
2022-07-14 23:33:41 +00:00
|
|
|
server: cwtch_event.data["Identity"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
intent: ServerIntent::from(cwtch_event.data["Intent"].clone())
|
|
|
|
},
|
|
|
|
"ServerDeleted" => Event::ServerDeleted {
|
2022-07-14 23:33:41 +00:00
|
|
|
server: cwtch_event.data["Identity"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
success: cwtch_event.data["Status"].clone() == "success",
|
|
|
|
error: match cwtch_event.data.get("Error") {
|
|
|
|
Some(e) => Some(e.clone()),
|
|
|
|
None => None,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"ServerStatsUpdate" => Event::ServerStatsUpdate {
|
2022-07-14 23:33:41 +00:00
|
|
|
server: cwtch_event.data["Identity"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
total_messages: cwtch_event.data["TotalMessages"].parse().unwrap_or(0),
|
|
|
|
connections: cwtch_event.data["Connections"].parse().unwrap_or(0),
|
|
|
|
},
|
|
|
|
"ManifestSizeReceived" => Event::ManifestSizeReceived {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-14 23:33:41 +00:00
|
|
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
manifest_size: cwtch_event.data["ManifestSize"].parse().unwrap_or(0),
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: cwtch_event.data["Handle"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
|
|
|
"ManifestError" => Event::ManifestError {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
|
|
|
contact_id: cwtch_event.data["Handle"].clone().into(),
|
2022-07-14 23:33:41 +00:00
|
|
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
|
|
|
"ManifestReceived" => Event::ManifestReceived {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
|
|
|
contact_id: cwtch_event.data["Handle"].clone().into(),
|
2022-07-14 23:33:41 +00:00
|
|
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
serialized_manifest: cwtch_event.data["SerializedManifest"].clone(),
|
|
|
|
},
|
|
|
|
"ManifestSaved" => Event::ManifestSaved {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
|
|
|
contact_id: cwtch_event.data["Handle"].clone().into(),
|
2022-07-14 23:33:41 +00:00
|
|
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
serialized_manifest: cwtch_event.data["SerializedManifest"].clone(),
|
|
|
|
temp_file: cwtch_event.data["TempFile"].clone(),
|
|
|
|
name_suggestion: cwtch_event.data["NameSuggestion"].clone(),
|
|
|
|
},
|
|
|
|
"FileDownloadProgressUpdate" => Event::FileDownloadProgressUpdate {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-14 23:33:41 +00:00
|
|
|
filekey: cwtch_event.data["FileKey"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
progress: cwtch_event.data["Progress"].parse().unwrap_or(0),
|
|
|
|
filesize_in_chunks: cwtch_event.data["FileSizeInChunks"].parse().unwrap_or(0),
|
|
|
|
name_suggestion: cwtch_event.data["NameSuggestion"].clone(),
|
|
|
|
},
|
|
|
|
"PeerAcknowledgement" => Event::PeerAcknowledgement {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
|
|
|
event_id: cwtch_event.data["EventID"].clone(),
|
|
|
|
contact_id: cwtch_event.data["RemotePeer"].clone().into(),
|
|
|
|
conversation_id: cwtch_event.data.get("ConversationID").unwrap_or(&"0".to_string()).parse().unwrap_or(0)
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
|
|
|
"NewMessageFromGroup" => Event::NewMessageFromGroup {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
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),
|
|
|
|
content_hash: cwtch_event.data["ContentHash"].clone(),
|
2022-07-14 23:33:41 +00:00
|
|
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2).into(),
|
2022-07-21 08:04:21 +00:00
|
|
|
contact_id: cwtch_event.data["RemotePeer"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
nick: cwtch_event.data["Nick"].clone(),
|
2023-05-07 18:21:14 +00:00
|
|
|
message: MessageWrapper::from_json(&cwtch_event.data["Data"]),
|
2022-07-07 06:52:30 +00:00
|
|
|
notification: MessageNotification::from(cwtch_event.data["notification"].clone()),
|
2022-07-21 08:04:21 +00:00
|
|
|
picture: cwtch_event.data["picture"].clone(),
|
2022-07-07 06:52:30 +00:00
|
|
|
},
|
|
|
|
"GroupCreated" => Event::GroupCreated {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-14 23:33:41 +00:00
|
|
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2).into(),
|
|
|
|
group_id: cwtch_event.data["GroupID"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
group_server: cwtch_event.data["GroupServer"].clone(),
|
|
|
|
group_name: cwtch_event.data["GroupName"].clone(),
|
|
|
|
picture: cwtch_event.data["picture"].clone(),
|
|
|
|
access_control_list: serde_json::from_str(cwtch_event.data["accessControlList"].as_str()).unwrap_or(ACL::new()),
|
|
|
|
},
|
|
|
|
"NewGroup" => Event::NewGroup {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-14 23:33:41 +00:00
|
|
|
conversation_id: cwtch_event.data["ConversationID"].parse().unwrap_or(-2).into(),
|
|
|
|
group_id: cwtch_event.data["GroupID"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
group_server: cwtch_event.data["GroupServer"].clone(),
|
|
|
|
group_invite: cwtch_event.data["GroupInvite"].clone(),
|
|
|
|
group_name: cwtch_event.data["GroupName"].clone(),
|
|
|
|
picture: cwtch_event.data["picture"].clone(),
|
|
|
|
access_control_list: serde_json::from_str(cwtch_event.data["accessControlList"].as_str()).unwrap_or(ACL::new()),
|
|
|
|
},
|
|
|
|
"ServerStateChange" => Event::ServerStateChange {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
group_server: cwtch_event.data["GroupServer"].clone(),
|
|
|
|
state: ConnectionState::from(cwtch_event.data["ConnectionState"].as_str()),
|
|
|
|
},
|
|
|
|
"NewRetValMessageFromPeer" => Event::NewRetValMessageFromPeer {
|
2022-07-21 08:04:21 +00:00
|
|
|
profile_id: cwtch_event.data["ProfileOnion"].clone().into(),
|
|
|
|
contact_id: cwtch_event.data["RemotePeer"].clone().into(),
|
2022-07-07 06:52:30 +00:00
|
|
|
scope: cwtch_event.data["Scope"].clone(),
|
|
|
|
path: cwtch_event.data["Path"].clone(),
|
|
|
|
exists: cwtch_event.data["Exists"].parse().unwrap_or(false),
|
|
|
|
data: cwtch_event.data["Data"].clone(),
|
|
|
|
file_path: match cwtch_event.data.get("FilePath") {
|
|
|
|
Some(fp) => Some(fp.to_string()),
|
|
|
|
None => None,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
_ => Event::ErrUnhandled {
|
|
|
|
name: cwtch_event.event_type.to_string(),
|
|
|
|
data: cwtch_event.data.clone(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|