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-roommaster
parent
79025e3f40
commit
5670700f7f
|
@ -171,8 +171,28 @@ fn calculate_room_name(
|
||||||
|
|
||||||
// TODO: What length does the spec want us to use here and in
|
// TODO: What length does the spec want us to use here and in
|
||||||
// the `else`?
|
// the `else`?
|
||||||
format!("{}, and {} others", names.join(", "), (joined_member_count + invited_member_count))
|
format!("{}, and {} others", names.join(", "), (invited_joined - heroes_count))
|
||||||
} else {
|
} else {
|
||||||
"Empty room".to_string()
|
"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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue