forked from cwtch.im/libcwtch-rs
profile convo list by id, handle2id fn
This commit is contained in:
parent
d223325646
commit
895a9e78d1
|
@ -123,7 +123,7 @@ checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libcwtch"
|
name = "libcwtch"
|
||||||
version = "0.3.0"
|
version = "0.3.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hex-literal",
|
"hex-literal",
|
||||||
"libc",
|
"libc",
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
[package]
|
[package]
|
||||||
name = "libcwtch"
|
name = "libcwtch"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
authors = ["Dan Ballard <dan@mindstab.net>"]
|
authors = ["Dan Ballard <dan@mindstab.net>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
description = "libcwtch is an interface to a Cwtch app that allows creating of profiles to communicate with contacts over the Cwtch protocol"
|
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"
|
repository = "https://git.openprivacy.ca/cwtch.im/libcwtch-rs"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
documentation = "https://docs.rs/libcwtch/0.3.0/libcwtch/"
|
documentation = "https://docs.rs/libcwtch/0.3.2/libcwtch/"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
hex-literal = "0.3.4"
|
hex-literal = "0.3.4"
|
||||||
|
|
|
@ -148,7 +148,7 @@ pub struct Profile {
|
||||||
/// all profile attributes
|
/// all profile attributes
|
||||||
pub attr: HashMap<String, String>,
|
pub attr: HashMap<String, String>,
|
||||||
/// map of conversation [ onion => conversation ]
|
/// map of conversation [ onion => conversation ]
|
||||||
pub conversations: HashMap<String, Conversation>,
|
pub conversations: HashMap<i32, Conversation>,
|
||||||
/// map of servers [ onion => server ]
|
/// map of servers [ onion => server ]
|
||||||
pub servers: HashMap<String, Server>,
|
pub servers: HashMap<String, Server>,
|
||||||
}
|
}
|
||||||
|
@ -289,8 +289,8 @@ impl Profile {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_conversations(conversations_json: &str) -> Result<HashMap<String, Conversation>, String> {
|
fn process_conversations(conversations_json: &str) -> Result<HashMap<i32, Conversation>, String> {
|
||||||
let mut conversations: HashMap<String, Conversation> = HashMap::new();
|
let mut conversations: HashMap<i32, Conversation> = HashMap::new();
|
||||||
if conversations_json == "null" {
|
if conversations_json == "null" {
|
||||||
return Ok(conversations);
|
return Ok(conversations);
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ impl Profile {
|
||||||
Err(e) => return Err(format!("invalid json: {:?}", e)),
|
Err(e) => return Err(format!("invalid json: {:?}", e)),
|
||||||
};
|
};
|
||||||
for conversation in conversations_map {
|
for conversation in conversations_map {
|
||||||
conversations.insert(conversation.handle.clone(), conversation);
|
conversations.insert(conversation.identifier, conversation);
|
||||||
}
|
}
|
||||||
Ok(conversations)
|
Ok(conversations)
|
||||||
}
|
}
|
||||||
|
@ -318,4 +318,12 @@ impl Profile {
|
||||||
}
|
}
|
||||||
Ok(servers)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue