1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +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

@@ -58,6 +58,7 @@ function debuglog() {
* @constructor
* @param {MatrixClient} client The matrix client instance to use.
* @param {Object} opts Config options
* @param {module:crypto=} opts.crypto Crypto manager
*/
function SyncApi(client, opts) {
this.client = client;
@@ -529,13 +530,18 @@ SyncApi.prototype._sync = function(syncOptions) {
}
// emit synced events
const syncEventData = {
oldSyncToken: syncToken,
nextSyncToken: data.next_batch,
};
if (!syncOptions.hasSyncedBefore) {
self._updateSyncState("PREPARED");
self._updateSyncState("PREPARED", syncEventData);
syncOptions.hasSyncedBefore = true;
}
// keep emitting SYNCING -> SYNCING for clients who want to do bulk updates
self._updateSyncState("SYNCING");
self._updateSyncState("SYNCING", syncEventData);
self._sync(syncOptions);
}, function(err) {
@@ -584,6 +590,7 @@ SyncApi.prototype._processSyncResponse = function(syncToken, data) {
// next_batch: $token,
// presence: { events: [] },
// account_data: { events: [] },
// device_lists: { changed: ["@user:server", ... ]},
// to_device: { events: [] },
// rooms: {
// invite: {
@@ -859,6 +866,13 @@ SyncApi.prototype._processSyncResponse = function(syncToken, data) {
client.getNotifTimelineSet().addLiveEvent(event);
});
}
// Handle device list updates
if (this.opts.crypto && data.device_lists && data.device_lists.changed) {
data.device_lists.changed.forEach((u) => {
this.opts.crypto.userDeviceListChanged(u);
});
}
};
/**