@@ -67,7 +67,6 @@ export interface EventTileTypeProps {
67
67
68
68
type FactoryProps = Omit < EventTileTypeProps , "ref" > ;
69
69
type Factory < X = FactoryProps > = ( ref : Optional < React . RefObject < any > > , props : X ) => JSX . Element ;
70
- type FactoryMap = Record < string , Factory > ;
71
70
72
71
const MessageEventFactory : Factory = ( ref , props ) => < MessageEvent ref = { ref } { ...props } /> ;
73
72
const KeyVerificationConclFactory : Factory = ( ref , props ) => < MKeyVerificationConclusion ref = { ref } { ...props } /> ;
@@ -82,40 +81,40 @@ const HiddenEventFactory: Factory = (ref, props) => <HiddenBody ref={ref} {...pr
82
81
export const JitsiEventFactory : Factory = ( ref , props ) => < MJitsiWidgetEvent ref = { ref } { ...props } /> ;
83
82
export const JSONEventFactory : Factory = ( ref , props ) => < ViewSourceEvent ref = { ref } { ...props } /> ;
84
83
85
- const EVENT_TILE_TYPES : FactoryMap = {
86
- [ EventType . RoomMessage ] : MessageEventFactory , // note that verification requests are handled in pickFactory()
87
- [ EventType . Sticker ] : MessageEventFactory ,
88
- [ M_POLL_START . name ] : MessageEventFactory ,
89
- [ M_POLL_START . altName ] : MessageEventFactory ,
90
- [ EventType . KeyVerificationCancel ] : KeyVerificationConclFactory ,
91
- [ EventType . KeyVerificationDone ] : KeyVerificationConclFactory ,
92
- [ EventType . CallInvite ] : CallEventFactory , // note that this requires a special factory type
93
- } ;
94
-
95
- const STATE_EVENT_TILE_TYPES : FactoryMap = {
96
- [ EventType . RoomEncryption ] : ( ref , props ) => < EncryptionEvent ref = { ref } { ...props } /> ,
97
- [ EventType . RoomCanonicalAlias ] : TextualEventFactory ,
98
- [ EventType . RoomCreate ] : ( ref , props ) => < RoomCreate ref = { ref } { ...props } /> ,
99
- [ EventType . RoomMember ] : TextualEventFactory ,
100
- [ EventType . RoomName ] : TextualEventFactory ,
101
- [ EventType . RoomAvatar ] : ( ref , props ) => < RoomAvatarEvent ref = { ref } { ...props } /> ,
102
- [ EventType . RoomThirdPartyInvite ] : TextualEventFactory ,
103
- [ EventType . RoomHistoryVisibility ] : TextualEventFactory ,
104
- [ EventType . RoomTopic ] : TextualEventFactory ,
105
- [ EventType . RoomPowerLevels ] : TextualEventFactory ,
106
- [ EventType . RoomPinnedEvents ] : TextualEventFactory ,
107
- [ EventType . RoomServerAcl ] : TextualEventFactory ,
84
+ const EVENT_TILE_TYPES = new Map < string , Factory > ( [
85
+ [ EventType . RoomMessage , MessageEventFactory ] , // note that verification requests are handled in pickFactory()
86
+ [ EventType . Sticker , MessageEventFactory ] ,
87
+ [ M_POLL_START . name , MessageEventFactory ] ,
88
+ [ M_POLL_START . altName , MessageEventFactory ] ,
89
+ [ EventType . KeyVerificationCancel , KeyVerificationConclFactory ] ,
90
+ [ EventType . KeyVerificationDone , KeyVerificationConclFactory ] ,
91
+ [ EventType . CallInvite , CallEventFactory ] , // note that this requires a special factory type
92
+ ] ) ;
93
+
94
+ const STATE_EVENT_TILE_TYPES = new Map < string , Factory > ( [
95
+ [ EventType . RoomEncryption , ( ref , props ) => < EncryptionEvent ref = { ref } { ...props } /> ] ,
96
+ [ EventType . RoomCanonicalAlias , TextualEventFactory ] ,
97
+ [ EventType . RoomCreate , ( ref , props ) => < RoomCreate ref = { ref } { ...props } /> ] ,
98
+ [ EventType . RoomMember , TextualEventFactory ] ,
99
+ [ EventType . RoomName , TextualEventFactory ] ,
100
+ [ EventType . RoomAvatar , ( ref , props ) => < RoomAvatarEvent ref = { ref } { ...props } /> ] ,
101
+ [ EventType . RoomThirdPartyInvite , TextualEventFactory ] ,
102
+ [ EventType . RoomHistoryVisibility , TextualEventFactory ] ,
103
+ [ EventType . RoomTopic , TextualEventFactory ] ,
104
+ [ EventType . RoomPowerLevels , TextualEventFactory ] ,
105
+ [ EventType . RoomPinnedEvents , TextualEventFactory ] ,
106
+ [ EventType . RoomServerAcl , TextualEventFactory ] ,
108
107
// TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111)
109
- 'im.vector.modular.widgets' : TextualEventFactory , // note that Jitsi widgets are special in pickFactory()
110
- [ WIDGET_LAYOUT_EVENT_TYPE ] : TextualEventFactory ,
111
- [ EventType . RoomTombstone ] : TextualEventFactory ,
112
- [ EventType . RoomJoinRules ] : TextualEventFactory ,
113
- [ EventType . RoomGuestAccess ] : TextualEventFactory ,
114
- } ;
108
+ [ 'im.vector.modular.widgets' , TextualEventFactory ] , // note that Jitsi widgets are special in pickFactory()
109
+ [ WIDGET_LAYOUT_EVENT_TYPE , TextualEventFactory ] ,
110
+ [ EventType . RoomTombstone , TextualEventFactory ] ,
111
+ [ EventType . RoomJoinRules , TextualEventFactory ] ,
112
+ [ EventType . RoomGuestAccess , TextualEventFactory ] ,
113
+ ] ) ;
115
114
116
115
// Add all the Mjolnir stuff to the renderer too
117
116
for ( const evType of ALL_RULE_TYPES ) {
118
- STATE_EVENT_TILE_TYPES [ evType ] = TextualEventFactory ;
117
+ STATE_EVENT_TILE_TYPES . set ( evType , TextualEventFactory ) ;
119
118
}
120
119
121
120
// These events should be recorded in the STATE_EVENT_TILE_TYPES
@@ -225,11 +224,11 @@ export function pickFactory(
225
224
return noEventFactoryFactory ( ) ; // improper event type to render
226
225
}
227
226
228
- if ( STATE_EVENT_TILE_TYPES [ evType ] === TextualEventFactory && ! hasText ( mxEvent , showHiddenEvents ) ) {
227
+ if ( STATE_EVENT_TILE_TYPES . get ( evType ) === TextualEventFactory && ! hasText ( mxEvent , showHiddenEvents ) ) {
229
228
return noEventFactoryFactory ( ) ;
230
229
}
231
230
232
- return STATE_EVENT_TILE_TYPES [ evType ] ?? noEventFactoryFactory ( ) ;
231
+ return STATE_EVENT_TILE_TYPES . get ( evType ) ?? noEventFactoryFactory ( ) ;
233
232
}
234
233
235
234
// Blanket override for all events. The MessageEvent component handles redacted states for us.
@@ -241,7 +240,7 @@ export function pickFactory(
241
240
return noEventFactoryFactory ( ) ;
242
241
}
243
242
244
- return EVENT_TILE_TYPES [ evType ] ?? noEventFactoryFactory ( ) ;
243
+ return EVENT_TILE_TYPES . get ( evType ) ?? noEventFactoryFactory ( ) ;
245
244
}
246
245
247
246
/**
@@ -391,7 +390,7 @@ export function haveRendererForEvent(mxEvent: MatrixEvent, showHiddenEvents: boo
391
390
if ( ! handler ) return false ;
392
391
if ( handler === TextualEventFactory ) {
393
392
return hasText ( mxEvent , showHiddenEvents ) ;
394
- } else if ( handler === STATE_EVENT_TILE_TYPES [ EventType . RoomCreate ] ) {
393
+ } else if ( handler === STATE_EVENT_TILE_TYPES . get ( EventType . RoomCreate ) ) {
395
394
return Boolean ( mxEvent . getContent ( ) [ 'predecessor' ] ) ;
396
395
} else if ( handler === JSONEventFactory ) {
397
396
return false ;
0 commit comments