async_client: Claim keys for missing sessions if we try to send in an encrypted room.

master
Damir Jelić 2020-04-03 10:30:32 +02:00
parent 2dd84517b9
commit 670761376d
1 changed files with 32 additions and 1 deletions

View File

@ -511,7 +511,7 @@ impl AsyncClient {
if self.base_client.read().await.should_query_keys().await { if self.base_client.read().await.should_query_keys().await {
// TODO enable this // TODO enable this
// let _ = self.keys_query().await; let _ = self.keys_query().await;
} }
} }
@ -627,6 +627,37 @@ impl AsyncClient {
room_id: &str, room_id: &str,
data: MessageEventContent, data: MessageEventContent,
) -> Result<create_message_event::Response> { ) -> Result<create_message_event::Response> {
#[cfg(feature = "encryption")]
{
let encrypted = {
let client = self.base_client.read().await;
let room = client.joined_rooms.get(room_id);
match room {
Some(r) => r.lock().await.is_encrypted(),
None => false,
}
};
if encrypted {
let missing_sessions = {
let client = self.base_client.read().await;
let room = client.joined_rooms.get(room_id);
let room = room.as_ref().unwrap().lock().await;
let users = room.members.keys();
self.base_client
.read()
.await
.get_missing_sessions(users)
.await
};
if !missing_sessions.is_empty() {
let _ = self.claim_one_time_keys(missing_sessions).await;
}
}
}
let request = create_message_event::Request { let request = create_message_event::Request {
room_id: RoomId::try_from(room_id).unwrap(), room_id: RoomId::try_from(room_id).unwrap(),
event_type: EventType::RoomMessage, event_type: EventType::RoomMessage,