From 52149ce74a15df358601bb9c8c532cf2b4b5d490 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 2 Aug 2018 19:37:06 +0200 Subject: [PATCH] Move LL filter creation inside MatrixClient As we need an option to turn lazy loading on (we can't just accept a filter, as /messages has an incompatible filter), better only pass the option and create the filter inside startClient --- src/client.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/client.js b/src/client.js index 2361770ca..9d4e96c83 100644 --- a/src/client.js +++ b/src/client.js @@ -45,6 +45,18 @@ const ContentHelpers = require("./content-helpers"); import ReEmitter from './ReEmitter'; import RoomList from './crypto/RoomList'; + +const LAZY_LOADING_MESSAGES_FILTER = { + lazy_load_members: true, +}; + +const LAZY_LOADING_SYNC_FILTER = { + room: { + state: LAZY_LOADING_MESSAGES_FILTER, + }, +}; + + const SCROLLBACK_DELAY_MS = 3000; let CRYPTO_ENABLED = false; @@ -2115,7 +2127,7 @@ MatrixClient.prototype._createMessagesRequest = function(roomId, fromToken, limi let filter = null; if (this._clientOpts.lazyLoadMembers) { - filter = {lazy_load_members: true}; + filter = LAZY_LOADING_MESSAGES_FILTER; } if (timelineFilter) { // XXX: it's horrific that /messages' filter parameter doesn't match @@ -3041,8 +3053,9 @@ MatrixClient.prototype.getTurnServers = function() { * updating presence. * @param {Boolean=} opts.lazyLoadMembers True to not load all membership events during * initial sync but fetch them when needed by calling `loadOutOfBandMembers` + * This will override the filter option at this moment. */ -MatrixClient.prototype.startClient = function(opts) { +MatrixClient.prototype.startClient = async function(opts) { if (this.clientRunning) { // client is already running. return; @@ -3072,6 +3085,10 @@ MatrixClient.prototype.startClient = function(opts) { // shallow-copy the opts dict before modifying and storing it opts = Object.assign({}, opts); + if (opts.lazyLoadMembers) { + opts.filter = await this.createFilter(LAZY_LOADING_SYNC_FILTER); + } + opts.crypto = this._crypto; opts.canResetEntireTimeline = (roomId) => { if (!this._canResetTimelineCallback) {