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

Commit c054777

Browse files
sumnerevanst3chguy
andcommitted
Use UnstableValue for finding the shortcode
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> Signed-off-by: Sumner Evans <sumner@beeper.com>
1 parent 40f0379 commit c054777

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/components/views/messages/ReactionsRow.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import React, { SyntheticEvent } from "react";
1818
import classNames from "classnames";
1919
import { MatrixEvent, MatrixEventEvent, Relations, RelationsEvent } from "matrix-js-sdk/src/matrix";
2020
import { uniqBy } from "lodash";
21+
import { UnstableValue } from "matrix-js-sdk/src/NamespacedValue";
2122

2223
import { _t } from "../../../languageHandler";
2324
import { isContentActionable } from "../../../utils/EventUtils";
@@ -31,6 +32,8 @@ import AccessibleButton from "../elements/AccessibleButton";
3132
// The maximum number of reactions to initially show on a message.
3233
const MAX_ITEMS_WHEN_LIMITED = 8;
3334

35+
export const REACTION_SHORTCODE_KEY = new UnstableValue("shortcode", "com.beeper.reaction.shortcode");
36+
3437
const ReactButton: React.FC<IProps> = ({ mxEvent, reactions }) => {
3538
const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu();
3639

src/components/views/messages/ReactionsRowButton.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import ReactionsRowButtonTooltip from "./ReactionsRowButtonTooltip";
2626
import AccessibleButton from "../elements/AccessibleButton";
2727
import MatrixClientContext from "../../../contexts/MatrixClientContext";
2828
import SettingsStore from "../../../settings/SettingsStore";
29+
import { REACTION_SHORTCODE_KEY } from "./ReactionsRow";
2930
interface IProps {
3031
// The event we're displaying reactions for
3132
mxEvent: MatrixEvent;
@@ -115,8 +116,8 @@ export default class ReactionsRowButton extends React.PureComponent<IProps, ISta
115116
for (const reactionEvent of reactionEvents) {
116117
const member = room.getMember(reactionEvent.getSender()!);
117118
senders.push(member?.name || reactionEvent.getSender()!);
118-
if (customReactionImagesEnabled && reactionEvent.event.content?.["com.beeper.reaction.shortcode"]) {
119-
customReactionName = reactionEvent.event.content?.["com.beeper.reaction.shortcode"];
119+
if (customReactionImagesEnabled && REACTION_SHORTCODE_KEY.findIn(reactionEvent.getContent())) {
120+
customReactionName = REACTION_SHORTCODE_KEY.findIn(reactionEvent.getContent());
120121
}
121122
}
122123

src/components/views/messages/ReactionsRowButtonTooltip.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { formatCommaSeparatedList } from "../../../utils/FormattingUtils";
2323
import Tooltip from "../elements/Tooltip";
2424
import MatrixClientContext from "../../../contexts/MatrixClientContext";
2525
import SettingsStore from "../../../settings/SettingsStore";
26+
import { REACTION_SHORTCODE_KEY } from "./ReactionsRow";
2627
interface IProps {
2728
// The event we're displaying reactions for
2829
mxEvent: MatrixEvent;
@@ -50,8 +51,8 @@ export default class ReactionsRowButtonTooltip extends React.PureComponent<IProp
5051
const member = room.getMember(reactionEvent.getSender()!);
5152
const name = member?.name ?? reactionEvent.getSender()!;
5253
senders.push(name);
53-
if (customReactionImagesEnabled && reactionEvent.event.content?.["com.beeper.reaction.shortcode"]) {
54-
customReactionName = reactionEvent.event.content?.["com.beeper.reaction.shortcode"];
54+
if (customReactionImagesEnabled && REACTION_SHORTCODE_KEY.findIn(reactionEvent.getContent())) {
55+
customReactionName = REACTION_SHORTCODE_KEY.findIn(reactionEvent.getContent());
5556
}
5657
}
5758
const shortName = unicodeToShortcode(content) || customReactionName;

0 commit comments

Comments
 (0)