forked from mystiq/hydrogen-web
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:
parent
1f9d6191c2
commit
212efe823c
4 changed files with 11 additions and 16 deletions
|
@ -51,12 +51,13 @@ export class Session {
|
||||||
this._olmEncryption = null;
|
this._olmEncryption = null;
|
||||||
this._megolmEncryption = null;
|
this._megolmEncryption = null;
|
||||||
this._megolmDecryption = null;
|
this._megolmDecryption = null;
|
||||||
|
this._getSyncToken = () => this.syncToken;
|
||||||
|
|
||||||
if (olm) {
|
if (olm) {
|
||||||
this._olmUtil = new olm.Utility();
|
this._olmUtil = new olm.Utility();
|
||||||
this._deviceTracker = new DeviceTracker({
|
this._deviceTracker = new DeviceTracker({
|
||||||
storage,
|
storage,
|
||||||
getSyncToken: () => this.syncToken,
|
getSyncToken: this._getSyncToken,
|
||||||
olmUtil: this._olmUtil,
|
olmUtil: this._olmUtil,
|
||||||
ownUserId: sessionInfo.userId,
|
ownUserId: sessionInfo.userId,
|
||||||
ownDeviceId: sessionInfo.deviceId,
|
ownDeviceId: sessionInfo.deviceId,
|
||||||
|
@ -241,6 +242,7 @@ export class Session {
|
||||||
createRoom(roomId, pendingEvents) {
|
createRoom(roomId, pendingEvents) {
|
||||||
const room = new Room({
|
const room = new Room({
|
||||||
roomId,
|
roomId,
|
||||||
|
getSyncToken: this._getSyncToken,
|
||||||
storage: this._storage,
|
storage: this._storage,
|
||||||
emitCollectionChange: this._roomUpdateCallback,
|
emitCollectionChange: this._roomUpdateCallback,
|
||||||
hsApi: this._hsApi,
|
hsApi: this._hsApi,
|
||||||
|
|
|
@ -28,7 +28,7 @@ import {Heroes} from "./members/Heroes.js";
|
||||||
import {EventEntry} from "./timeline/entries/EventEntry.js";
|
import {EventEntry} from "./timeline/entries/EventEntry.js";
|
||||||
|
|
||||||
export class Room extends EventEmitter {
|
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();
|
super();
|
||||||
this._roomId = roomId;
|
this._roomId = roomId;
|
||||||
this._storage = storage;
|
this._storage = storage;
|
||||||
|
@ -44,6 +44,7 @@ export class Room extends EventEmitter {
|
||||||
this._memberList = null;
|
this._memberList = null;
|
||||||
this._createRoomEncryption = createRoomEncryption;
|
this._createRoomEncryption = createRoomEncryption;
|
||||||
this._roomEncryption = null;
|
this._roomEncryption = null;
|
||||||
|
this._getSyncToken = getSyncToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
async notifyRoomKeys(roomKeys) {
|
async notifyRoomKeys(roomKeys) {
|
||||||
|
@ -270,6 +271,7 @@ export class Room extends EventEmitter {
|
||||||
roomId: this._roomId,
|
roomId: this._roomId,
|
||||||
hsApi: this._hsApi,
|
hsApi: this._hsApi,
|
||||||
storage: this._storage,
|
storage: this._storage,
|
||||||
|
syncToken: this._getSyncToken(),
|
||||||
// to handle race between /members and /sync
|
// to handle race between /members and /sync
|
||||||
setChangedMembersMap: map => this._changedMembersDuringSync = map,
|
setChangedMembersMap: map => this._changedMembersDuringSync = map,
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,12 +31,8 @@ function applySyncResponse(data, roomResponse, membership, isInitialSync, isTime
|
||||||
if (roomResponse.state) {
|
if (roomResponse.state) {
|
||||||
data = roomResponse.state.events.reduce(processStateEvent, data);
|
data = roomResponse.state.events.reduce(processStateEvent, data);
|
||||||
}
|
}
|
||||||
if (roomResponse.timeline) {
|
const {timeline} = roomResponse;
|
||||||
const {timeline} = roomResponse;
|
if (timeline && Array.isArray(timeline.events)) {
|
||||||
if (timeline.prev_batch) {
|
|
||||||
data = data.cloneIfNeeded();
|
|
||||||
data.lastPaginationToken = timeline.prev_batch;
|
|
||||||
}
|
|
||||||
data = timeline.events.reduce((data, event) => {
|
data = timeline.events.reduce((data, event) => {
|
||||||
if (typeof event.state_key === "string") {
|
if (typeof event.state_key === "string") {
|
||||||
return processStateEvent(data, event);
|
return processStateEvent(data, event);
|
||||||
|
@ -150,7 +146,6 @@ class SummaryData {
|
||||||
this.canonicalAlias = copy ? copy.canonicalAlias : null;
|
this.canonicalAlias = copy ? copy.canonicalAlias : null;
|
||||||
this.hasFetchedMembers = copy ? copy.hasFetchedMembers : false;
|
this.hasFetchedMembers = copy ? copy.hasFetchedMembers : false;
|
||||||
this.isTrackingMembers = copy ? copy.isTrackingMembers : false;
|
this.isTrackingMembers = copy ? copy.isTrackingMembers : false;
|
||||||
this.lastPaginationToken = copy ? copy.lastPaginationToken : null;
|
|
||||||
this.avatarUrl = copy ? copy.avatarUrl : null;
|
this.avatarUrl = copy ? copy.avatarUrl : null;
|
||||||
this.notificationCount = copy ? copy.notificationCount : 0;
|
this.notificationCount = copy ? copy.notificationCount : 0;
|
||||||
this.highlightCount = copy ? copy.highlightCount : 0;
|
this.highlightCount = copy ? copy.highlightCount : 0;
|
||||||
|
@ -245,10 +240,6 @@ export class RoomSummary {
|
||||||
return this._data.isTrackingMembers;
|
return this._data.isTrackingMembers;
|
||||||
}
|
}
|
||||||
|
|
||||||
get lastPaginationToken() {
|
|
||||||
return this._data.lastPaginationToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
get tags() {
|
get tags() {
|
||||||
return this._data.tags;
|
return this._data.tags;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,13 @@ async function loadMembers({roomId, storage}) {
|
||||||
return memberDatas.map(d => new RoomMember(d));
|
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,
|
// if any members are changed by sync while we're fetching members,
|
||||||
// they will end up here, so we check not to override them
|
// they will end up here, so we check not to override them
|
||||||
const changedMembersDuringSync = new Map();
|
const changedMembersDuringSync = new Map();
|
||||||
setChangedMembersMap(changedMembersDuringSync);
|
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([
|
const txn = await storage.readWriteTxn([
|
||||||
storage.storeNames.roomSummary,
|
storage.storeNames.roomSummary,
|
||||||
|
|
Loading…
Reference in a new issue