-
-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
verification in DMs #1050
verification in DMs #1050
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks generally good, just a few things to address before.
src/crypto/index.js
Outdated
return; | ||
} | ||
const content = event.getContent(); | ||
const relatesTo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use MatrixEvent.getRelation
here. We stuck with m.relates_to
for now, but if we ever change it to m.relationship
, best to have to change it only once.
if (!relatesTo || !relatesTo.rel_type | ||
|| relatesTo.rel_type !== "m.reference" | ||
|| !relatesTo.event_id | ||
|| relatesTo.event_id !== eventId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would throw if an event comes in before the verification event gets sent (and eventId is defined).
I tried this:
function scope() {
const f = () => console.log("foo", foo);
f();
const foo = 5;
f();
}
scope();
and it throws with ReferenceError: foo is not defined
at the first call of f()
.
You could put a let eventId
at the top and reassign it at the bottom?
src/crypto/index.js
Outdated
methodMap = this._baseApis._crypto._verificationMethods; | ||
} | ||
|
||
return new Promise(async (_resolve, _reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If sendEvent
inside this function (or anything after it) would throw, it would get swallowed, as the return value from the promise executor is ignored (here the promise of the async function).
You could instead put the sendEvent
after creating this promise (and putting it in a variable) and make the whole method async rather than the promise executor, like so:
const listenPromise = new Promise((_resolve, _reject) => {
...
});
const res = await this._baseApis.sendEvent(...);
return listenPromise;
src/crypto/verification/Base.js
Outdated
} | ||
// FIXME: only use one of m.relationship/m.relates_to, once MSC1849 | ||
// decides which one to use | ||
content["m.relationship"] = content["m.relates_to"] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you're doing both here because of this discussion? I'd just stick with "m.relates_to"
for now, as we're not doing this anywhere else, but feel free to leave it like this.
Comments have been addressed. BK tests passed: https://buildkite.com/matrix-dot-org/matrix-js-sdk/builds/608 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes! Looks good, just one nit, but no need to re-review after addressing that, it's good to merge 👍 😄
src/crypto/index.js
Outdated
@@ -797,23 +797,23 @@ Crypto.prototype.requestVerificationDM = function(userId, roomId, methods) { | |||
methodMap = this._baseApis._crypto._verificationMethods; | |||
} | |||
|
|||
return new Promise(async (_resolve, _reject) => { | |||
let eventId = undefined; | |||
const listenPromise = new Promise(async (_resolve, _reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this doesn't need to be async anymore i think?
Fixes element-hq/element-web#10793
implements MSC2241
also cleans up some bits of code, and removes some obsolete (will no longer be used) code