1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

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
This commit is contained in:
Bruno Windels
2018-08-02 19:37:06 +02:00
parent bffc20612d
commit 52149ce74a

View File

@@ -45,6 +45,18 @@ const ContentHelpers = require("./content-helpers");
import ReEmitter from './ReEmitter'; import ReEmitter from './ReEmitter';
import RoomList from './crypto/RoomList'; 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; const SCROLLBACK_DELAY_MS = 3000;
let CRYPTO_ENABLED = false; let CRYPTO_ENABLED = false;
@@ -2115,7 +2127,7 @@ MatrixClient.prototype._createMessagesRequest = function(roomId, fromToken, limi
let filter = null; let filter = null;
if (this._clientOpts.lazyLoadMembers) { if (this._clientOpts.lazyLoadMembers) {
filter = {lazy_load_members: true}; filter = LAZY_LOADING_MESSAGES_FILTER;
} }
if (timelineFilter) { if (timelineFilter) {
// XXX: it's horrific that /messages' filter parameter doesn't match // XXX: it's horrific that /messages' filter parameter doesn't match
@@ -3041,8 +3053,9 @@ MatrixClient.prototype.getTurnServers = function() {
* updating presence. * updating presence.
* @param {Boolean=} opts.lazyLoadMembers True to not load all membership events during * @param {Boolean=} opts.lazyLoadMembers True to not load all membership events during
* initial sync but fetch them when needed by calling `loadOutOfBandMembers` * 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) { if (this.clientRunning) {
// client is already running. // client is already running.
return; return;
@@ -3072,6 +3085,10 @@ MatrixClient.prototype.startClient = function(opts) {
// shallow-copy the opts dict before modifying and storing it // shallow-copy the opts dict before modifying and storing it
opts = Object.assign({}, opts); opts = Object.assign({}, opts);
if (opts.lazyLoadMembers) {
opts.filter = await this.createFilter(LAZY_LOADING_SYNC_FILTER);
}
opts.crypto = this._crypto; opts.crypto = this._crypto;
opts.canResetEntireTimeline = (roomId) => { opts.canResetEntireTimeline = (roomId) => {
if (!this._canResetTimelineCallback) { if (!this._canResetTimelineCallback) {