@@ -235,7 +235,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
235
235
// This is recomputed on each render. It's only stored on the component
236
236
// for ease of passing the data around since it's computed in one pass
237
237
// over all events.
238
- private readReceiptsByEvent : Record < string , IReadReceiptProps [ ] > = { } ;
238
+ private readReceiptsByEvent : Map < string , IReadReceiptProps [ ] > = new Map ( ) ;
239
239
240
240
// Track read receipts by user ID. For each user ID we've ever shown a
241
241
// a read receipt for, we store an object:
@@ -254,7 +254,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
254
254
// This is recomputed on each render, using the data from the previous
255
255
// render as our fallback for any user IDs we can't match a receipt to a
256
256
// displayed event in the current render cycle.
257
- private readReceiptsByUserId : Record < string , IReadReceiptForUser > = { } ;
257
+ private readReceiptsByUserId : Map < string , IReadReceiptForUser > = new Map ( ) ;
258
258
259
259
private readonly _showHiddenEvents : boolean ;
260
260
private isMounted = false ;
@@ -624,7 +624,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
624
624
// Note: the EventTile might still render a "sent/sending receipt" independent of
625
625
// this information. When not providing read receipt information, the tile is likely
626
626
// to assume that sent receipts are to be shown more often.
627
- this . readReceiptsByEvent = { } ;
627
+ this . readReceiptsByEvent = new Map ( ) ;
628
628
if ( this . props . showReadReceipts ) {
629
629
this . readReceiptsByEvent = this . getReadReceiptsByShownEvent ( ) ;
630
630
}
@@ -727,7 +727,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
727
727
const eventId = mxEv . getId ( ) ;
728
728
const highlight = eventId === this . props . highlightedEventId ;
729
729
730
- const readReceipts = this . readReceiptsByEvent [ eventId ] ;
730
+ const readReceipts = this . readReceiptsByEvent . get ( eventId ) ;
731
731
732
732
let isLastSuccessful = false ;
733
733
const isSentState = ( s : EventStatus ) : boolean => ! s || s === EventStatus . SENT ;
@@ -846,17 +846,11 @@ export default class MessagePanel extends React.Component<IProps, IState> {
846
846
// Get an object that maps from event ID to a list of read receipts that
847
847
// should be shown next to that event. If a hidden event has read receipts,
848
848
// they are folded into the receipts of the last shown event.
849
- private getReadReceiptsByShownEvent ( ) : Record < string , IReadReceiptProps [ ] > {
850
- const receiptsByEvent : Record < string , IReadReceiptProps [ ] > = { } ;
851
- const receiptsByUserId : Record <
852
- string ,
853
- {
854
- lastShownEventId : string ;
855
- receipt : IReadReceiptProps ;
856
- }
857
- > = { } ;
849
+ private getReadReceiptsByShownEvent ( ) : Map < string , IReadReceiptProps [ ] > {
850
+ const receiptsByEvent : Map < string , IReadReceiptProps [ ] > = new Map ( ) ;
851
+ const receiptsByUserId : Map < string , IReadReceiptForUser > = new Map ( ) ;
858
852
859
- let lastShownEventId ;
853
+ let lastShownEventId : string ;
860
854
for ( const event of this . props . events ) {
861
855
if ( this . shouldShowEvent ( event ) ) {
862
856
lastShownEventId = event . getId ( ) ;
@@ -865,9 +859,9 @@ export default class MessagePanel extends React.Component<IProps, IState> {
865
859
continue ;
866
860
}
867
861
868
- const existingReceipts = receiptsByEvent [ lastShownEventId ] || [ ] ;
862
+ const existingReceipts = receiptsByEvent . get ( lastShownEventId ) || [ ] ;
869
863
const newReceipts = this . getReadReceiptsForEvent ( event ) ;
870
- receiptsByEvent [ lastShownEventId ] = existingReceipts . concat ( newReceipts ) ;
864
+ receiptsByEvent . set ( lastShownEventId , existingReceipts . concat ( newReceipts ) ) ;
871
865
872
866
// Record these receipts along with their last shown event ID for
873
867
// each associated user ID.
@@ -885,21 +879,21 @@ export default class MessagePanel extends React.Component<IProps, IState> {
885
879
// someone which had one in the last. By looking through our previous
886
880
// mapping of receipts by user ID, we can cover recover any receipts
887
881
// that would have been lost by using the same event ID from last time.
888
- for ( const userId in this . readReceiptsByUserId ) {
889
- if ( receiptsByUserId [ userId ] ) {
882
+ for ( const userId of this . readReceiptsByUserId . keys ( ) ) {
883
+ if ( receiptsByUserId . get ( userId ) ) {
890
884
continue ;
891
885
}
892
- const { lastShownEventId, receipt } = this . readReceiptsByUserId [ userId ] ;
893
- const existingReceipts = receiptsByEvent [ lastShownEventId ] || [ ] ;
894
- receiptsByEvent [ lastShownEventId ] = existingReceipts . concat ( receipt ) ;
895
- receiptsByUserId [ userId ] = { lastShownEventId, receipt } ;
886
+ const { lastShownEventId, receipt } = this . readReceiptsByUserId . get ( userId ) ;
887
+ const existingReceipts = receiptsByEvent . get ( lastShownEventId ) || [ ] ;
888
+ receiptsByEvent . set ( lastShownEventId , existingReceipts . concat ( receipt ) ) ;
889
+ receiptsByUserId . set ( userId , { lastShownEventId, receipt } ) ;
896
890
}
897
891
this . readReceiptsByUserId = receiptsByUserId ;
898
892
899
893
// After grouping receipts by shown events, do another pass to sort each
900
894
// receipt list.
901
- for ( const eventId in receiptsByEvent ) {
902
- receiptsByEvent [ eventId ] . sort ( ( r1 , r2 ) => {
895
+ for ( const receipts of receiptsByEvent . values ( ) ) {
896
+ receipts . sort ( ( r1 , r2 ) => {
903
897
return r2 . ts - r1 . ts ;
904
898
} ) ;
905
899
}
0 commit comments