Update reactions when redacted

This updates the reaction state in the reaction row and action bar when a
reaction is redacted.

Part of https://github.com/vector-im/riot-web/issues/9574
This commit is contained in:
J. Ryan Stinnett 2019-05-09 15:14:58 +01:00
parent 8fdb59a909
commit 6a59143ffb
2 changed files with 62 additions and 3 deletions

View file

@ -28,6 +28,34 @@ export default class ReactionsRow extends React.PureComponent {
reactions: PropTypes.object,
}
constructor(props) {
super(props);
if (props.reactions) {
props.reactions.on("Relations.redaction", this.onReactionsChange);
}
}
componentWillReceiveProps(nextProps) {
if (this.props.reactions !== nextProps.reactions) {
nextProps.reactions.on("Relations.redaction", this.onReactionsChange);
}
}
componentWillUnmount() {
if (this.props.reactions) {
this.props.reactions.removeListener(
"Relations.redaction",
this.onReactionsChange,
);
}
}
onReactionsChange = () => {
// TODO: Call `onHeightChanged` as needed
this.forceUpdate();
}
render() {
const { mxEvent, reactions } = this.props;
@ -37,7 +65,10 @@ export default class ReactionsRow extends React.PureComponent {
const ReactionsRowButton = sdk.getComponent('messages.ReactionsRowButton');
const items = reactions.getSortedAnnotationsByKey().map(([content, events]) => {
const count = events.length;
const count = events.size;
if (!count) {
return null;
}
return <ReactionsRowButton
key={content}
content={content}