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

Commit 986bc6f

Browse files
committed
read receipts: improve type signature for determineAvatarPosition
1 parent d9a2ecf commit 986bc6f

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/components/views/rooms/ReadReceiptGroup.tsx

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

34-
const MAX_READ_AVATARS = 4;
35-
const MAX_READ_AVATARS_PLUS_N = MAX_READ_AVATARS - 1;
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+
3639
const READ_AVATAR_OFFSET = 10;
3740
export const READ_AVATAR_SIZE = 16;
3841

@@ -44,14 +47,24 @@ interface Props {
4447
isTwelveHour: boolean;
4548
}
4649

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

5158
if (index >= firstVisible) {
52-
return [false, index - firstVisible];
59+
return {
60+
hidden: false,
61+
position: index - firstVisible,
62+
};
5363
} else {
54-
return [true, 0];
64+
return {
65+
hidden: true,
66+
position: 0,
67+
};
5568
}
5669
}
5770

@@ -90,7 +103,7 @@ export function ReadReceiptGroup(
90103
: MAX_READ_AVATARS;
91104

92105
const avatars = readReceipts.map((receipt, index) => {
93-
const [hidden, position] = determineAvatarPosition(index, readReceipts.length, maxAvatars);
106+
const { hidden, position } = determineAvatarPosition(index, readReceipts.length, maxAvatars);
94107

95108
const userId = receipt.userId;
96109
let readReceiptInfo: IReadReceiptInfo;

0 commit comments

Comments
 (0)