From f12499c6bfe47d9527bdcbd8b4bc212ea46aedf9 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 5 Jan 2016 13:24:51 +0000 Subject: [PATCH] Support guest room filters --- lib/sync.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/sync.js b/lib/sync.js index ff4e8ba9d..10b68ffc4 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -190,8 +190,8 @@ SyncApi.prototype.sync = function() { } if (client.isGuest()) { - // no push rules for guests - getFilter(); + // no push rules for guests, no access to POST filter for guests. + self._sync({}); } else { getPushRules(); @@ -210,8 +210,13 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { var self = this; attempt = attempt || 1; + var filterId = syncOptions.filterId; + if (client.isGuest() && !filterId) { + filterId = this._getGuestFilter(); + } + var qps = { - filter: syncOptions.filterId, + filter: filterId, timeout: this.opts.pollTimeout, since: client.store.getSyncToken() || undefined // do not send 'null' }; @@ -223,10 +228,6 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { qps.timeout = 1; } - if (client._guestRooms && client._isGuest) { - qps.room_id = client._guestRooms; - } - client._http.authedRequestWithPrefix( undefined, "GET", "/sync", qps, undefined, httpApi.PREFIX_V2_ALPHA, this.opts.pollTimeout + BUFFER_PERIOD_MS // normal timeout= plus buffer time @@ -543,7 +544,18 @@ SyncApi.prototype._processRoomEvents = function(room, stateEventList, // execute the timeline events, this will begin to diverge the current state // if the timeline has any state events in it. room.addEventsToTimeline(timelineEventList); +}; +SyncApi.prototype._getGuestFilter = function() { + var guestRooms = this.client._guestRooms; // FIXME: horrible gut-wrenching + if (!guestRooms) { + return "{}"; + } + return JSON.stringify({ + room: { + rooms: guestRooms + } + }); }; function retryTimeMsForAttempt(attempt) {