hook up device tracker with sync
This commit is contained in:
parent
8b358379e8
commit
afb9ae4391
2 changed files with 19 additions and 2 deletions
|
@ -19,6 +19,7 @@ import { ObservableMap } from "../observable/index.js";
|
|||
import { SendScheduler, RateLimitingBackoff } from "./SendScheduler.js";
|
||||
import {User} from "./User.js";
|
||||
import {Account as E2EEAccount} from "./e2ee/Account.js";
|
||||
import {DeviceTracker} from "./e2ee/DeviceTracker.js";
|
||||
const PICKLE_KEY = "DEFAULT_KEY";
|
||||
|
||||
export class Session {
|
||||
|
@ -34,6 +35,11 @@ export class Session {
|
|||
this._user = new User(sessionInfo.userId);
|
||||
this._olm = olm;
|
||||
this._e2eeAccount = null;
|
||||
this._deviceTracker = olm ? new DeviceTracker({
|
||||
storage,
|
||||
getSyncToken: () => this.syncToken,
|
||||
olm,
|
||||
}) : null;
|
||||
}
|
||||
|
||||
async beforeFirstSync(isNewLogin) {
|
||||
|
@ -152,7 +158,7 @@ export class Session {
|
|||
return room;
|
||||
}
|
||||
|
||||
writeSync(syncResponse, syncFilterId, txn) {
|
||||
async writeSync(syncResponse, syncFilterId, roomChanges, txn) {
|
||||
const changes = {};
|
||||
const syncToken = syncResponse.next_batch;
|
||||
const deviceOneTimeKeysCount = syncResponse.device_one_time_keys_count;
|
||||
|
@ -166,6 +172,17 @@ export class Session {
|
|||
txn.session.set("sync", syncInfo);
|
||||
changes.syncInfo = syncInfo;
|
||||
}
|
||||
if (this._deviceTracker) {
|
||||
const deviceLists = syncResponse.device_lists;
|
||||
if (deviceLists) {
|
||||
await this._deviceTracker.writeDeviceChanges(deviceLists, txn);
|
||||
}
|
||||
for (const {room, changes} of roomChanges) {
|
||||
if (room.isTrackingMembers && changes.memberChanges?.size) {
|
||||
await this._deviceTracker.writeMemberChanges(room, changes.memberChanges, txn);
|
||||
}
|
||||
}
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,6 @@ export class Sync {
|
|||
const roomChanges = [];
|
||||
let sessionChanges;
|
||||
try {
|
||||
sessionChanges = this._session.writeSync(response, syncFilterId, syncTxn);
|
||||
// to_device
|
||||
// presence
|
||||
if (response.rooms) {
|
||||
|
@ -153,6 +152,7 @@ export class Sync {
|
|||
});
|
||||
await Promise.all(promises);
|
||||
}
|
||||
sessionChanges = await this._session.writeSync(response, syncFilterId, roomChanges, syncTxn);
|
||||
} catch(err) {
|
||||
console.warn("aborting syncTxn because of error");
|
||||
console.error(err);
|
||||
|
|
Reference in a new issue