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

Commit f7d7a8c

Browse files
committed
Move calculation of whether to render custom reaction images up to ReactionRow
Signed-off-by: Sumner Evans <sumner@beeper.com>
1 parent c054777 commit f7d7a8c

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/components/views/messages/ReactionsRow.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import ReactionPicker from "../emojipicker/ReactionPicker";
2828
import ReactionsRowButton from "./ReactionsRowButton";
2929
import RoomContext from "../../../contexts/RoomContext";
3030
import AccessibleButton from "../elements/AccessibleButton";
31+
import SettingsStore from "../../../settings/SettingsStore";
3132

3233
// The maximum number of reactions to initially show on a message.
3334
const MAX_ITEMS_WHEN_LIMITED = 8;
@@ -172,6 +173,7 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
172173
if (!reactions || !isContentActionable(mxEvent)) {
173174
return null;
174175
}
176+
const customReactionImagesEnabled = SettingsStore.getValue("feature_render_reaction_images");
175177

176178
let items = reactions
177179
.getSortedAnnotationsByKey()
@@ -198,6 +200,7 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
198200
mxEvent={mxEvent}
199201
reactionEvents={deduplicatedEvents}
200202
myReactionEvent={myReactionEvent}
203+
customReactionImagesEnabled={customReactionImagesEnabled}
201204
disabled={
202205
!this.context.canReact ||
203206
(myReactionEvent && !myReactionEvent.isRedacted() && !this.context.canSelfRedact)

src/components/views/messages/ReactionsRowButton.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
import React from "react";
1818
import classNames from "classnames";
1919
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
20+
import { Optional } from "matrix-events-sdk/lib/types";
2021

2122
import { mediaFromMxc } from "../../../customisations/Media";
2223
import { _t } from "../../../languageHandler";
@@ -25,7 +26,6 @@ import dis from "../../../dispatcher/dispatcher";
2526
import ReactionsRowButtonTooltip from "./ReactionsRowButtonTooltip";
2627
import AccessibleButton from "../elements/AccessibleButton";
2728
import MatrixClientContext from "../../../contexts/MatrixClientContext";
28-
import SettingsStore from "../../../settings/SettingsStore";
2929
import { REACTION_SHORTCODE_KEY } from "./ReactionsRow";
3030
interface IProps {
3131
// The event we're displaying reactions for
@@ -40,6 +40,8 @@ interface IProps {
4040
myReactionEvent?: MatrixEvent;
4141
// Whether to prevent quick-reactions by clicking on this reaction
4242
disabled?: boolean;
43+
// Whether to render custom image reactions
44+
customReactionImagesEnabled?: boolean;
4345
}
4446

4547
interface IState {
@@ -103,20 +105,23 @@ export default class ReactionsRowButton extends React.PureComponent<IProps, ISta
103105
content={content}
104106
reactionEvents={reactionEvents}
105107
visible={this.state.tooltipVisible}
108+
customReactionImagesEnabled={this.props.customReactionImagesEnabled}
106109
/>
107110
);
108111
}
109112

110113
const room = this.context.getRoom(mxEvent.getRoomId());
111-
const customReactionImagesEnabled = SettingsStore.getValue("feature_render_reaction_images");
112114
let label: string | undefined;
113-
let customReactionName: string | undefined;
115+
let customReactionName: Optional<string>;
114116
if (room) {
115117
const senders: string[] = [];
116118
for (const reactionEvent of reactionEvents) {
117119
const member = room.getMember(reactionEvent.getSender()!);
118120
senders.push(member?.name || reactionEvent.getSender()!);
119-
if (customReactionImagesEnabled && REACTION_SHORTCODE_KEY.findIn(reactionEvent.getContent())) {
121+
if (
122+
this.props.customReactionImagesEnabled &&
123+
REACTION_SHORTCODE_KEY.findIn(reactionEvent.getContent())
124+
) {
120125
customReactionName = REACTION_SHORTCODE_KEY.findIn(reactionEvent.getContent());
121126
}
122127
}
@@ -137,7 +142,7 @@ export default class ReactionsRowButton extends React.PureComponent<IProps, ISta
137142
{content}
138143
</span>
139144
);
140-
if (customReactionImagesEnabled && content.startsWith("mxc://")) {
145+
if (this.props.customReactionImagesEnabled && content.startsWith("mxc://")) {
141146
const imageSrc = mediaFromMxc(content).srcHttp;
142147
if (imageSrc) {
143148
reactionContent = (

src/components/views/messages/ReactionsRowButtonTooltip.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ limitations under the License.
1616

1717
import React from "react";
1818
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
19+
import { Optional } from "matrix-events-sdk/lib/types";
1920

2021
import { unicodeToShortcode } from "../../../HtmlUtils";
2122
import { _t } from "../../../languageHandler";
2223
import { formatCommaSeparatedList } from "../../../utils/FormattingUtils";
2324
import Tooltip from "../elements/Tooltip";
2425
import MatrixClientContext from "../../../contexts/MatrixClientContext";
25-
import SettingsStore from "../../../settings/SettingsStore";
2626
import { REACTION_SHORTCODE_KEY } from "./ReactionsRow";
2727
interface IProps {
2828
// The event we're displaying reactions for
@@ -32,6 +32,8 @@ interface IProps {
3232
// A list of Matrix reaction events for this key
3333
reactionEvents: MatrixEvent[];
3434
visible: boolean;
35+
// Whether to render custom image reactions
36+
customReactionImagesEnabled?: boolean;
3537
}
3638

3739
export default class ReactionsRowButtonTooltip extends React.PureComponent<IProps> {
@@ -44,14 +46,16 @@ export default class ReactionsRowButtonTooltip extends React.PureComponent<IProp
4446
const room = this.context.getRoom(mxEvent.getRoomId());
4547
let tooltipLabel: JSX.Element | undefined;
4648
if (room) {
47-
const customReactionImagesEnabled = SettingsStore.getValue("feature_render_reaction_images");
4849
const senders: string[] = [];
49-
let customReactionName: string | undefined;
50+
let customReactionName: Optional<string>;
5051
for (const reactionEvent of reactionEvents) {
5152
const member = room.getMember(reactionEvent.getSender()!);
5253
const name = member?.name ?? reactionEvent.getSender()!;
5354
senders.push(name);
54-
if (customReactionImagesEnabled && REACTION_SHORTCODE_KEY.findIn(reactionEvent.getContent())) {
55+
if (
56+
this.props.customReactionImagesEnabled &&
57+
REACTION_SHORTCODE_KEY.findIn(reactionEvent.getContent())
58+
) {
5559
customReactionName = REACTION_SHORTCODE_KEY.findIn(reactionEvent.getContent());
5660
}
5761
}

0 commit comments

Comments
 (0)