mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-02-19 15:42:05 +00:00
20 lines
640 B
TypeScript
20 lines
640 B
TypeScript
import type { EventTimeline, MatrixClient, MatrixEvent } from "matrix-js-sdk";
|
|
import { filter, map, of, startWith, type Observable } from "rxjs";
|
|
import { fromMatrixClientEvent } from "./events";
|
|
|
|
export function roomTimeline(
|
|
client: MatrixClient,
|
|
roomId: string | undefined,
|
|
): Observable<MatrixEvent[]> {
|
|
if (!roomId) return of([]);
|
|
const room = client.getRoom(roomId);
|
|
if (!room) return of([]);
|
|
const eventTimeline = room.getLiveTimeline();
|
|
|
|
return fromMatrixClientEvent(client, "Room.timeline").pipe(
|
|
filter(([, room]) => room?.roomId === roomId),
|
|
startWith([]),
|
|
map(() => eventTimeline.getEvents()),
|
|
);
|
|
}
|