Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 5a5a792

Browse files
authored
Read Receipts: never show +1, if it’s just 4, show all of them (#8428)
* read receipts: never show +1, if it’s just 4, show all of them * read receipts: improve type signature for determineAvatarPosition
1 parent 6d22300 commit 5a5a792

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/components/views/rooms/ReadReceiptGroup.tsx

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ import { useTooltip } from "../../../utils/useTooltip";
3131
import { _t } from "../../../languageHandler";
3232
import { useRovingTabIndex } from "../../../accessibility/RovingTabIndex";
3333

34-
const MAX_READ_AVATARS = 3;
34+
// #20547 Design specified that we should show the three latest read receipts
35+
const MAX_READ_AVATARS_PLUS_N = 3;
36+
// #21935 If we’ve got just 4, don’t show +1, just show all of them
37+
const MAX_READ_AVATARS = MAX_READ_AVATARS_PLUS_N + 1;
38+
3539
const READ_AVATAR_OFFSET = 10;
3640
export const READ_AVATAR_SIZE = 16;
3741

@@ -43,14 +47,24 @@ interface Props {
4347
isTwelveHour: boolean;
4448
}
4549

46-
// Design specified that we should show the three latest read receipts
47-
function determineAvatarPosition(index, count): [boolean, number] {
48-
const firstVisible = Math.max(0, count - MAX_READ_AVATARS);
50+
interface IAvatarPosition {
51+
hidden: boolean;
52+
position: number;
53+
}
54+
55+
function determineAvatarPosition(index: number, count: number, max: number): IAvatarPosition {
56+
const firstVisible = Math.max(0, count - max);
4957

5058
if (index >= firstVisible) {
51-
return [false, index - firstVisible];
59+
return {
60+
hidden: false,
61+
position: index - firstVisible,
62+
};
5263
} else {
53-
return [true, 0];
64+
return {
65+
hidden: true,
66+
position: 0,
67+
};
5468
}
5569
}
5670

@@ -83,8 +97,13 @@ export function ReadReceiptGroup(
8397
);
8498
}
8599

100+
// If we are above MAX_READ_AVATARS, we’ll have to remove a few to have space for the +n count.
101+
const maxAvatars = readReceipts.length > MAX_READ_AVATARS
102+
? MAX_READ_AVATARS_PLUS_N
103+
: MAX_READ_AVATARS;
104+
86105
const avatars = readReceipts.map((receipt, index) => {
87-
const [hidden, position] = determineAvatarPosition(index, readReceipts.length);
106+
const { hidden, position } = determineAvatarPosition(index, readReceipts.length, maxAvatars);
88107

89108
const userId = receipt.userId;
90109
let readReceiptInfo: IReadReceiptInfo;
@@ -114,7 +133,7 @@ export function ReadReceiptGroup(
114133
});
115134

116135
let remText: JSX.Element;
117-
const remainder = readReceipts.length - MAX_READ_AVATARS;
136+
const remainder = readReceipts.length - maxAvatars;
118137
if (remainder > 0) {
119138
remText = (
120139
<span className="mx_ReadReceiptGroup_remainder" aria-live="off">
@@ -163,7 +182,7 @@ export function ReadReceiptGroup(
163182
<span
164183
className="mx_ReadReceiptGroup_container"
165184
style={{
166-
width: Math.min(MAX_READ_AVATARS, readReceipts.length) * READ_AVATAR_OFFSET +
185+
width: Math.min(maxAvatars, readReceipts.length) * READ_AVATAR_OFFSET +
167186
READ_AVATAR_SIZE - READ_AVATAR_OFFSET,
168187
}}
169188
>

0 commit comments

Comments
 (0)