Skip to content
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

Merged
merged 4 commits into from
Oct 23, 2019
Merged

verification in DMs #1050

merged 4 commits into from
Oct 23, 2019

Conversation

uhoreg
Copy link
Member

@uhoreg uhoreg commented Oct 8, 2019

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

@uhoreg uhoreg requested a review from a team October 9, 2019 15:40
@bwindels bwindels requested review from bwindels and removed request for a team October 11, 2019 14:16
Copy link
Contributor

@bwindels bwindels left a 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.

return;
}
const content = event.getContent();
const relatesTo
Copy link
Contributor

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) {
Copy link
Contributor

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?

methodMap = this._baseApis._crypto._verificationMethods;
}

return new Promise(async (_resolve, _reject) => {
Copy link
Contributor

@bwindels bwindels Oct 11, 2019

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/index.js Show resolved Hide resolved
}
// FIXME: only use one of m.relationship/m.relates_to, once MSC1849
// decides which one to use
content["m.relationship"] = content["m.relates_to"] = {
Copy link
Contributor

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.

@uhoreg
Copy link
Member Author

uhoreg commented Oct 22, 2019

Comments have been addressed.

BK tests passed: https://buildkite.com/matrix-dot-org/matrix-js-sdk/builds/608

@uhoreg uhoreg requested a review from bwindels October 22, 2019 18:58
Copy link
Contributor

@bwindels bwindels left a 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 👍 😄

@@ -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) => {
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement verification over DMs in js-sdk
5 participants