From 5670700f7f86cc512343e80635d1d50d8eb414ea Mon Sep 17 00:00:00 2001 From: Austin Ray Date: Fri, 21 May 2021 18:48:19 -0400 Subject: [PATCH] base: fix room name's "and {} others" count The current implementation uses number of invited and joined members for "and {} others" message. This assigns rooms with 5 members the name "a, b, c, and 5 others" suggesting 8 room members. The correct message is "a, b, c, and 2 others". To get this, subtract number of heroes from invited and joined member count. Step 3.ii of the naming algorithm[0] confirms using a remaining users count in the name. [0] https://matrix.org/docs/spec/client_server/latest#calculating-the-display-name-for-a-room --- matrix_sdk_base/src/rooms/mod.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/matrix_sdk_base/src/rooms/mod.rs b/matrix_sdk_base/src/rooms/mod.rs index 6ade20f4..244955b7 100644 --- a/matrix_sdk_base/src/rooms/mod.rs +++ b/matrix_sdk_base/src/rooms/mod.rs @@ -171,8 +171,28 @@ fn calculate_room_name( // TODO: What length does the spec want us to use here and in // the `else`? - format!("{}, and {} others", names.join(", "), (joined_member_count + invited_member_count)) + format!("{}, and {} others", names.join(", "), (invited_joined - heroes_count)) } else { "Empty room".to_string() } } + +#[cfg(test)] +mod tests { + use super::*; + #[test] + + fn test_calculate_room_name() { + let mut actual = calculate_room_name(2, 0, vec!["a"]); + assert_eq!("a", actual); + + actual = calculate_room_name(3, 0, vec!["a", "b"]); + assert_eq!("a, b", actual); + + actual = calculate_room_name(4, 0, vec!["a", "b", "c"]); + assert_eq!("a, b, c", actual); + + actual = calculate_room_name(5, 0, vec!["a", "b", "c"]); + assert_eq!("a, b, c, and 2 others", actual); + } +}