Use client.decryptEvent to avoid accessing js-sdk private members

pull/21833/head
Germain Souquet 2021-05-18 11:41:20 +01:00
parent 871c48f69b
commit 1cfd4b6e1a
5 changed files with 14 additions and 28 deletions

View File

@ -50,9 +50,8 @@ class FilePanel extends React.Component {
if (room?.roomId !== this.props?.roomId) return;
if (toStartOfTimeline || !data || !data.liveEvent || ev.isRedacted()) return;
if (ev.shouldAttemptDecryption()) {
ev.attemptDecryption(room._client._crypto);
}
const client = MatrixClientPeg.get();
client.decryptEvent(ev);
if (ev.isBeingDecrypted()) {
this.decryptingEvents.add(ev.getId());

View File

@ -1150,7 +1150,8 @@ class TimelinePanel extends React.Component {
.reverse()
.forEach(event => {
if (event.shouldAttemptDecryption()) {
event.attemptDecryption(MatrixClientPeg.get()._crypto);
const client = MatrixClientPeg.get();
client.decryptEvent(event);
}
});

View File

@ -126,7 +126,7 @@ export default class MessageActionBar extends React.PureComponent {
if (this.props.mxEvent.shouldAttemptDecryption()) {
const client = MatrixClientPeg.get();
this.props.mxEvent.attemptDecryption(client._crypto);
client.decryptEvent(this.props.mxEvent);
}
if (this.props.mxEvent.isBeingDecrypted()) {

View File

@ -40,7 +40,7 @@ export default class ViewSourceEvent extends React.PureComponent {
const client = MatrixClientPeg.get();
if (mxEvent.shouldAttemptDecryption()) {
mxEvent.attemptDecryption(client._client._crypto);
client.decryptEvent(mxEvent);
}
if (mxEvent.isBeingDecrypted()) {

View File

@ -177,8 +177,10 @@ export default class EventIndex extends EventEmitter {
* listener.
*/
onRoomTimeline = async (ev, room, toStartOfTimeline, removed, data) => {
const client = MatrixClientPeg.get();
// We only index encrypted rooms locally.
if (!MatrixClientPeg.get().isRoomEncrypted(room.roomId)) return;
if (!client.isRoomEncrypted(room.roomId)) return;
// If it isn't a live event or if it's redacted there's nothing to
// do.
@ -187,14 +189,7 @@ export default class EventIndex extends EventEmitter {
return;
}
if (ev.shouldAttemptDecryption()) {
ev.attemptDecryption(room._client._crypto);
}
if (ev.isBeingDecrypted()) {
// XXX: Private member access
await ev._decryptionPromise;
}
await client.decryptEvent(ev);
await this.addLiveEventToIndex(ev);
}
@ -522,19 +517,10 @@ export default class EventIndex extends EventEmitter {
const decryptionPromises = matrixEvents
.filter(event => event.isEncrypted())
.map(event => {
if (event.shouldAttemptDecryption()) {
return event.attemptDecryption(client._crypto, {
isRetry: true,
emit: false,
});
} else {
// TODO the decryption promise is a private property, this
// should either be made public or we should convert the
// event that gets fired when decryption is done into a
// promise using the once event emitter method:
// https://nodejs.org/api/events.html#events_events_once_emitter_name
return event._decryptionPromise;
}
return client.decryptEvent(event, {
isRetry: true,
emit: false,
});
});
// Let us wait for all the events to get decrypted.