You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-12 08:42:46 +03:00
client.js: Fix error handling in downloadKeys
Fix a bug in the error handling in downloadKeys: If the http request failed, then the exception would get silently swallowed and the promise would never resolve. Also: tests!
This commit is contained in:
@@ -378,10 +378,12 @@ MatrixClient.prototype.uploadKeys = function(maxKeys, deferred) {
|
||||
* store.
|
||||
* @param {Array} userIds The users to fetch.
|
||||
* @param {bool} forceDownload Always download the keys even if cached.
|
||||
* @return {object} A promise that will resolve when the keys are downloadded.
|
||||
*
|
||||
* @return {object} A promise that will resolve when the keys are downloaded;
|
||||
* resolves to a map userId->deviceId->device info
|
||||
*/
|
||||
MatrixClient.prototype.downloadKeys = function(userIds, forceDownload) {
|
||||
if (!CRYPTO_ENABLED || this.sessionStore === null) {
|
||||
if (this.sessionStore === null) {
|
||||
return q.reject(new Error("End-to-end encryption disabled"));
|
||||
}
|
||||
var stored = {};
|
||||
@@ -399,30 +401,29 @@ MatrixClient.prototype.downloadKeys = function(userIds, forceDownload) {
|
||||
downloadKeys = true;
|
||||
notStored[userId] = {};
|
||||
}
|
||||
var deferred = q.defer();
|
||||
if (downloadKeys) {
|
||||
var path = "/keys/query";
|
||||
var content = {device_keys: notStored};
|
||||
var self = this;
|
||||
this._http.authedRequestWithPrefix(
|
||||
undefined, "POST", path, undefined, content,
|
||||
httpApi.PREFIX_UNSTABLE
|
||||
).then(function(res) {
|
||||
for (var userId in res.device_keys) {
|
||||
if (userId in notStored) {
|
||||
self.sessionStore.storeEndToEndDevicesForUser(
|
||||
userId, res.device_keys[userId]
|
||||
);
|
||||
// TODO: validate the ed25519 signature.
|
||||
stored[userId] = res.device_keys[userId];
|
||||
}
|
||||
}
|
||||
deferred.resolve(stored);
|
||||
});
|
||||
} else {
|
||||
deferred.resolve(stored);
|
||||
|
||||
if (!downloadKeys) {
|
||||
return q(stored);
|
||||
}
|
||||
return deferred.promise;
|
||||
|
||||
var path = "/keys/query";
|
||||
var content = {device_keys: notStored};
|
||||
var self = this;
|
||||
return this._http.authedRequestWithPrefix(
|
||||
undefined, "POST", path, undefined, content,
|
||||
httpApi.PREFIX_UNSTABLE
|
||||
).then(function(res) {
|
||||
for (var userId in res.device_keys) {
|
||||
if (userId in notStored) {
|
||||
self.sessionStore.storeEndToEndDevicesForUser(
|
||||
userId, res.device_keys[userId]
|
||||
);
|
||||
// TODO: validate the ed25519 signature.
|
||||
stored[userId] = res.device_keys[userId];
|
||||
}
|
||||
}
|
||||
return stored;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user