verification in DMs - #1050
verification in DMs#1050
Conversation
bwindels
left a comment
There was a problem hiding this comment.
Looks generally good, just a few things to address before.
| return; | ||
| } | ||
| const content = event.getContent(); | ||
| const relatesTo |
There was a problem hiding this comment.
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.
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) => { |
There was a problem hiding this comment.
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;
| } | ||
| // 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.
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 |
bwindels
left a comment
There was a problem hiding this comment.
Thanks for the fixes! Looks good, just one nit, but no need to re-review after addressing that, it's good to merge 👍 😄
|
|
||
| return new Promise(async (_resolve, _reject) => { | ||
| let eventId = undefined; | ||
| const listenPromise = new Promise(async (_resolve, _reject) => { |
There was a problem hiding this comment.
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