1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

Handle device change notifications from /sync

When we get a notification from /sync that a user has updated their device
list, mark the list outdated, and then fire off a device query.
This commit is contained in:
Richard van der Hoff
2017-02-01 14:01:41 +00:00
parent 7e82ac3620
commit 89ef4aa6e7
5 changed files with 89 additions and 26 deletions

View File

@@ -55,8 +55,6 @@ function Crypto(baseApis, eventEmitter, sessionStore, userId, deviceId) {
this._userId = userId;
this._deviceId = deviceId;
this._initialSyncCompleted = false;
this._olmDevice = new OlmDevice(sessionStore);
this._deviceList = new DeviceList(baseApis, sessionStore, this._olmDevice);
@@ -115,6 +113,9 @@ function _registerEventHandlers(crypto, eventEmitter) {
const rooms = eventEmitter.getRooms();
crypto._onInitialSyncCompleted(rooms);
}
if (syncState === "SYNCING") {
crypto._onSyncCompleted(data);
}
} catch (e) {
console.error("Error handling sync", e);
}
@@ -689,6 +690,18 @@ Crypto.prototype.decryptEvent = function(event) {
alg.decryptEvent(event);
};
/**
* Handle the notification from /sync that a user has updated their device list.
*
* @param {String} userId
*/
Crypto.prototype.userDeviceListChanged = function(userId) {
this._deviceList.invalidateUserDeviceList(userId);
// don't flush the outdated device list yet - we do it once we finish
// processing the sync.
};
/**
* handle an m.room.encryption event
*
@@ -716,11 +729,6 @@ Crypto.prototype._onCryptoEvent = function(event) {
* @param {module:models/room[]} rooms list of rooms the client knows about
*/
Crypto.prototype._onInitialSyncCompleted = function(rooms) {
this._initialSyncCompleted = true;
// catch up on any m.new_device events which arrived during the initial sync.
this._deviceList.refreshOutdatedDeviceLists().done();
if (this._sessionStore.getDeviceAnnounced()) {
return;
}
@@ -779,6 +787,12 @@ Crypto.prototype._onInitialSyncCompleted = function(rooms) {
});
};
Crypto.prototype._onSyncCompleted = function(syncData) {
// catch up on any new devices we got told about during the sync.
this._deviceList.lastKnownSyncToken = syncData.nextSyncToken;
this._deviceList.refreshOutdatedDeviceLists().done();
};
/**
* Handle a key event
*
@@ -852,12 +866,6 @@ Crypto.prototype._onNewDeviceEvent = function(event) {
}
this._deviceList.invalidateUserDeviceList(userId);
// we delay handling these until the intialsync has completed, so that we
// can do all of them together.
if (this._initialSyncCompleted) {
this._deviceList.refreshOutdatedDeviceLists().done();
}
};