From 67462e9fc43aa05c2d89f470e9161d21c1642cba Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 25 Jun 2019 14:51:25 +0200 Subject: [PATCH] support paginating relations --- src/base-apis.js | 12 +++++++++--- src/client.js | 14 +++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/base-apis.js b/src/base-apis.js index d8b51dcdd..a495efe07 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -440,14 +440,20 @@ MatrixBaseApis.prototype.createRoom = function(options, callback) { }; MatrixBaseApis.prototype.fetchRelations = - async function(roomId, eventId, relationType, eventType) { + async function(roomId, eventId, relationType, eventType, opts) { + const queryParams = {}; + if (opts.token) { + queryParams.from = opts.token; + } + const queryString = utils.encodeParams(queryParams); // valid options include: room_alias_name, visibility, invite const response = await this._http.authedRequestWithPrefix( undefined, - "GET", `/rooms/${roomId}/relations/${eventId}/${relationType}/${eventType}`, + "GET", + `/rooms/${roomId}/relations/${eventId}/${relationType}/${eventType}?` + queryString, null, null, httpApi.PREFIX_UNSTABLE, ); - return response.chunk; + return response; }; /** diff --git a/src/client.js b/src/client.js index c6113bea7..1f0f43266 100644 --- a/src/client.js +++ b/src/client.js @@ -3966,9 +3966,17 @@ MatrixClient.prototype.getCanResetTimelineCallback = function() { }; MatrixClient.prototype.relations = -async function(roomId, eventId, relationType, eventType) { - const events = await this.fetchRelations(roomId, eventId, relationType, eventType); - return events.map(this.getEventMapper()); +async function(roomId, eventId, relationType, eventType, opts = {}) { + const result = await this.fetchRelations( + roomId, + eventId, + relationType, + eventType, + opts); + return { + events: result.chunk.map(this.getEventMapper()), + nextBatch: result.next_batch, + }; }; function setupCallEventHandler(client) {