Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk,base,ui,ffi): Continue to remove dead code in SlidingSyncRoom #3084

Merged

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Feb 1, 2024

This patch continues the clean up of matrix_sdk::sliding_sync::SlidingSyncRoom. Please read commit-by-commit. 3 methods are removed, because either they are never used, or because the data they contain are a duplication with the matrix_sdk_base::Room.


This patch removes the `SlidingSyncRoom::is_initial_response` method.
It's not used anywhere in the SDK, neither by the FFI bindings. Since
this code is still experimental, it's fine to remove public API.
This patch removes the `SlidingSyncRoom::is_dm` method. It's not used
anywhere in the SDK, neither by the FFI bindings. Since this code is
still experimental, it's fine to remove public API.
This patch removes the `SlidingSyncRoom::name` method. The name is
already synchronized with the `matrix_sdk_base::Room`. This code is
then useless.
@Hywan Hywan requested a review from a team as a code owner February 1, 2024 14:28
@Hywan Hywan requested review from poljar and bnjbvr and removed request for a team and poljar February 1, 2024 14:28
Copy link

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (61a5f1b) 83.72% compared to head (a802b73) 83.73%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3084   +/-   ##
=======================================
  Coverage   83.72%   83.73%           
=======================================
  Files         224      224           
  Lines       23508    23497   -11     
=======================================
- Hits        19683    19675    -8     
+ Misses       3825     3822    -3     

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

Some(name) => name,
None => self.inner.room.display_name().await.ok()?.to_string(),
})
Some(self.inner.room.display_name().await.ok()?.to_string())
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we certain that this is not needed? The proxy calculates the room name for us even before we have all the members or events, i.e. it does what display_name() does for us.

I see that we're storing whatever the proxy sends to us as the m.room.name event in the RoomInfo since #2032.

But that PR seems to be questionable at best. Though the PR should mean that these two method do contain the same info.

Copy link
Member

Choose a reason for hiding this comment

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

Oops, auto-merge strikes again 😨

Copy link
Member Author

Choose a reason for hiding this comment

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

The SS room name is synced with the room and room info during the sync process. So yeah, this is not needed to keep it in SS room anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

And to reply concretely to your mesasge, normally display_name returns early if RoomInfo contains a name,

async fn calculate_name(&self) -> StoreResult<DisplayName> {
let summary = {
let inner = self.inner.read();
if let Some(name) = inner.name() {
let name = name.trim();
return Ok(DisplayName::Named(name.to_owned()));
}
.

Also, we have this test that ensures the behaviour at the sliding sync level,

async fn display_name_from_sliding_sync_overrides_alias() {
// Given a logged-in client
let client = logged_in_client().await;
let room_id = room_id!("!r:e.uk");
let user_id = user_id!("@u:e.uk");
let room_alias_id = room_alias_id!("#myroom:e.uk");
// When the sliding sync response contains an explicit room name as well as an
// alias
let mut room = room_with_canonical_alias(room_alias_id, user_id);
room.name = Some("This came from the server".to_owned());
let response = response_with_room(room_id, room).await;
client.process_sliding_sync(&response, &()).await.expect("Failed to process sync");
// Then the room's name is just exactly what the server supplied
let client_room = client.get_room(room_id).expect("No room found");
assert_eq!(
client_room.display_name().await.unwrap().to_string(),
"This came from the server"
);
}
.

Copy link
Contributor

Choose a reason for hiding this comment

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

And to reply concretely to your mesasge, normally display_name returns early if RoomInfo contains a name,

I know what display_name() does, it follows the spec: https://spec.matrix.org/unstable/client-server-api/#calculating-the-display-name-for-a-room.

What I'm complaining about is that we put something that isn't a m.room.name event content into the field that always should contain a m.room.name event content.

The thing that the SS proxy returns is not a m.room.name event, it's the result of the calculation I linked previously done by the proxy.

Incidentally this thing works, because we created a fake m.room.name event and put it in the same field, the spec tells you to take this field verbatim. The problem is that this data, while also being a string, is semantically very different.

This might now contain the field "Tom, Dick, and Harry" for a three person room, but this string should be localized and we lost any way of doing and detecting this case because we pretended that it's actually an m.room.name event that contains "Tom, Dick, and Harry".

I should probably post this complaint on the PR instead or just open a new issue. I find such hacks that make things quickly work, but mangle with the correctness and make future features harder to implement, for example like the localization of room display names, the bane of our existence.

@Hywan Hywan merged commit b951d0d into matrix-org:main Feb 1, 2024
34 checks passed
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.

3 participants