profile convo list by id, handle2id fn

This commit is contained in:
Dan Ballard 2022-05-01 18:34:40 -07:00
parent d223325646
commit 895a9e78d1
3 changed files with 15 additions and 7 deletions

2
Cargo.lock generated
View File

@ -123,7 +123,7 @@ checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]]
name = "libcwtch"
version = "0.3.0"
version = "0.3.2"
dependencies = [
"hex-literal",
"libc",

View File

@ -1,13 +1,13 @@
[package]
name = "libcwtch"
version = "0.3.1"
version = "0.3.2"
authors = ["Dan Ballard <dan@mindstab.net>"]
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"

View File

@ -148,7 +148,7 @@ pub struct Profile {
/// all profile attributes
pub attr: HashMap<String, String>,
/// map of conversation [ onion => conversation ]
pub conversations: HashMap<String, Conversation>,
pub conversations: HashMap<i32, Conversation>,
/// map of servers [ onion => server ]
pub servers: HashMap<String, Server>,
}
@ -289,8 +289,8 @@ impl Profile {
})
}
fn process_conversations(conversations_json: &str) -> Result<HashMap<String, Conversation>, String> {
let mut conversations: HashMap<String, Conversation> = HashMap::new();
fn process_conversations(conversations_json: &str) -> Result<HashMap<i32, Conversation>, String> {
let mut conversations: HashMap<i32, Conversation> = 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<i32> {
match self.conversations.values().filter(|c| c.handle == handle).next() {
Some(conversation) => Some(conversation.identifier),
None => None
}
}
}