You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-09 10:22:46 +03:00
Add ability to choose how many timeline events to sync when peeking (#4300)
* Add ability to choose how many timeline events to sync when peeking. * Add a test that covers the new method parameter. * Formatting. --------- Co-authored-by: Joel <joel.garplind+github@gmail.com>
This commit is contained in:
@@ -2281,7 +2281,9 @@ describe("MatrixClient syncing", () => {
|
||||
httpBackend!.expectedRequests = [];
|
||||
});
|
||||
|
||||
it("should return a room based on the room initialSync API", async () => {
|
||||
it.each([undefined, 100])(
|
||||
"should return a room based on the room initialSync API with limit %s",
|
||||
async (limit) => {
|
||||
httpBackend!.when("GET", `/rooms/${encodeURIComponent(roomOne)}/initialSync`).respond(200, {
|
||||
room_id: roomOne,
|
||||
membership: KnownMembership.Leave,
|
||||
@@ -2328,7 +2330,7 @@ describe("MatrixClient syncing", () => {
|
||||
});
|
||||
httpBackend!.when("GET", "/events").respond(200, { chunk: [] });
|
||||
|
||||
const prom = client!.peekInRoom(roomOne);
|
||||
const prom = client!.peekInRoom(roomOne, limit);
|
||||
await httpBackend!.flushAllExpected();
|
||||
const room = await prom;
|
||||
|
||||
@@ -2341,7 +2343,8 @@ describe("MatrixClient syncing", () => {
|
||||
client?.stopPeeking();
|
||||
httpBackend!.when("GET", "/events").respond(200, { chunk: [] });
|
||||
await httpBackend!.flushAllExpected();
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("user account data", () => {
|
||||
|
@@ -6603,13 +6603,14 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* Peek into a room and receive updates about the room. This only works if the
|
||||
* history visibility for the room is world_readable.
|
||||
* @param roomId - The room to attempt to peek into.
|
||||
* @param limit - The number of timeline events to initially retrieve.
|
||||
* @returns Promise which resolves: Room object
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public peekInRoom(roomId: string): Promise<Room> {
|
||||
public peekInRoom(roomId: string, limit: number = 20): Promise<Room> {
|
||||
this.peekSync?.stopPeeking();
|
||||
this.peekSync = new SyncApi(this, this.clientOpts, this.buildSyncApiOptions());
|
||||
return this.peekSync.peek(roomId);
|
||||
return this.peekSync.peek(roomId, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -401,17 +401,18 @@ export class SyncApi {
|
||||
* Peek into a room. This will result in the room in question being synced so it
|
||||
* is accessible via getRooms(). Live updates for the room will be provided.
|
||||
* @param roomId - The room ID to peek into.
|
||||
* @param limit - The number of timeline events to initially retrieve.
|
||||
* @returns A promise which resolves once the room has been added to the
|
||||
* store.
|
||||
*/
|
||||
public peek(roomId: string): Promise<Room> {
|
||||
public peek(roomId: string, limit: number = 20): Promise<Room> {
|
||||
if (this._peekRoom?.roomId === roomId) {
|
||||
return Promise.resolve(this._peekRoom);
|
||||
}
|
||||
|
||||
const client = this.client;
|
||||
this._peekRoom = this.createRoom(roomId);
|
||||
return this.client.roomInitialSync(roomId, 20).then((response) => {
|
||||
return this.client.roomInitialSync(roomId, limit).then((response) => {
|
||||
if (this._peekRoom?.roomId !== roomId) {
|
||||
throw new Error("Peeking aborted");
|
||||
}
|
||||
|
Reference in New Issue
Block a user