-
-
Notifications
You must be signed in to change notification settings - Fork 606
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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; | ||
|
||
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Since the event mapper will invoke |
||
})); | ||
events = events.filter(e => e.getType() === eventType); | ||
} | ||
return { | ||
events: result.chunk.map(this.getEventMapper()), | ||
events, | ||
nextBatch: result.next_batch, | ||
}; | ||
}; | ||
|
There was a problem hiding this comment.
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 alwaysm.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)?