From 212efe823c6ab01df14da89e72b04e1bfca79866 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 9 Sep 2020 09:50:03 +0200 Subject: [PATCH] fix memberlist not containing all members we were using the prev_batch of the last sync to pass to /members, but this points at the timeline *before* the last sync, so wouldn't contain all members. Use the sync token instead. --- src/matrix/Session.js | 4 +++- src/matrix/room/Room.js | 4 +++- src/matrix/room/RoomSummary.js | 15 +++------------ src/matrix/room/members/load.js | 4 ++-- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index b4cbf3b2..19725b58 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -51,12 +51,13 @@ export class Session { this._olmEncryption = null; this._megolmEncryption = null; this._megolmDecryption = null; + this._getSyncToken = () => this.syncToken; if (olm) { this._olmUtil = new olm.Utility(); this._deviceTracker = new DeviceTracker({ storage, - getSyncToken: () => this.syncToken, + getSyncToken: this._getSyncToken, olmUtil: this._olmUtil, ownUserId: sessionInfo.userId, ownDeviceId: sessionInfo.deviceId, @@ -241,6 +242,7 @@ export class Session { createRoom(roomId, pendingEvents) { const room = new Room({ roomId, + getSyncToken: this._getSyncToken, storage: this._storage, emitCollectionChange: this._roomUpdateCallback, hsApi: this._hsApi, diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index daec1dd6..b8454df7 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -28,7 +28,7 @@ import {Heroes} from "./members/Heroes.js"; import {EventEntry} from "./timeline/entries/EventEntry.js"; export class Room extends EventEmitter { - constructor({roomId, storage, hsApi, emitCollectionChange, sendScheduler, pendingEvents, user, createRoomEncryption}) { + constructor({roomId, storage, hsApi, emitCollectionChange, sendScheduler, pendingEvents, user, createRoomEncryption, getSyncToken}) { super(); this._roomId = roomId; this._storage = storage; @@ -44,6 +44,7 @@ export class Room extends EventEmitter { this._memberList = null; this._createRoomEncryption = createRoomEncryption; this._roomEncryption = null; + this._getSyncToken = getSyncToken; } async notifyRoomKeys(roomKeys) { @@ -270,6 +271,7 @@ export class Room extends EventEmitter { roomId: this._roomId, hsApi: this._hsApi, storage: this._storage, + syncToken: this._getSyncToken(), // to handle race between /members and /sync setChangedMembersMap: map => this._changedMembersDuringSync = map, }); diff --git a/src/matrix/room/RoomSummary.js b/src/matrix/room/RoomSummary.js index 3b550527..270fa690 100644 --- a/src/matrix/room/RoomSummary.js +++ b/src/matrix/room/RoomSummary.js @@ -31,12 +31,8 @@ function applySyncResponse(data, roomResponse, membership, isInitialSync, isTime if (roomResponse.state) { data = roomResponse.state.events.reduce(processStateEvent, data); } - if (roomResponse.timeline) { - const {timeline} = roomResponse; - if (timeline.prev_batch) { - data = data.cloneIfNeeded(); - data.lastPaginationToken = timeline.prev_batch; - } + const {timeline} = roomResponse; + if (timeline && Array.isArray(timeline.events)) { data = timeline.events.reduce((data, event) => { if (typeof event.state_key === "string") { return processStateEvent(data, event); @@ -150,7 +146,6 @@ class SummaryData { this.canonicalAlias = copy ? copy.canonicalAlias : null; this.hasFetchedMembers = copy ? copy.hasFetchedMembers : false; this.isTrackingMembers = copy ? copy.isTrackingMembers : false; - this.lastPaginationToken = copy ? copy.lastPaginationToken : null; this.avatarUrl = copy ? copy.avatarUrl : null; this.notificationCount = copy ? copy.notificationCount : 0; this.highlightCount = copy ? copy.highlightCount : 0; @@ -244,11 +239,7 @@ export class RoomSummary { get isTrackingMembers() { return this._data.isTrackingMembers; } - - get lastPaginationToken() { - return this._data.lastPaginationToken; - } - + get tags() { return this._data.tags; } diff --git a/src/matrix/room/members/load.js b/src/matrix/room/members/load.js index 667bec96..18fc4eb4 100644 --- a/src/matrix/room/members/load.js +++ b/src/matrix/room/members/load.js @@ -25,13 +25,13 @@ async function loadMembers({roomId, storage}) { return memberDatas.map(d => new RoomMember(d)); } -async function fetchMembers({summary, roomId, hsApi, storage, setChangedMembersMap}) { +async function fetchMembers({summary, syncToken, roomId, hsApi, storage, setChangedMembersMap}) { // if any members are changed by sync while we're fetching members, // they will end up here, so we check not to override them const changedMembersDuringSync = new Map(); setChangedMembersMap(changedMembersDuringSync); - const memberResponse = await hsApi.members(roomId, {at: summary.lastPaginationToken}).response(); + const memberResponse = await hsApi.members(roomId, {at: syncToken}).response(); const txn = await storage.readWriteTxn([ storage.storeNames.roomSummary,