@@ -31,7 +31,11 @@ import { useTooltip } from "../../../utils/useTooltip";
31
31
import { _t } from "../../../languageHandler" ;
32
32
import { useRovingTabIndex } from "../../../accessibility/RovingTabIndex" ;
33
33
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
+
35
39
const READ_AVATAR_OFFSET = 10 ;
36
40
export const READ_AVATAR_SIZE = 16 ;
37
41
@@ -43,14 +47,24 @@ interface Props {
43
47
isTwelveHour : boolean ;
44
48
}
45
49
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 ) ;
49
57
50
58
if ( index >= firstVisible ) {
51
- return [ false , index - firstVisible ] ;
59
+ return {
60
+ hidden : false ,
61
+ position : index - firstVisible ,
62
+ } ;
52
63
} else {
53
- return [ true , 0 ] ;
64
+ return {
65
+ hidden : true ,
66
+ position : 0 ,
67
+ } ;
54
68
}
55
69
}
56
70
@@ -83,8 +97,13 @@ export function ReadReceiptGroup(
83
97
) ;
84
98
}
85
99
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
+
86
105
const avatars = readReceipts . map ( ( receipt , index ) => {
87
- const [ hidden , position ] = determineAvatarPosition ( index , readReceipts . length ) ;
106
+ const { hidden, position } = determineAvatarPosition ( index , readReceipts . length , maxAvatars ) ;
88
107
89
108
const userId = receipt . userId ;
90
109
let readReceiptInfo : IReadReceiptInfo ;
@@ -114,7 +133,7 @@ export function ReadReceiptGroup(
114
133
} ) ;
115
134
116
135
let remText : JSX . Element ;
117
- const remainder = readReceipts . length - MAX_READ_AVATARS ;
136
+ const remainder = readReceipts . length - maxAvatars ;
118
137
if ( remainder > 0 ) {
119
138
remText = (
120
139
< span className = "mx_ReadReceiptGroup_remainder" aria-live = "off" >
@@ -163,7 +182,7 @@ export function ReadReceiptGroup(
163
182
< span
164
183
className = "mx_ReadReceiptGroup_container"
165
184
style = { {
166
- width : Math . min ( MAX_READ_AVATARS , readReceipts . length ) * READ_AVATAR_OFFSET +
185
+ width : Math . min ( maxAvatars , readReceipts . length ) * READ_AVATAR_OFFSET +
167
186
READ_AVATAR_SIZE - READ_AVATAR_OFFSET ,
168
187
} }
169
188
>
0 commit comments