From a38990573436f6f3498434e0805ab4de0caa847f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 10 Apr 2020 11:47:01 +0200 Subject: [PATCH] base_client: Expose the method to check if a group session needs to be shared. --- src/base_client.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/base_client.rs b/src/base_client.rs index 677214cf..12164686 100644 --- a/src/base_client.rs +++ b/src/base_client.rs @@ -399,6 +399,25 @@ impl Client { } } + /// Should the client share a group session for the given room. + /// + /// Returns true if a session needs to be shared before room messages can be + /// encrypted, false if one is already shared and ready to encrypt room + /// messages. + /// + /// This should be called every time a new room message wants to be sent out + /// since group sessions can expire at any time. + #[cfg(feature = "encryption")] + #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))] + pub async fn should_share_group_session(&self, room_id: &RoomId) -> bool { + let olm = self.olm.lock().await; + + match &*olm { + Some(o) => o.should_share_group_session(room_id), + None => false, + } + } + /// Should users be queried for their device keys. #[cfg(feature = "encryption")] #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))]