Merge pull request #6106 from matrix-org/jryans/hidden-events-reactions

Update reactions row on event decryption
pull/21833/head
J. Ryan Stinnett 2021-05-26 17:34:54 +01:00 committed by GitHub
commit 118556b542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 32 deletions

View File

@ -81,19 +81,39 @@ 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,
}; };
} }
componentDidUpdate(prevProps) { 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: IProps) {
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);
this.props.reactions.on("Relations.remove", this.onReactionsChange); this.props.reactions.on("Relations.remove", this.onReactionsChange);
@ -102,24 +122,12 @@ 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 = () => { private onReactionsChange = () => {
// TODO: Call `onHeightChanged` as needed // TODO: Call `onHeightChanged` as needed
this.setState({ this.setState({
myReactions: this.getMyReactions(), myReactions: this.getMyReactions(),
@ -130,7 +138,7 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
this.forceUpdate(); this.forceUpdate();
} }
getMyReactions() { private getMyReactions() {
const reactions = this.props.reactions; const reactions = this.props.reactions;
if (!reactions) { if (!reactions) {
return null; return null;
@ -143,7 +151,7 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
return [...myReactions.values()]; return [...myReactions.values()];
} }
onShowAllClick = () => { private onShowAllClick = () => {
this.setState({ this.setState({
showAll: true, showAll: true,
}); });

View File

@ -790,13 +790,6 @@ export default class EventTile extends React.Component<IProps, IState> {
return null; return null;
} }
const eventId = this.props.mxEvent.getId(); const eventId = this.props.mxEvent.getId();
if (!eventId) {
// XXX: Temporary diagnostic logging for https://github.com/vector-im/element-web/issues/11120
console.error("EventTile attempted to get relations for an event without an ID");
// Use event's special `toJSON` method to log key data.
console.log(JSON.stringify(this.props.mxEvent, null, 4));
console.trace("Stacktrace for https://github.com/vector-im/element-web/issues/11120");
}
return this.props.getRelationsForEvent(eventId, "m.annotation", "m.reaction"); return this.props.getRelationsForEvent(eventId, "m.annotation", "m.reaction");
}; };