Merge pull request #6052 from matrix-org/gsouquet/decrypt-relations

This commit is contained in:
Germain 2021-05-18 17:21:13 +01:00 committed by GitHub
commit cf384c2a54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 22 deletions

View file

@ -331,6 +331,8 @@ export const Notifier = {
if (!this.isSyncing) return; // don't alert for any messages initially if (!this.isSyncing) return; // don't alert for any messages initially
if (ev.sender && ev.sender.userId === MatrixClientPeg.get().credentials.userId) return; if (ev.sender && ev.sender.userId === MatrixClientPeg.get().credentials.userId) return;
MatrixClientPeg.get().decryptEventIfNeeded(ev);
// If it's an encrypted event and the type is still 'm.room.encrypted', // If it's an encrypted event and the type is still 'm.room.encrypted',
// it hasn't yet been decrypted, so wait until it is. // it hasn't yet been decrypted, so wait until it is.
if (ev.isBeingDecrypted() || ev.isDecryptionFailure()) { if (ev.isBeingDecrypted() || ev.isDecryptionFailure()) {

View file

@ -50,6 +50,9 @@ 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;
const client = MatrixClientPeg.get();
client.decryptEventIfNeeded(ev);
if (ev.isBeingDecrypted()) { if (ev.isBeingDecrypted()) {
this.decryptingEvents.add(ev.getId()); this.decryptingEvents.add(ev.getId());
} else { } else {

View file

@ -811,7 +811,7 @@ export default class RoomView extends React.Component<IProps, IState> {
}; };
private onEvent = (ev) => { private onEvent = (ev) => {
if (ev.isBeingDecrypted() || ev.isDecryptionFailure()) return; if (ev.isBeingDecrypted() || ev.isDecryptionFailure() || ev.shouldAttemptDecryption()) return;
this.handleEffects(ev); this.handleEffects(ev);
}; };

View file

@ -1149,9 +1149,8 @@ class TimelinePanel extends React.Component {
arrayFastClone(events) arrayFastClone(events)
.reverse() .reverse()
.forEach(event => { .forEach(event => {
if (event.shouldAttemptDecryption()) { const client = MatrixClientPeg.get();
event.attemptDecryption(MatrixClientPeg.get()._crypto); client.decryptEventIfNeeded(event);
}
}); });
const firstVisibleEventIndex = this._checkForPreJoinUISI(events); const firstVisibleEventIndex = this._checkForPreJoinUISI(events);

View file

@ -31,6 +31,7 @@ import {RovingAccessibleTooltipButton, useRovingTabIndex} from "../../../accessi
import {replaceableComponent} from "../../../utils/replaceableComponent"; import {replaceableComponent} from "../../../utils/replaceableComponent";
import {canCancel} from "../context_menus/MessageContextMenu"; import {canCancel} from "../context_menus/MessageContextMenu";
import Resend from "../../../Resend"; import Resend from "../../../Resend";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
const OptionsButton = ({mxEvent, getTile, getReplyThread, permalinkCreator, onFocusChange}) => { const OptionsButton = ({mxEvent, getTile, getReplyThread, permalinkCreator, onFocusChange}) => {
const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu(); const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu();
@ -122,6 +123,10 @@ export default class MessageActionBar extends React.PureComponent {
if (this.props.mxEvent.status && this.props.mxEvent.status !== EventStatus.SENT) { if (this.props.mxEvent.status && this.props.mxEvent.status !== EventStatus.SENT) {
this.props.mxEvent.on("Event.status", this.onSent); this.props.mxEvent.on("Event.status", this.onSent);
} }
const client = MatrixClientPeg.get();
client.decryptEventIfNeeded(this.props.mxEvent);
if (this.props.mxEvent.isBeingDecrypted()) { if (this.props.mxEvent.isBeingDecrypted()) {
this.props.mxEvent.once("Event.decrypted", this.onDecrypted); this.props.mxEvent.once("Event.decrypted", this.onDecrypted);
} }

View file

@ -18,6 +18,7 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import {replaceableComponent} from "../../../utils/replaceableComponent"; import {replaceableComponent} from "../../../utils/replaceableComponent";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
@replaceableComponent("views.messages.ViewSourceEvent") @replaceableComponent("views.messages.ViewSourceEvent")
export default class ViewSourceEvent extends React.PureComponent { export default class ViewSourceEvent extends React.PureComponent {
@ -36,6 +37,10 @@ export default class ViewSourceEvent extends React.PureComponent {
componentDidMount() { componentDidMount() {
const {mxEvent} = this.props; const {mxEvent} = this.props;
const client = MatrixClientPeg.get();
client.decryptEventIfNeeded(mxEvent);
if (mxEvent.isBeingDecrypted()) { if (mxEvent.isBeingDecrypted()) {
mxEvent.once("Event.decrypted", () => this.forceUpdate()); mxEvent.once("Event.decrypted", () => this.forceUpdate());
} }

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,10 +189,7 @@ export default class EventIndex extends EventEmitter {
return; return;
} }
if (ev.isBeingDecrypted()) { await client.decryptEventIfNeeded(ev);
// XXX: Private member access
await ev._decryptionPromise;
}
await this.addLiveEventToIndex(ev); await this.addLiveEventToIndex(ev);
} }
@ -518,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.decryptEventIfNeeded(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.

View file

@ -400,6 +400,7 @@ export class StopGapWidget extends EventEmitter {
} }
private onEvent = (ev: MatrixEvent) => { private onEvent = (ev: MatrixEvent) => {
MatrixClientPeg.get().decryptEventIfNeeded(ev);
if (ev.isBeingDecrypted() || ev.isDecryptionFailure()) return; if (ev.isBeingDecrypted() || ev.isDecryptionFailure()) return;
if (ev.getRoomId() !== this.eventListenerRoomId) return; if (ev.getRoomId() !== this.eventListenerRoomId) return;
this.feedEvent(ev); this.feedEvent(ev);

View file

@ -95,6 +95,7 @@ export function createTestClient() {
getItem: jest.fn(), getItem: jest.fn(),
}, },
}, },
decryptEventIfNeeded: () => Promise.resolve(),
}; };
} }