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

room names: better make use of the hero names for locally computing a room display name #3461

Merged
merged 11 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ once_cell = "1.16.0"
pin-project-lite = "0.2.9"
rand = "0.8.5"
reqwest = { version = "0.12.4", default-features = false }
ruma = { version = "0.10.1", features = [
ruma = { git = "https://github.com/Hywan/ruma", branch = "feat-sliding-sync-list-include-heroes", features = [
"client-api-c",
"compat-upload-signatures",
"compat-user-id",
Expand All @@ -53,7 +53,7 @@ ruma = { version = "0.10.1", features = [
"unstable-msc3266",
"unstable-msc4075"
] }
ruma-common = { version = "0.13.0" }
ruma-common = { git = "https://github.com/Hywan/ruma", branch = "feat-sliding-sync-list-include-heroes" }
serde = "1.0.151"
serde_html_form = "0.2.0"
serde_json = "1.0.91"
Expand Down
4 changes: 3 additions & 1 deletion bindings/matrix-sdk-ffi/src/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ pub struct RequiredState {
pub struct RoomSubscription {
pub required_state: Option<Vec<RequiredState>>,
pub timeline_limit: Option<u32>,
pub include_heroes: Option<bool>,
}

impl From<RoomSubscription> for RumaRoomSubscription {
Expand All @@ -623,7 +624,8 @@ impl From<RoomSubscription> for RumaRoomSubscription {
required_state: val.required_state.map(|r|
r.into_iter().map(|s| (s.key.into(), s.value)).collect()
).unwrap_or_default(),
timeline_limit: val.timeline_limit.map(|u| u.into())
timeline_limit: val.timeline_limit.map(|u| u.into()),
include_heroes: val.include_heroes,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ impl BaseClient {
let mut room_info = room.clone_info();

room_info.mark_as_joined();
room_info.update_summary(&new_info.summary);
room_info.update_from_ruma_summary(&new_info.summary);
room_info.set_prev_batch(new_info.timeline.prev_batch.as_deref());
room_info.mark_state_fully_synced();

Expand Down
21 changes: 11 additions & 10 deletions crates/matrix-sdk-base/src/rooms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,9 @@ impl BaseRoomInfo {
&self,
joined_member_count: u64,
invited_member_count: u64,
heroes: Vec<RoomMember>,
heroes: Vec<&str>,
) -> DisplayName {
calculate_room_name(
joined_member_count,
invited_member_count,
heroes.iter().map(|mem| mem.name()).collect::<Vec<&str>>(),
)
calculate_room_name(joined_member_count, invited_member_count, heroes)
}

/// Get the room version of this room.
Expand Down Expand Up @@ -371,19 +367,21 @@ fn calculate_room_name(
invited_member_count: u64,
mut heroes: Vec<&str>,
) -> DisplayName {
let heroes_count = heroes.len() as u64;
let num_heroes = heroes.len() as u64;
let invited_joined = invited_member_count + joined_member_count;
let invited_joined_minus_one = invited_joined.saturating_sub(1);

// Stabilize ordering.
heroes.sort_unstable();

let names = if heroes_count >= invited_joined_minus_one {
let names = if num_heroes == 0 && invited_joined > 1 {
format!("{} people", invited_joined)
} else if num_heroes >= invited_joined_minus_one {
heroes.join(", ")
} else if heroes_count < invited_joined_minus_one && invited_joined > 1 {
} else if num_heroes < invited_joined_minus_one && invited_joined > 1 {
// TODO: What length does the spec want us to use here and in
// the `else`?
format!("{}, and {} others", heroes.join(", "), (invited_joined - heroes_count))
format!("{}, and {} others", heroes.join(", "), (invited_joined - num_heroes))
} else {
"".to_owned()
};
Expand Down Expand Up @@ -581,6 +579,9 @@ mod tests {
actual = calculate_room_name(5, 0, vec!["a", "b", "c"]);
assert_eq!(DisplayName::Calculated("a, b, c, and 2 others".to_owned()), actual);

actual = calculate_room_name(5, 0, vec![]);
assert_eq!(DisplayName::Calculated("5 people".to_owned()), actual);

actual = calculate_room_name(0, 0, vec![]);
assert_eq!(DisplayName::Empty, actual);

Expand Down
Loading
Loading