adding needed structs #10
|
@ -73,23 +73,25 @@ pub struct CwtchEvent {
|
|||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
/// Struct to serialize/deserialize contacts coming from libcwtch-go
|
||||
pub struct Contact {
|
||||
/// onion address / id of the contact
|
||||
pub onion: String,
|
||||
/// Struct to serialize/deserialize conversations coming from libcwtch-go
|
||||
pub struct Conversation {
|
||||
/// onion address / id of the conversation
|
||||
#[serde(alias = "onion")]
|
||||
pub handle: String,
|
||||
/// unique identifier of the contact/conversation to be used in API access
|
||||
|
||||
pub identifier: i32,
|
||||
/// display name of the contact, as determined in libcwtch-go from name specified by contact
|
||||
/// display name of the conversation, as determined in libcwtch-go from name specified by contact
|
||||
pub name: String,
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
// cwtch loads profile/contacts from storage and leaves status blank, it's filled in "soon" by events...
|
||||
// cwtch loads profile/conversation from storage and leaves status blank, it's filled in "soon" by events...
|
||||
/// contact connection status
|
||||
pub status: ConnectionState,
|
||||
/// has the contact been manually accpted
|
||||
/// has the conversation been manually accpted
|
||||
pub accepted: bool,
|
||||
/// has the contact been manually blocked
|
||||
/// has the conversation been manually blocked
|
||||
pub blocked: bool,
|
||||
/// is this contact a group? if so "onion" will be a group ID
|
||||
/// is this conversation a group? if so "onion" will be a group ID
|
||||
/// FIXME: deprecate
|
||||
pub is_group: bool,
|
||||
//attr: HashMap<String, String>,
|
||||
}
|
||||
|
@ -114,14 +116,14 @@ pub struct Profile {
|
|||
pub image_path: String,
|
||||
/// all profile attributes
|
||||
pub attr: HashMap<String, String>,
|
||||
/// map of contacts [ onion => contact ]
|
||||
pub contacts: HashMap<String, Contact>,
|
||||
/// map of conversation [ onion => conversation ]
|
||||
pub conversations: HashMap<String, Conversation>,
|
||||
/// map of servers [ onion => server ]
|
||||
pub servers: HashMap<String, Server>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
/// Struct to serialize/deserialize messages sent over Cwtch between profiles / contacts
|
||||
/// Struct to serialize/deserialize messages sent over Cwtch between profiles / conversation
|
||||
pub struct Message {
|
||||
/// overlay id that the message is targeting as defined in cwtch/model/overlay.go
|
||||
/// [ OverlayChat = 1, OverlayInviteContact = 100, OverlayInviteGroup = 101, OverlayFileSharing = 200 ]
|
||||
|
@ -146,13 +148,13 @@ pub struct Settings {
|
|||
pub ExperimentsEnabled: bool,
|
||||
/// map of experiment names and their enabled status
|
||||
pub Experiments: HashMap<String, bool>,
|
||||
/// Should the app block unknown contacts
|
||||
/// Should the app block unknown conversations
|
||||
pub BlockUnknownConnections: bool,
|
||||
// Notification policy of a UI app
|
||||
//pub NotificationPolicy: String, //Todo: NotificationPolicy struct
|
||||
// Notification content to show for a UI app
|
||||
//pub NotificationContent: String,
|
||||
/// Should the UI hide contact IDs
|
||||
/// Should the UI hide conversation IDs
|
||||
pub StreamerMode: bool,
|
||||
/// Unused?
|
||||
pub StateRootPane: i32,
|
||||
|
@ -184,13 +186,13 @@ pub struct Settings {
|
|||
|
||||
/// Enum of experiment types that can be managed in Settings
|
||||
dan marked this conversation as resolved
sarah
commented
spelling enabling spelling enabling
|
||||
pub enum Experiments {
|
||||
/// experiment enabeling in app management and running of Cwtch servers
|
||||
/// experiment enabling in app management and running of Cwtch servers
|
||||
ServersExperiment,
|
||||
/// experiment enabeling use of Cwtch groups
|
||||
/// experiment enabling use of Cwtch groups
|
||||
GroupExperiment,
|
||||
/// experiment enabeling filesharing
|
||||
/// experiment enabling filesharing
|
||||
FileSharingExperiment,
|
||||
/// experiment enabeling auto downloading of image files to Settings::DownloadPath
|
||||
/// experiment enabling auto downloading of image files to Settings::DownloadPath
|
||||
ImagePreviewsExperiment,
|
||||
}
|
||||
|
||||
|
@ -229,16 +231,16 @@ impl Settings {
|
|||
|
||||
impl Profile {
|
||||
/// Create a new profile populated from supplied data
|
||||
/// contacts_json as supplied by libcwtch-go, a map of contacts
|
||||
/// contacts_json as supplied by libcwtch-go, a map of conversations
|
||||
/// server_list as supplied by libcwtch-go, a map of servers
|
||||
pub fn new(
|
||||
identity: &str,
|
||||
name: &str,
|
||||
picture: &str,
|
||||
contacts_json: &str,
|
||||
conversations_json: &str,
|
||||
server_list: &str,
|
||||
) -> Result<Profile, String> {
|
||||
let contacts = match Profile::process_contacts(contacts_json) {
|
||||
let conversations = match Profile::process_conversations(conversations_json) {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
@ -251,25 +253,24 @@ impl Profile {
|
|||
nick: name.to_string(),
|
||||
image_path: picture.to_string(),
|
||||
attr: Default::default(),
|
||||
contacts: contacts,
|
||||
conversations,
|
||||
servers: servers,
|
||||
})
|
||||
}
|
||||
|
||||
fn process_contacts(constacts_json: &str) -> Result<HashMap<String, Contact>, String> {
|
||||
let mut contacts: HashMap<String, Contact> = HashMap::new();
|
||||
if constacts_json == "null" {
|
||||
return Ok(contacts);
|
||||
fn process_conversations(conversations_json: &str) -> Result<HashMap<String, Conversation>, String> {
|
||||
let mut conversations: HashMap<String, Conversation> = HashMap::new();
|
||||
if conversations_json == "null" {
|
||||
return Ok(conversations);
|
||||
}
|
||||
println!("contacts_json: '{}'", constacts_json);
|
||||
let contacts_map: Vec<Contact> = match serde_json::from_str(constacts_json) {
|
||||
let conversations_map: Vec<Conversation> = match serde_json::from_str(conversations_json) {
|
||||
Ok(cm) => cm,
|
||||
Err(e) => return Err(format!("invalid json: {:?}", e)),
|
||||
};
|
||||
for contact in contacts_map {
|
||||
contacts.insert(contact.onion.clone(), contact);
|
||||
for conversation in conversations_map {
|
||||
conversations.insert(conversation.handle.clone(), conversation);
|
||||
}
|
||||
Ok(contacts)
|
||||
Ok(conversations)
|
||||
}
|
||||
|
||||
fn process_servers(servers_json: &str) -> Result<HashMap<String, Server>, String> {
|
||||
|
|
Loading…
Reference in New Issue
u32?
can't do to auto generated api is i32, we can try and force conversion with.try_into().unwrap() but there's an additional problem in
https://git.openprivacy.ca/cwtch.im/libcwtch-go/src/branch/trunk/lib.go#L799
where we do infact use a negative convo id