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

Handle relations in encrypted rooms #969

Merged
merged 3 commits into from
Jun 27, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3980,7 +3980,9 @@ MatrixClient.prototype.getCanResetTimelineCallback = function() {
};

/**
* Returns relations for a given event
* Returns relations for a given event. Handles encryption transparently,
* with the caveat that the amount of events returned might be 0, even though you get a nextBatch.
* When the returned promise resolves, all messages should have finished trying to decrypt.
* @param {string} roomId the room of the event
* @param {string} eventId the id of the event
* @param {string} relationType the rel_type of the relations requested
Expand All @@ -3991,14 +3993,25 @@ MatrixClient.prototype.getCanResetTimelineCallback = function() {
*/
MatrixClient.prototype.relations =
async function(roomId, eventId, relationType, eventType, opts = {}) {
const isEncrypted = this.isRoomEncrypted(roomId);
const fetchedEventType = isEncrypted ? "m.room.encrypted" : eventType;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, so this fetchedEventType will be wrong for reactions, which are now always m.reaction even in E2E rooms. 😓 It does seem nice to handle encryption transparently though... Maybe we should add a helper function similar to _encryptEventIfNeeded called something like _getEncryptedIfNeededEventType that returns the eventual event type (with a similar exception for reactions)?


const result = await this.fetchRelations(
roomId,
eventId,
relationType,
eventType,
fetchedEventType,
opts);

let events = result.chunk.map(this.getEventMapper());
if (isEncrypted) {
await Promise.all(events.map(e => {
return new Promise(resolve => e.once("Event.decrypted", resolve));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reactions in an encrypted room won't be encrypted events themselves, so we can't use isEncrypted for the whole room to decide whether to await Event.decrypted.

Since the event mapper will invoke attemptDecryption, I think you only want to wait for Event.decrypted if event.isBeingDecrypted().

}));
events = events.filter(e => e.getType() === eventType);
}
return {
events: result.chunk.map(this.getEventMapper()),
events,
nextBatch: result.next_batch,
};
};
Expand Down