Update reactions row on event decryption

This fixes a race (perhaps revealed by the recent lazy decryption work) where
the reactions row have reactions to show, but the event would not be decrypted,
so they wouldn't render. Adding a decryption listener gets things moving again.

Fixes https://github.com/vector-im/element-web/issues/17461
This commit is contained in:
J. Ryan Stinnett 2021-05-26 16:47:21 +01:00
parent cb88f37bbd
commit d4ca1babbe

View file

@ -81,18 +81,38 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
if (props.reactions) {
props.reactions.on("Relations.add", this.onReactionsChange);
props.reactions.on("Relations.remove", this.onReactionsChange);
props.reactions.on("Relations.redaction", this.onReactionsChange);
}
this.state = { this.state = {
myReactions: this.getMyReactions(), myReactions: this.getMyReactions(),
showAll: false, showAll: false,
}; };
} }
componentDidMount() {
const { mxEvent, reactions } = this.props;
if (mxEvent.isBeingDecrypted() || mxEvent.shouldAttemptDecryption()) {
mxEvent.once("Event.decrypted", this.onDecrypted);
}
if (reactions) {
reactions.on("Relations.add", this.onReactionsChange);
reactions.on("Relations.remove", this.onReactionsChange);
reactions.on("Relations.redaction", this.onReactionsChange);
}
}
componentWillUnmount() {
const { mxEvent, reactions } = this.props;
mxEvent.off("Event.decrypted", this.onDecrypted);
if (reactions) {
reactions.off("Relations.add", this.onReactionsChange);
reactions.off("Relations.remove", this.onReactionsChange);
reactions.off("Relations.redaction", this.onReactionsChange);
}
}
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
if (prevProps.reactions !== this.props.reactions) { if (prevProps.reactions !== this.props.reactions) {
this.props.reactions.on("Relations.add", this.onReactionsChange); this.props.reactions.on("Relations.add", this.onReactionsChange);
@ -102,21 +122,9 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
} }
} }
componentWillUnmount() { private onDecrypted = () => {
if (this.props.reactions) { // Decryption changes whether the event is actionable
this.props.reactions.removeListener( this.forceUpdate();
"Relations.add",
this.onReactionsChange,
);
this.props.reactions.removeListener(
"Relations.remove",
this.onReactionsChange,
);
this.props.reactions.removeListener(
"Relations.redaction",
this.onReactionsChange,
);
}
} }
onReactionsChange = () => { onReactionsChange = () => {