1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

Add MatrixClient.getEventSenderDeviceInfo()

- a function to get information about the device which sent an event
This commit is contained in:
Richard van der Hoff
2016-09-20 15:31:10 +01:00
parent 6e31319294
commit 78a0aa5d47
2 changed files with 31 additions and 24 deletions

View File

@@ -401,6 +401,21 @@ function _setDeviceVerification(client, userId, deviceId, verified, blocked) {
client.emit("deviceVerificationChanged", userId, deviceId);
}
/**
* Get e2e information on the device that sent an event
*
* @param {MatrixEvent} event event to be checked
*
* @return {module:crypto/deviceinfo?}
*/
MatrixClient.prototype.getEventSenderDeviceInfo = function(event) {
if (!this._crypto) {
return null;
}
return this._crypto.getEventSenderDeviceInfo(event);
};
/**
* Check if the sender of an event is verified
*
@@ -410,21 +425,11 @@ function _setDeviceVerification(client, userId, deviceId, verified, blocked) {
* {@link module:client~MatrixClient#setDeviceVerified|setDeviceVerified}.
*/
MatrixClient.prototype.isEventSenderVerified = function(event) {
if (!this._crypto) {
var device = this.getEventSenderDeviceInfo(event);
if (!device) {
return false;
}
var sender_key = event.getSenderKey();
if (!sender_key) {
return false;
}
var algorithm = event.getWireContent().algorithm;
return this._crypto.isSenderKeyVerified(
event.getSender(), algorithm, sender_key
);
return device.isVerified();
};
/**