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.
This commit is contained in:
Bruno Windels 2020-09-09 09:50:03 +02:00
parent 1f9d6191c2
commit 212efe823c
4 changed files with 11 additions and 16 deletions

View file

@ -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,

View file

@ -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,
});

View file

@ -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;
}

View file

@ -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,