Skip to content

Commit ee78ba3

Browse files
committed
fixes for reading room state
1 parent ad0cb68 commit ee78ba3

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/ClientWidgetApi.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -530,18 +530,24 @@ export class ClientWidgetApi extends EventEmitter {
530530
// For backwards compatibility we still call the deprecated
531531
// readRoomEvents and readStateEvents methods in case the client isn't
532532
// letting us know the currently viewed room via setViewedRoomId
533-
const events =
534-
request.data.room_ids === undefined && askRoomIds.length === 0
535-
? await (request.data.state_key === undefined
536-
? this.driver.readRoomEvents(request.data.type, msgtype, limit, null, since)
537-
: this.driver.readStateEvents(request.data.type, stateKey, limit, null))
538-
: (
539-
await Promise.all(
540-
askRoomIds.map((roomId) =>
541-
this.driver.readRoomTimeline(roomId, request.data.type, msgtype, stateKey, limit, since),
542-
),
543-
)
544-
).flat(1);
533+
const events = request.data.room_ids === undefined && askRoomIds.length === 0
534+
? await (
535+
// This returns [] with the current driver of Element Web.
536+
// Add default implementations of the `readRoomEvents` and `readStateEvents`
537+
// methods to use `readRoomTimeline` and `readRoomState` if they are not overwritten.
538+
request.data.state_key === undefined
539+
? this.driver.readRoomEvents(request.data.type, msgtype, limit, null, since)
540+
: this.driver.readStateEvents(request.data.type, stateKey, limit, null)
541+
)
542+
: (
543+
request.data.state_key === undefined
544+
? await Promise.all(askRoomIds.map(roomId =>
545+
this.driver.readRoomTimeline(roomId, request.data.type, msgtype, stateKey, limit, since),
546+
))
547+
: await Promise.all(askRoomIds.map(roomId =>
548+
this.driver.readRoomState(roomId, request.data.type, stateKey),
549+
))
550+
).flat(1);
545551
this.transport.reply<IReadEventFromWidgetResponseData>(request, { events });
546552
}
547553

0 commit comments

Comments
 (0)