Skip to content

verification in DMs - #1050

Merged
uhoreg merged 4 commits into
matrix-org:developfrom
uhoreg:verification_in_dms
Oct 23, 2019
Merged

uhoreg merged 4 commits into
matrix-org:developfrom
uhoreg:verification_in_dms

Conversation

@uhoreg

@uhoreg uhoreg commented Oct 8, 2019

Copy link
Copy Markdown
Member

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

@bwindels bwindels left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/crypto/index.js Outdated
return;
}
const content = event.getContent();
const relatesTo

Copy link
Copy Markdown
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.

Comment thread src/crypto/index.js
if (!relatesTo || !relatesTo.rel_type
|| relatesTo.rel_type !== "m.reference"
|| !relatesTo.event_id
|| relatesTo.event_id !== eventId) {

Copy link
Copy Markdown
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?

Comment thread src/crypto/index.js Outdated
methodMap = this._baseApis._crypto._verificationMethods;
}

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

@bwindels bwindels Oct 11, 2019

Copy link
Copy Markdown
Contributor

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;

Comment thread src/crypto/index.js
Comment thread 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"] = {

Copy link
Copy Markdown
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

uhoreg commented Oct 22, 2019

Copy link
Copy Markdown
Member Author

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

@bwindels bwindels left a comment

Copy link
Copy Markdown
Contributor

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 👍 😄

Comment thread src/crypto/index.js Outdated

return new Promise(async (_resolve, _reject) => {
let eventId = undefined;
const listenPromise = new Promise(async (_resolve, _reject) => {

Copy link
Copy Markdown
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