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

Commit

Permalink
read receipts: improve tooltips to show names of users
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Apr 29, 2022
1 parent 565488a commit f17f75f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
47 changes: 37 additions & 10 deletions src/components/views/rooms/ReadReceiptGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ interface IAvatarPosition {
}

function determineAvatarPosition(index: number, count: number, max: number): IAvatarPosition {
const firstVisible = Math.max(0, count - max);

if (index >= firstVisible) {
if (index < max) {
return {
hidden: false,
position: index - firstVisible,
position: Math.min(count, max) - index,
};
} else {
return {
Expand All @@ -72,8 +70,42 @@ export function ReadReceiptGroup(
{ readReceipts, readReceiptMap, checkUnmounting, suppressAnimation, isTwelveHour }: Props,
) {
const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu();

// If we are above MAX_READ_AVATARS, we’ll have to remove a few to have space for the +n count.
const maxAvatars = readReceipts.length > MAX_READ_AVATARS
? MAX_READ_AVATARS_PLUS_N
: MAX_READ_AVATARS;

const tooltipMembers: string[] = readReceipts.slice(0, maxAvatars)
.map(it => it.roomMember?.name ?? it.userId);
let tooltipText: string | null;
if (readReceipts.length > MAX_READ_AVATARS) {
tooltipText = _t("%(members)s and more", {
members: tooltipMembers.join(", "),
});
} else if (readReceipts.length) {
const last = tooltipMembers.pop();
if (last) {
tooltipText = _t("%(members)s and %(last)s", {
members: tooltipMembers.join(", "),
last: last,
});
} else {
tooltipText = tooltipMembers.join(", ");
}
}

const [{ showTooltip, hideTooltip }, tooltip] = useTooltip({
label: _t("Seen by %(count)s people", { count: readReceipts.length }),
label: (
<>
<div className="mx_Tooltip_title">
{ _t("Seen by %(count)s people", { count: readReceipts.length }) }
</div>
<div className="mx_Tooltip_sub">
{ tooltipText }
</div>
</>
),
alignment: Alignment.TopRight,
});

Expand All @@ -97,11 +129,6 @@ export function ReadReceiptGroup(
);
}

// If we are above MAX_READ_AVATARS, we’ll have to remove a few to have space for the +n count.
const maxAvatars = readReceipts.length > MAX_READ_AVATARS
? MAX_READ_AVATARS_PLUS_N
: MAX_READ_AVATARS;

const avatars = readReceipts.map((receipt, index) => {
const { hidden, position } = determineAvatarPosition(index, readReceipts.length, maxAvatars);

Expand Down
2 changes: 2 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,8 @@
"Preview": "Preview",
"View": "View",
"Join": "Join",
"%(members)s and more": "%(members)s and more",
"%(members)s and %(last)s": "%(members)s and %(last)s",
"Seen by %(count)s people|other": "Seen by %(count)s people",
"Seen by %(count)s people|one": "Seen by %(count)s person",
"Recently viewed": "Recently viewed",
Expand Down

0 comments on commit f17f75f

Please sign in to comment.