room: mark encryption state as missing if a room thinks it's not encrypted after requesting it
This commit is contained in:
@@ -1575,6 +1575,25 @@ impl Room {
|
||||
// could be quite useful if someone wants to enable encryption and
|
||||
// send a message right after it's enabled.
|
||||
_ = timeout(self.client.inner.sync_beat.listen(), SYNC_WAIT_TIME).await;
|
||||
|
||||
// If after waiting for a sync, we don't have the encryption state we expect,
|
||||
// assume the local encryption state is incorrect; this will cause
|
||||
// the SDK to re-request it later for confirmation, instead of
|
||||
// assuming it's sync'd and correct (and not encrypted).
|
||||
let _sync_lock = self.client.base_client().sync_lock().lock().await;
|
||||
if !self.inner.is_encrypted() {
|
||||
debug!("still not marked as encrypted, marking encryption state as missing");
|
||||
|
||||
let mut room_info = self.clone_info();
|
||||
room_info.mark_encryption_state_missing();
|
||||
let mut changes = StateChanges::default();
|
||||
changes.add_room(room_info.clone());
|
||||
|
||||
self.client.store().save_changes(&changes).await?;
|
||||
self.set_room_info(room_info, RoomInfoNotableUpdateReasons::empty());
|
||||
} else {
|
||||
debug!("room successfully marked as encrypted");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -761,3 +761,37 @@ async fn test_make_reply_event_doesnt_require_event_cache() {
|
||||
// make_edit_event works, even if the event cache hasn't been enabled.
|
||||
room.make_edit_event(resp_event_id, EditedContent::RoomMessage(new_content)).await.unwrap();
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_enable_encryption_doesnt_stay_unencrypted() {
|
||||
let (client, server) = logged_in_client_with_server().await;
|
||||
|
||||
mock_encryption_state(&server, false).await;
|
||||
|
||||
Mock::given(method("PUT"))
|
||||
.and(path_regex(r"^/_matrix/client/r0/rooms/.*/state/m.*room.*encryption.?"))
|
||||
.and(header("authorization", "Bearer 1234"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "event_id": "$1"})))
|
||||
.mount(&server)
|
||||
.await;
|
||||
|
||||
let room_id = room_id!("!a:b.c");
|
||||
let room = mock_sync_with_new_room(
|
||||
|builder| {
|
||||
builder.add_joined_room(JoinedRoomBuilder::new(room_id));
|
||||
},
|
||||
&client,
|
||||
&server,
|
||||
room_id,
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(!room.is_encrypted().await.unwrap());
|
||||
|
||||
room.enable_encryption().await.expect("enabling encryption should work");
|
||||
|
||||
server.reset().await;
|
||||
mock_encryption_state(&server, true).await;
|
||||
|
||||
assert!(room.is_encrypted().await.unwrap());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user