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 (room?.roomId !== this.props?.roomId) return;
if (toStartOfTimeline || !data || !data.liveEvent || ev.isRedacted()) return; if (toStartOfTimeline || !data || !data.liveEvent || ev.isRedacted()) return;
if (ev.shouldAttemptDecryption()) { const client = MatrixClientPeg.get();
ev.attemptDecryption(room._client._crypto); client.decryptEvent(ev);
}
if (ev.isBeingDecrypted()) { if (ev.isBeingDecrypted()) {
this.decryptingEvents.add(ev.getId()); this.decryptingEvents.add(ev.getId());

View File

@ -1150,7 +1150,8 @@ class TimelinePanel extends React.Component {
.reverse() .reverse()
.forEach(event => { .forEach(event => {
if (event.shouldAttemptDecryption()) { 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()) { if (this.props.mxEvent.shouldAttemptDecryption()) {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
this.props.mxEvent.attemptDecryption(client._crypto); client.decryptEvent(this.props.mxEvent);
} }
if (this.props.mxEvent.isBeingDecrypted()) { if (this.props.mxEvent.isBeingDecrypted()) {

View File

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

View File

@ -177,8 +177,10 @@ export default class EventIndex extends EventEmitter {
* listener. * listener.
*/ */
onRoomTimeline = async (ev, room, toStartOfTimeline, removed, data) => { onRoomTimeline = async (ev, room, toStartOfTimeline, removed, data) => {
const client = MatrixClientPeg.get();
// We only index encrypted rooms locally. // 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 // If it isn't a live event or if it's redacted there's nothing to
// do. // do.
@ -187,14 +189,7 @@ export default class EventIndex extends EventEmitter {
return; return;
} }
if (ev.shouldAttemptDecryption()) { await client.decryptEvent(ev);
ev.attemptDecryption(room._client._crypto);
}
if (ev.isBeingDecrypted()) {
// XXX: Private member access
await ev._decryptionPromise;
}
await this.addLiveEventToIndex(ev); await this.addLiveEventToIndex(ev);
} }
@ -522,19 +517,10 @@ export default class EventIndex extends EventEmitter {
const decryptionPromises = matrixEvents const decryptionPromises = matrixEvents
.filter(event => event.isEncrypted()) .filter(event => event.isEncrypted())
.map(event => { .map(event => {
if (event.shouldAttemptDecryption()) { return client.decryptEvent(event, {
return event.attemptDecryption(client._crypto, {
isRetry: true, isRetry: true,
emit: false, 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;
}
}); });
// Let us wait for all the events to get decrypted. // Let us wait for all the events to get decrypted.