diff --git a/src/components/structures/FilePanel.js b/src/components/structures/FilePanel.js index 8f9908f1ca..ff30c25073 100644 --- a/src/components/structures/FilePanel.js +++ b/src/components/structures/FilePanel.js @@ -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()); diff --git a/src/components/structures/TimelinePanel.js b/src/components/structures/TimelinePanel.js index 5012d91a5f..4918a4a3b4 100644 --- a/src/components/structures/TimelinePanel.js +++ b/src/components/structures/TimelinePanel.js @@ -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); } }); diff --git a/src/components/views/messages/MessageActionBar.js b/src/components/views/messages/MessageActionBar.js index cf3a0a704f..21b7cd64c9 100644 --- a/src/components/views/messages/MessageActionBar.js +++ b/src/components/views/messages/MessageActionBar.js @@ -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()) { diff --git a/src/components/views/messages/ViewSourceEvent.js b/src/components/views/messages/ViewSourceEvent.js index 9a110a8826..9e30261fd6 100644 --- a/src/components/views/messages/ViewSourceEvent.js +++ b/src/components/views/messages/ViewSourceEvent.js @@ -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()) { diff --git a/src/indexing/EventIndex.js b/src/indexing/EventIndex.js index df46d800b1..4d207d9f49 100644 --- a/src/indexing/EventIndex.js +++ b/src/indexing/EventIndex.js @@ -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.