diff --git a/Cargo.lock b/Cargo.lock index 33a0330..69d1d9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,7 +123,7 @@ checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "libcwtch" -version = "0.3.0" +version = "0.3.2" dependencies = [ "hex-literal", "libc", diff --git a/Cargo.toml b/Cargo.toml index 9ac145e..fc9b081 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "libcwtch" -version = "0.3.1" +version = "0.3.2" authors = ["Dan Ballard "] edition = "2018" license = "MIT" description = "libcwtch is an interface to a Cwtch app that allows creating of profiles to communicate with contacts over the Cwtch protocol" repository = "https://git.openprivacy.ca/cwtch.im/libcwtch-rs" readme = "README.md" -documentation = "https://docs.rs/libcwtch/0.3.0/libcwtch/" +documentation = "https://docs.rs/libcwtch/0.3.2/libcwtch/" [build-dependencies] hex-literal = "0.3.4" diff --git a/src/structs.rs b/src/structs.rs index 6c8875a..91b41e6 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -148,7 +148,7 @@ pub struct Profile { /// all profile attributes pub attr: HashMap, /// map of conversation [ onion => conversation ] - pub conversations: HashMap, + pub conversations: HashMap, /// map of servers [ onion => server ] pub servers: HashMap, } @@ -289,8 +289,8 @@ impl Profile { }) } - fn process_conversations(conversations_json: &str) -> Result, String> { - let mut conversations: HashMap = HashMap::new(); + fn process_conversations(conversations_json: &str) -> Result, String> { + let mut conversations: HashMap = HashMap::new(); if conversations_json == "null" { return Ok(conversations); } @@ -299,7 +299,7 @@ impl Profile { Err(e) => return Err(format!("invalid json: {:?}", e)), }; for conversation in conversations_map { - conversations.insert(conversation.handle.clone(), conversation); + conversations.insert(conversation.identifier, conversation); } Ok(conversations) } @@ -318,4 +318,12 @@ impl Profile { } Ok(servers) } + + /// Find a conversation_id associated with a remote handle (used for some events with no conversation id like PeerStateChange) + pub fn find_conversation_id_by_handle(&self, handle: String) -> Option { + match self.conversations.values().filter(|c| c.handle == handle).next() { + Some(conversation) => Some(conversation.identifier), + None => None + } + } }