diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 41b9add70..3b10fca2d 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -1613,46 +1613,6 @@ impl Client { Ok(room::Joined::new(self, base_room).unwrap()) } - /// Create a direct message room with the specified user. - #[cfg(not(feature = "e2e-encryption"))] - pub async fn create_dm_room(&self, user_id: &UserId) -> Result { - use ruma::{ - api::client::room::create_room::v3::RoomPreset, events::direct::DirectEventContent, - }; - - // First we create the DM room, where we invite the user and tell the - // invitee that the room should be a DM. - let invite = &[user_id.to_owned()]; - - let request = assign!(ruma::api::client::room::create_room::v3::Request::new(), { - invite, - is_direct: true, - preset: Some(RoomPreset::TrustedPrivateChat), - }); - - let room = self.create_room(request).await?; - - // Now we need to mark the room as a DM for ourselves, we fetch the - // existing `m.direct` event and append the room to the list of DMs we - // have with this user. - let mut content = self - .account() - .account_data::() - .await? - .map(|c| c.deserialize()) - .transpose()? - .unwrap_or_default(); - - content.entry(user_id.to_owned()).or_default().push(room.room_id().to_owned()); - - // TODO We should probably save the fact that we need to send this out - // because otherwise we might end up in a state where we have a DM that - // isn't marked as one. - self.account().set_account_data(content).await?; - - Ok(room) - } - /// Search the homeserver's directory for public rooms with a filter. /// /// # Arguments diff --git a/crates/matrix-sdk/src/encryption/identities/users.rs b/crates/matrix-sdk/src/encryption/identities/users.rs index 9e8d27248..711a6416e 100644 --- a/crates/matrix-sdk/src/encryption/identities/users.rs +++ b/crates/matrix-sdk/src/encryption/identities/users.rs @@ -475,12 +475,8 @@ impl OtherUserIdentity { room.invite_user_by_id(self.inner.user_id()).await?; } room.clone() - } else if let Some(room) = - self.client.create_dm_room(self.inner.user_id().to_owned()).await? - { - room } else { - return Err(RequestVerificationError::RoomCreation(self.inner.user_id().to_owned())); + self.client.create_dm_room(self.inner.user_id().to_owned()).await? }; let response = room diff --git a/crates/matrix-sdk/src/encryption/mod.rs b/crates/matrix-sdk/src/encryption/mod.rs index 6f0881e53..a7cca5c2c 100644 --- a/crates/matrix-sdk/src/encryption/mod.rs +++ b/crates/matrix-sdk/src/encryption/mod.rs @@ -38,7 +38,6 @@ pub use matrix_sdk_base::crypto::{ use matrix_sdk_base::crypto::{ CrossSigningStatus, OutgoingRequest, RoomMessageRequest, ToDeviceRequest, }; -use matrix_sdk_common::instant::Duration; #[cfg(feature = "e2e-encryption")] use ruma::OwnedDeviceId; use ruma::{ @@ -227,16 +226,11 @@ impl Client { } #[cfg(feature = "e2e-encryption")] - pub(crate) async fn create_dm_room( - &self, - user_id: OwnedUserId, - ) -> Result> { + pub(crate) async fn create_dm_room(&self, user_id: OwnedUserId) -> Result { use ruma::{ api::client::room::create_room::v3::RoomPreset, events::direct::DirectEventContent, }; - const SYNC_WAIT_TIME: Duration = Duration::from_secs(3); - // First we create the DM room, where we invite the user and tell the // invitee that the room should be a DM. let invite = &[user_id.clone()]; @@ -247,7 +241,7 @@ impl Client { preset: Some(RoomPreset::TrustedPrivateChat), }); - let response = self.send(request, None).await?; + let room = self.create_room(request).await?; // Now we need to mark the room as a DM for ourselves, we fetch the // existing `m.direct` event and append the room to the list of DMs we @@ -260,21 +254,14 @@ impl Client { .transpose()? .unwrap_or_default(); - content.entry(user_id.to_owned()).or_default().push(response.room_id.to_owned()); + content.entry(user_id.to_owned()).or_default().push(room.room_id().to_owned()); // TODO We should probably save the fact that we need to send this out // because otherwise we might end up in a state where we have a DM that // isn't marked as one. self.account().set_account_data(content).await?; - // If the room is already in our store, fetch it, otherwise wait for a - // sync to be done which should put the room into our store. - if let Some(room) = self.get_joined_room(&response.room_id) { - Ok(Some(room)) - } else { - self.inner.sync_beat.listen().wait_timeout(SYNC_WAIT_TIME); - Ok(self.get_joined_room(&response.room_id)) - } + Ok(room) } /// Claim one-time keys creating new Olm sessions.