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

Commit ed2a6ad

Browse files
committed
read receipts: improve tooltips to show names of users
1 parent 6120ada commit ed2a6ad

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

src/components/views/rooms/ReadReceiptGroup.tsx

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ interface IAvatarPosition {
5353
}
5454

5555
function determineAvatarPosition(index: number, count: number, max: number): IAvatarPosition {
56-
const firstVisible = Math.max(0, count - max);
57-
58-
if (index >= firstVisible) {
56+
if (index < max) {
5957
return {
6058
hidden: false,
61-
position: index - firstVisible,
59+
position: Math.min(count, max) - index,
6260
};
6361
} else {
6462
return {
@@ -72,8 +70,42 @@ export function ReadReceiptGroup(
7270
{ readReceipts, readReceiptMap, checkUnmounting, suppressAnimation, isTwelveHour }: Props,
7371
) {
7472
const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu();
73+
74+
// If we are above MAX_READ_AVATARS, we’ll have to remove a few to have space for the +n count.
75+
const maxAvatars = readReceipts.length > MAX_READ_AVATARS
76+
? MAX_READ_AVATARS_PLUS_N
77+
: MAX_READ_AVATARS;
78+
79+
const tooltipMembers: string[] = readReceipts.slice(0, maxAvatars)
80+
.map(it => it.roomMember?.name ?? it.userId);
81+
let tooltipText: string | null;
82+
if (readReceipts.length > MAX_READ_AVATARS) {
83+
tooltipText = _t("%(members)s and more", {
84+
members: tooltipMembers.join(", "),
85+
});
86+
} else if (readReceipts.length) {
87+
const last = tooltipMembers.pop();
88+
if (last) {
89+
tooltipText = _t("%(members)s and %(last)s", {
90+
members: tooltipMembers.join(", "),
91+
last: last,
92+
});
93+
} else {
94+
tooltipText = tooltipMembers.join(", ");
95+
}
96+
}
97+
7598
const [{ showTooltip, hideTooltip }, tooltip] = useTooltip({
76-
label: _t("Seen by %(count)s people", { count: readReceipts.length }),
99+
label: (
100+
<>
101+
<div className="mx_Tooltip_title">
102+
{ _t("Seen by %(count)s people", { count: readReceipts.length }) }
103+
</div>
104+
<div className="mx_Tooltip_sub">
105+
{ tooltipText }
106+
</div>
107+
</>
108+
),
77109
alignment: Alignment.TopRight,
78110
});
79111

@@ -97,11 +129,6 @@ export function ReadReceiptGroup(
97129
);
98130
}
99131

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-
105132
const avatars = readReceipts.map((receipt, index) => {
106133
const { hidden, position } = determineAvatarPosition(index, readReceipts.length, maxAvatars);
107134

src/i18n/strings/en_EN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,8 @@
17661766
"Preview": "Preview",
17671767
"View": "View",
17681768
"Join": "Join",
1769+
"%(members)s and more": "%(members)s and more",
1770+
"%(members)s and %(last)s": "%(members)s and %(last)s",
17691771
"Seen by %(count)s people|other": "Seen by %(count)s people",
17701772
"Seen by %(count)s people|one": "Seen by %(count)s person",
17711773
"Recently viewed": "Recently viewed",

0 commit comments

Comments
 (0)