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
master
Austin Ray 2021-05-21 18:48:19 -04:00
parent 79025e3f40
commit 5670700f7f
No known key found for this signature in database
GPG Key ID: 89D6C2B99503DC49
1 changed files with 21 additions and 1 deletions

View File

@ -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);
}
}