You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-01 04:43:29 +03:00
apply suggestions from review
This commit is contained in:
@@ -782,7 +782,7 @@ function verificationEventHandler(target, userId, roomId, eventId) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Crypto.prototype.requestVerificationDM = function(userId, roomId, methods) {
|
Crypto.prototype.requestVerificationDM = async function(userId, roomId, methods) {
|
||||||
let methodMap;
|
let methodMap;
|
||||||
if (methods) {
|
if (methods) {
|
||||||
methodMap = new Map();
|
methodMap = new Map();
|
||||||
@@ -797,16 +797,15 @@ Crypto.prototype.requestVerificationDM = function(userId, roomId, methods) {
|
|||||||
methodMap = this._baseApis._crypto._verificationMethods;
|
methodMap = this._baseApis._crypto._verificationMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise(async (_resolve, _reject) => {
|
let eventId = undefined;
|
||||||
|
const listenPromise = new Promise(async (_resolve, _reject) => {
|
||||||
const listener = (event) => {
|
const listener = (event) => {
|
||||||
// listen for events related to this verification
|
// listen for events related to this verification
|
||||||
if (event.getRoomId() !== roomId
|
if (event.getRoomId() !== roomId
|
||||||
|| event.getSender() !== userId) {
|
|| event.getSender() !== userId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const content = event.getContent();
|
const relatesTo = event.getRelation();
|
||||||
const relatesTo
|
|
||||||
= content["m.relationship"] || content["m.relates_to"];
|
|
||||||
if (!relatesTo || !relatesTo.rel_type
|
if (!relatesTo || !relatesTo.rel_type
|
||||||
|| relatesTo.rel_type !== "m.reference"
|
|| relatesTo.rel_type !== "m.reference"
|
||||||
|| !relatesTo.event_id
|
|| !relatesTo.event_id
|
||||||
@@ -814,6 +813,7 @@ Crypto.prototype.requestVerificationDM = function(userId, roomId, methods) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const content = event.getContent();
|
||||||
// the event seems to be related to this verification
|
// the event seems to be related to this verification
|
||||||
switch (event.getType()) {
|
switch (event.getType()) {
|
||||||
case "m.key.verification.start": {
|
case "m.key.verification.start": {
|
||||||
@@ -824,6 +824,8 @@ Crypto.prototype.requestVerificationDM = function(userId, roomId, methods) {
|
|||||||
verifier.handler = verificationEventHandler(
|
verifier.handler = verificationEventHandler(
|
||||||
verifier, userId, roomId, eventId,
|
verifier, userId, roomId, eventId,
|
||||||
);
|
);
|
||||||
|
// this handler gets removed when the verification finishes
|
||||||
|
// (see the verify method of crypto/verification/Base.js)
|
||||||
this._baseApis.on("event", verifier.handler);
|
this._baseApis.on("event", verifier.handler);
|
||||||
resolve(verifier);
|
resolve(verifier);
|
||||||
break;
|
break;
|
||||||
@@ -844,22 +846,24 @@ Crypto.prototype.requestVerificationDM = function(userId, roomId, methods) {
|
|||||||
this._baseApis.off("event", listener);
|
this._baseApis.off("event", listener);
|
||||||
_reject(...args);
|
_reject(...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
const res = await this._baseApis.sendEvent(
|
|
||||||
roomId, "m.room.message",
|
|
||||||
{
|
|
||||||
body: this._baseApis.getUserId() + " is requesting to verify " +
|
|
||||||
"your key, but your client does not support in-chat key " +
|
|
||||||
"verification. You will need to use legacy key " +
|
|
||||||
"verification to verify keys.",
|
|
||||||
msgtype: "m.key.verification.request",
|
|
||||||
to: userId,
|
|
||||||
from_device: this._baseApis.getDeviceId(),
|
|
||||||
methods: [...methodMap.keys()],
|
|
||||||
},
|
|
||||||
);
|
|
||||||
const eventId = res.event_id;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const res = await this._baseApis.sendEvent(
|
||||||
|
roomId, "m.room.message",
|
||||||
|
{
|
||||||
|
body: this._baseApis.getUserId() + " is requesting to verify " +
|
||||||
|
"your key, but your client does not support in-chat key " +
|
||||||
|
"verification. You will need to use legacy key " +
|
||||||
|
"verification to verify keys.",
|
||||||
|
msgtype: "m.key.verification.request",
|
||||||
|
to: userId,
|
||||||
|
from_device: this._baseApis.getDeviceId(),
|
||||||
|
methods: [...methodMap.keys()],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
eventId = res.event_id;
|
||||||
|
|
||||||
|
return listenPromise;
|
||||||
};
|
};
|
||||||
|
|
||||||
Crypto.prototype.acceptVerificationDM = function(event, Method) {
|
Crypto.prototype.acceptVerificationDM = function(event, Method) {
|
||||||
|
|||||||
@@ -123,9 +123,9 @@ export default class VerificationBase extends EventEmitter {
|
|||||||
if (this._done) {
|
if (this._done) {
|
||||||
return Promise.reject(new Error("Verification is already done"));
|
return Promise.reject(new Error("Verification is already done"));
|
||||||
}
|
}
|
||||||
// FIXME: only use one of m.relationship/m.relates_to, once MSC1849
|
// FIXME: if MSC1849 decides to use m.relationship instead of
|
||||||
// decides which one to use
|
// m.relates_to, we should follow suit here
|
||||||
content["m.relationship"] = content["m.relates_to"] = {
|
content["m.relates_to"] = {
|
||||||
rel_type: "m.reference",
|
rel_type: "m.reference",
|
||||||
event_id: this.transactionId,
|
event_id: this.transactionId,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user