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

Commit 3cdff73

Browse files
committed
Code refactor
Signed-off-by: Šimon Brandner <[email protected]>
1 parent edfd70a commit 3cdff73

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

src/components/views/emojipicker/ReactionPicker.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import dis from "../../../dispatcher/dispatcher";
2626
import { Action } from '../../../dispatcher/actions';
2727
import RoomContext from "../../../contexts/RoomContext";
2828
import { FocusComposerPayload } from '../../../dispatcher/payloads/FocusComposerPayload';
29-
import { canRedact } from "../../../utils/EventUtils";
3029

3130
interface IProps {
3231
mxEvent: MatrixEvent;
@@ -97,7 +96,7 @@ class ReactionPicker extends React.Component<IProps, IState> {
9796
const roomId = this.props.mxEvent.getRoomId();
9897
const myReactions = this.getReactions();
9998
if (myReactions.hasOwnProperty(reaction)) {
100-
if (!canRedact(roomId, myReactions[reaction])) return;
99+
if (this.props.mxEvent.isRedacted() || !this.context.canSelfRedact) return;
101100

102101
MatrixClientPeg.get().redactEvent(roomId, myReactions[reaction].getId());
103102
dis.dispatch<FocusComposerPayload>({
@@ -124,10 +123,11 @@ class ReactionPicker extends React.Component<IProps, IState> {
124123
};
125124

126125
private isEmojiDisabled = (unicode: string): boolean => {
127-
const reaction = this.getReactions()[unicode];
126+
if (!this.getReactions()[unicode]) return false;
127+
if (this.props.mxEvent.isRedacted()) return false;
128+
if (this.context.canSelfRedact) return false;
128129

129-
if (!reaction) return false;
130-
return !canRedact(this.props.mxEvent.getRoomId(), reaction);
130+
return true;
131131
};
132132

133133
render() {

src/components/views/messages/ReactionsRow.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
183183
mxEvent={mxEvent}
184184
reactionEvents={events}
185185
myReactionEvent={myReactionEvent}
186-
disabled={!this.context.canReact}
186+
disabled={(
187+
!this.context.canReact ||
188+
(myReactionEvent && !myReactionEvent.isRedacted() && this.context.canSelfRedact)
189+
)}
187190
/>;
188191
}).filter(item => !!item);
189192

src/components/views/messages/ReactionsRowButton.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import dis from "../../../dispatcher/dispatcher";
2424
import ReactionsRowButtonTooltip from "./ReactionsRowButtonTooltip";
2525
import AccessibleButton from "../elements/AccessibleButton";
2626
import MatrixClientContext from "../../../contexts/MatrixClientContext";
27-
import { canRedact } from "../../../utils/EventUtils";
2827

2928
interface IProps {
3029
// The event we're displaying reactions for
@@ -59,7 +58,6 @@ export default class ReactionsRowButton extends React.PureComponent<IProps, ISta
5958
const { mxEvent, myReactionEvent, content } = this.props;
6059
if (myReactionEvent) {
6160
const roomId = mxEvent.getRoomId();
62-
if (!canRedact(roomId, myReactionEvent)) return;
6361

6462
this.context.redactEvent(
6563
roomId,
@@ -131,7 +129,7 @@ export default class ReactionsRowButton extends React.PureComponent<IProps, ISta
131129
className={classes}
132130
aria-label={label}
133131
onClick={this.onClick}
134-
disabled={this.props.disabled || (myReactionEvent && !canRedact(mxEvent.getRoomId(), myReactionEvent))}
132+
disabled={this.props.disabled}
135133
onMouseOver={this.onMouseOver}
136134
onMouseLeave={this.onMouseLeave}
137135
>

src/utils/EventUtils.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,3 @@ export function canForward(event: MatrixEvent): boolean {
292292
export function hasThreadSummary(event: MatrixEvent): boolean {
293293
return event.isThreadRoot && event.getThread()?.length && !!event.getThread().replyToEvent;
294294
}
295-
296-
export function canRedact(roomId: string, mxEvent: MatrixEvent): boolean {
297-
const client = MatrixClientPeg.get();
298-
const room = client.getRoom(roomId);
299-
return room.currentState.maySendRedactionForEvent(mxEvent, client.getUserId());
300-
}

0 commit comments

Comments
 (0)