base: use correct bound in naming algorithm
Step 3.ii of the name calculation algorithm[0] specifies the conditional as `heroes < invited + joined - 1 AND invited + joined > 1`. However, current implementation uses `invited + joined - 1 > 1` in the conditional, which can trigger the conditional if the user is alone. Correct this by using two variables representing `invited + joined` and `invited_joined - 1` and updating the conditional. `invited + joined` is kept as a variable since step 3.iii uses it for its conditional. [0] https://matrix.org/docs/spec/client_server/latest#calculating-the-display-name-for-a-roommaster
parent
fe17dce813
commit
c90e8ab483
|
@ -63,14 +63,15 @@ impl BaseRoomInfo {
|
||||||
heroes: Vec<RoomMember>,
|
heroes: Vec<RoomMember>,
|
||||||
) -> String {
|
) -> String {
|
||||||
let heroes_count = heroes.len() as u64;
|
let heroes_count = heroes.len() as u64;
|
||||||
let invited_joined = (invited_member_count + joined_member_count).saturating_sub(1);
|
let invited_joined = invited_member_count + joined_member_count;
|
||||||
|
let invited_joined_minus_one = invited_joined.saturating_sub(1);
|
||||||
|
|
||||||
if heroes_count >= invited_joined {
|
if heroes_count >= invited_joined_minus_one {
|
||||||
let mut names = heroes.iter().take(3).map(|mem| mem.name()).collect::<Vec<&str>>();
|
let mut names = heroes.iter().take(3).map(|mem| mem.name()).collect::<Vec<&str>>();
|
||||||
// stabilize ordering
|
// stabilize ordering
|
||||||
names.sort_unstable();
|
names.sort_unstable();
|
||||||
names.join(", ")
|
names.join(", ")
|
||||||
} else if heroes_count < invited_joined && invited_joined > 1 {
|
} else if heroes_count < invited_joined_minus_one && invited_joined > 1 {
|
||||||
let mut names = heroes.iter().take(3).map(|mem| mem.name()).collect::<Vec<&str>>();
|
let mut names = heroes.iter().take(3).map(|mem| mem.name()).collect::<Vec<&str>>();
|
||||||
names.sort_unstable();
|
names.sort_unstable();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue