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

Pop up a dialog when we get a room key request #996

Merged
merged 9 commits into from
Jun 20, 2017

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Jun 1, 2017

No description provided.

@@ -914,6 +915,14 @@ module.exports = React.createClass({
}
}
});

const krh = new KeyRequestHandler(cli);
cli.on("crypto.roomKeyRequest", (req) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API: The KeyRequestHandler is being given the entire MatrixClient, and given we never call handleKeyRequest or handleKeyRequestCancellation in any other situation, might it be better to make it the responsibility of KeyRequestHandler to attach event listeners? No strong feelings either way, just a thought.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that. The problem is that the code ends up looking like:

new KeyRequestHandler(cli);

or possibly:

const krh = new KeyRequestHandler(cli);
krh.registerEventListenersOnTheClientYouAlreadyHave();

... neither of which make me happy in any way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, agreed. Let's leave it as it is.

this.props.matrixClient.downloadKeys([userId], false).then((r) => {
if (this._unmounted) { return; }

const deviceInfo = r[userId][deviceId];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it guaranteed that r[userId] will never ever ever be undefined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, in short.


_onShareClicked: function() {
console.log("KeyShareDialog: User clicked 'share'");
this.props.onFinished(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about you, but I find it really unclear that onFinished(true) means "share keys" and onFinished(false) means "don't share keys". I wonder if there utility in defining named constants for this e.g:

const SHARE_KEYS = true;
const DONT_SHARE_KEYS = false;
// ...
this.props.onFinished(SHARE_KEYS);

I don't feel at all strongly about this, it's just a thought. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrm. that feels a bit ott; otoh a comment at the top of KeyShareDialog explaining what the values passed to onFinshed mean does seem worthwhile.

return (
<BaseDialog className='mx_KeyShareRequestDialog'
onFinished={this.props.onFinished}
title='Encryption key request'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_t please.

const requestId = keyRequest.requestId;

if (!this._pendingKeyRequests[userId]) {
this._pendingKeyRequests[userId] = {};
Copy link
Member

@kegsay kegsay Jun 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whilst we enforce (somewhat) the syntax of user IDs (starting with @), AFAIK we have no restrictions whatsoever on the syntax of device IDs. This means you need to be careful when creating lookup tables like this, because {} is not empty. Consider the case of a device ID of "hasOwnProperty":

> s = {}
{}
> Boolean(s["hasOwnProperty"])
true

Prefer Object.create(null) which does not inherit from the default Object prototype and is therefore a true map:

> s = Object.create(null)
{}
> Boolean(s["hasOwnProperty"])
false

this._currentDevice = null;

if (r) {
for (const req of this._pendingKeyRequests[userId][deviceId]) {
Copy link
Member

@kegsay kegsay Jun 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is your null guard on :94-:100 still valid in the finished callback or do you need to re-check in case someone has changed this._pendingKeyRequests from under you e.g. by a cancellation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, all the cocking around with _currentUser and _currentDevice is to ensure that this._pendingKeyRequests can't be changed under me.

delete this._pendingKeyRequests[userId];
}

this._processNextRequest();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UX: This means that dialogs may immediately pop up after you close the previous one. I don't know about you, but I find this annoying. It might be nicer to have a list of devices / users in the dialog and check boxes in the future? Not expecting anything here, just your thoughts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"yes".

@kegsay kegsay assigned richvdh and unassigned kegsay Jun 5, 2017
@kegsay
Copy link
Member

kegsay commented Jun 6, 2017

LGTM

@richvdh richvdh merged commit 0c43188 into develop Jun 20, 2017
@richvdh richvdh deleted the rav/handle_received_room_key_requests branch June 20, 2017 21:57
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.

None yet

2 participants