You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-10 09:22:25 +03:00
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:
@@ -32,11 +32,36 @@ export default class ReactionDimension extends React.PureComponent {
|
|||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
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();
|
const myReactions = this.getMyReactions();
|
||||||
if (!myReactions) {
|
if (!myReactions) {
|
||||||
return null;
|
return null;
|
||||||
@@ -45,6 +70,9 @@ export default class ReactionDimension extends React.PureComponent {
|
|||||||
let selected = null;
|
let selected = null;
|
||||||
for (const { key, content } of options) {
|
for (const { key, content } of options) {
|
||||||
const reactionExists = myReactions.some(mxEvent => {
|
const reactionExists = myReactions.some(mxEvent => {
|
||||||
|
if (mxEvent.isRedacted()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return mxEvent.getContent()["m.relates_to"].key === content;
|
return mxEvent.getContent()["m.relates_to"].key === content;
|
||||||
});
|
});
|
||||||
if (reactionExists) {
|
if (reactionExists) {
|
||||||
|
|||||||
@@ -28,6 +28,34 @@ export default class ReactionsRow extends React.PureComponent {
|
|||||||
reactions: PropTypes.object,
|
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() {
|
render() {
|
||||||
const { mxEvent, reactions } = this.props;
|
const { mxEvent, reactions } = this.props;
|
||||||
|
|
||||||
@@ -37,7 +65,10 @@ export default class ReactionsRow extends React.PureComponent {
|
|||||||
|
|
||||||
const ReactionsRowButton = sdk.getComponent('messages.ReactionsRowButton');
|
const ReactionsRowButton = sdk.getComponent('messages.ReactionsRowButton');
|
||||||
const items = reactions.getSortedAnnotationsByKey().map(([content, events]) => {
|
const items = reactions.getSortedAnnotationsByKey().map(([content, events]) => {
|
||||||
const count = events.length;
|
const count = events.size;
|
||||||
|
if (!count) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return <ReactionsRowButton
|
return <ReactionsRowButton
|
||||||
key={content}
|
key={content}
|
||||||
content={content}
|
content={content}
|
||||||
|
|||||||
Reference in New Issue
Block a user