Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Update reactions when redacted
Browse files Browse the repository at this point in the history
This updates the reaction state in the reaction row and action bar when a
reaction is redacted.

Part of element-hq/element-web#9574
  • Loading branch information
jryans committed May 10, 2019
1 parent 8fdb59a commit 6a59143
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
32 changes: 30 additions & 2 deletions src/components/views/messages/ReactionDimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,36 @@ export default class ReactionDimension extends React.PureComponent {
super(props);

this.state = {
selected: this.getInitialSelection(),
selected: this.getSelection(),
};

if (props.reactions) {
props.reactions.on("Relations.redaction", this.onReactionsChange);
}
}

getInitialSelection() {
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 = () => {
this.setState({
selected: this.getSelection(),
});
}

getSelection() {
const myReactions = this.getMyReactions();
if (!myReactions) {
return null;
Expand All @@ -45,6 +70,9 @@ export default class ReactionDimension extends React.PureComponent {
let selected = null;
for (const { key, content } of options) {
const reactionExists = myReactions.some(mxEvent => {
if (mxEvent.isRedacted()) {
return false;
}
return mxEvent.getContent()["m.relates_to"].key === content;
});
if (reactionExists) {
Expand Down
33 changes: 32 additions & 1 deletion src/components/views/messages/ReactionsRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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}
Expand Down

0 comments on commit 6a59143

Please sign in to comment.