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

Commit 99f1445

Browse files
committed
Re-add wrapped factory pattern to save bunch of SettingsStore calls
1 parent 375b477 commit 99f1445

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/events/EventTileFactory.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export function pickFactory(mxEvent: MatrixEvent, cli: MatrixClient, asHiddenEv?
153153
return JSONEventFactory;
154154
}
155155

156-
const noEventFactory: Optional<Factory> = SettingsStore.getValue("showHiddenEventsInTimeline")
156+
const noEventFactoryFactory: (() => Optional<Factory>) = () => SettingsStore.getValue("showHiddenEventsInTimeline")
157157
? JSONEventFactory
158158
: undefined; // just don't render things that we shouldn't render
159159

@@ -171,7 +171,7 @@ export function pickFactory(mxEvent: MatrixEvent, cli: MatrixClient, asHiddenEv?
171171
if (content?.msgtype === MsgType.KeyVerificationRequest) {
172172
const me = cli.getUserId();
173173
if (mxEvent.getSender() !== me && content['to'] !== me) {
174-
return noEventFactory; // not for/from us
174+
return noEventFactoryFactory(); // not for/from us
175175
} else {
176176
// override the factory
177177
return VerificationReqFactory;
@@ -182,7 +182,7 @@ export function pickFactory(mxEvent: MatrixEvent, cli: MatrixClient, asHiddenEv?
182182
// tile once the verification concludes, so filter out the one from the other party.
183183
const me = cli.getUserId();
184184
if (mxEvent.getSender() !== me) {
185-
return noEventFactory;
185+
return noEventFactoryFactory();
186186
}
187187
}
188188

@@ -192,7 +192,7 @@ export function pickFactory(mxEvent: MatrixEvent, cli: MatrixClient, asHiddenEv?
192192
// XXX: This is extremely a hack. Possibly these components should have an interface for
193193
// declining to render?
194194
if (!MKeyVerificationConclusion.shouldRender(mxEvent, mxEvent.verificationRequest)) {
195-
return noEventFactory;
195+
return noEventFactoryFactory();
196196
}
197197
}
198198

@@ -220,10 +220,10 @@ export function pickFactory(mxEvent: MatrixEvent, cli: MatrixClient, asHiddenEv?
220220
}
221221

222222
if (SINGULAR_STATE_EVENTS.has(evType) && mxEvent.getStateKey() !== '') {
223-
return noEventFactory; // improper event type to render
223+
return noEventFactoryFactory(); // improper event type to render
224224
}
225225

226-
return STATE_EVENT_TILE_TYPES[evType] ?? noEventFactory;
226+
return STATE_EVENT_TILE_TYPES[evType] ?? noEventFactoryFactory();
227227
}
228228

229229
// Blanket override for all events. The MessageEvent component handles redacted states for us.
@@ -232,10 +232,10 @@ export function pickFactory(mxEvent: MatrixEvent, cli: MatrixClient, asHiddenEv?
232232
}
233233

234234
if (mxEvent.isRelation(RelationType.Replace)) {
235-
return noEventFactory;
235+
return noEventFactoryFactory();
236236
}
237237

238-
return EVENT_TILE_TYPES[evType] ?? noEventFactory;
238+
return EVENT_TILE_TYPES[evType] ?? noEventFactoryFactory();
239239
}
240240

241241
/**

0 commit comments

Comments
 (0)