Skip to content

Conversation

@bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented May 15, 2025

This moves the logic from Room::join() to these two methods. This is isofunctional, because Room::join() does call into Client::join_room_by_id() internally.

Fix #4730.

@bnjbvr bnjbvr requested a review from a team as a code owner May 15, 2025 10:37
@bnjbvr bnjbvr requested review from poljar and removed request for a team May 15, 2025 10:37
@codecov
Copy link

codecov bot commented May 15, 2025

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 85.84%. Comparing base (c0e45a2) to head (e833028).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/client/mod.rs 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5043      +/-   ##
==========================================
+ Coverage   85.83%   85.84%   +0.01%     
==========================================
  Files         325      325              
  Lines       35896    35900       +4     
==========================================
+ Hits        30810    30820      +10     
+ Misses       5086     5080       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@pixlwave pixlwave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, testing this on EXI it works well 👏

Linking: element-hq/element-x-ios#3958

Comment on lines 1438 to 1446

let mark_as_dm = self.must_mark_joined_room_as_dm(&response.room_id).await;
let base_room = self.base_client().room_joined(&response.room_id).await?;
Ok(Room::new(self.clone(), base_room))
let room = Room::new(self.clone(), base_room);
if mark_as_dm {
room.set_is_direct(true).await?;
}

Ok(room)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we put this code snippet into a function? Seems like we have the same thing in two places now, unless I'm missing something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I've put all of this inside must_mark_joined_room_as_dm and renamed it finish_join_room 👍

@bnjbvr bnjbvr force-pushed the bnjbvr/fix-joined-room-not-marked-as-dms branch from 05ce616 to bb5a82b Compare May 15, 2025 12:01
@bnjbvr bnjbvr enabled auto-merge (rebase) May 15, 2025 12:02
…d_or_alias` as DMs if needs be

This moves the logic from `Room::join()` to these two methods. This is
isofunctional, because `Room::join()` does call into
`Client::join_room_by_id()` internally.
@bnjbvr bnjbvr force-pushed the bnjbvr/fix-joined-room-not-marked-as-dms branch from bb5a82b to e833028 Compare May 15, 2025 12:04
@bnjbvr bnjbvr merged commit 69b8878 into main May 15, 2025
41 checks passed
@bnjbvr bnjbvr deleted the bnjbvr/fix-joined-room-not-marked-as-dms branch May 15, 2025 12:19
/// in the DM event after creating the joined room.
async fn finish_join_room(&self, room_id: &RoomId) -> Result<Room> {
let mark_as_dm = if let Some(room) = self.get_room(room_id) {
room.state() == RoomState::Invited
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this race with the /sync response, causing it to do the wrong thing if the /sync response arrives before the /join completes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍 I suppose passing the previous room state, in the callers, captured before sending the join_room requests, would be sufficient to avoid the race (but would also need some kind of regression test to prove it can happen in the first place).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Starting a DM with the same user twice results in 2 entries in m.direct.

5 participants