/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see .
*/
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as ReactionActionCreators from '@app/actions/ReactionActionCreators';
import {ReactionInteractionDisabledModal} from '@app/components/alerts/ReactionInteractionDisabledModal';
import {EmojiInfoBottomSheet} from '@app/components/bottomsheets/EmojiInfoBottomSheet';
import {
createMessageActionHandlers,
isClientSystemMessage,
useMessagePermissions,
} from '@app/components/channel/MessageActionUtils';
import styles from '@app/components/channel/MessageReactions.module.css';
import {LongPressable} from '@app/components/LongPressable';
import {ExpressionPickerSheet} from '@app/components/modals/ExpressionPickerSheet';
import {EmojiPickerPopout} from '@app/components/popouts/EmojiPickerPopout';
import {ReactionTooltip} from '@app/components/popouts/ReactionTooltip';
import FocusRing from '@app/components/uikit/focus_ring/FocusRing';
import {Popout} from '@app/components/uikit/popout/Popout';
import {useHover} from '@app/hooks/useHover';
import type {MessageRecord} from '@app/records/MessageRecord';
import AccessibilityStore from '@app/stores/AccessibilityStore';
import KeyboardModeStore from '@app/stores/KeyboardModeStore';
import MobileLayoutStore from '@app/stores/MobileLayoutStore';
import {getEmojiName, getReactionKey, useEmojiURL} from '@app/utils/ReactionUtils';
import type {MessageReaction} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
import {useLingui} from '@lingui/react/macro';
import {SmileyIcon} from '@phosphor-icons/react';
import {clsx} from 'clsx';
import {AnimatePresence, motion} from 'framer-motion';
import {observer} from 'mobx-react-lite';
import {useCallback, useEffect, useRef, useState} from 'react';
interface EmojiInfoData {
id?: string;
name: string;
animated?: boolean;
}
const MessageReactionItem = observer(
({
message,
reaction,
isPreview = false,
disableInteraction = false,
}: {
message: MessageRecord;
reaction: MessageReaction;
isPreview?: boolean;
disableInteraction?: boolean;
}) => {
const {t, i18n} = useLingui();
const [hoverRef, isHovering] = useHover();
const [prevCount, setPrevCount] = useState(reaction.count);
const [animationSyncKey, setAnimationSyncKey] = useState(0);
const [emojiInfoOpen, setEmojiInfoOpen] = useState(false);
const [selectedEmoji, setSelectedEmoji] = useState(null);
const [tooltipHovering, setTooltipHovering] = useState(false);
const isMobile = MobileLayoutStore.isMobileLayout();
const handleTooltipAnimationSync = useCallback(() => {
setAnimationSyncKey((prev) => prev + 1);
}, []);
useEffect(() => {
if (prevCount !== reaction.count) {
setPrevCount(reaction.count);
}
}, [reaction.count, prevCount]);
const handleClick = () => {
if (disableInteraction) {
return;
}
if (isPreview) {
ModalActionCreators.push(modal(() => ));
return;
}
if (reaction.me) {
ReactionActionCreators.removeReaction(i18n, message.channelId, message.id, reaction.emoji);
} else {
ReactionActionCreators.addReaction(i18n, message.channelId, message.id, reaction.emoji);
}
};
const handleLongPress = () => {
if (isPreview || disableInteraction) {
return;
}
setSelectedEmoji({
id: reaction.emoji.id ?? undefined,
name: reaction.emoji.name,
animated: reaction.emoji.animated,
});
setEmojiInfoOpen(true);
};
const handleCloseEmojiInfo = useCallback(() => {
setEmojiInfoOpen(false);
setSelectedEmoji(null);
}, []);
const emojiName = getEmojiName(reaction.emoji);
const emojiUrl = useEmojiURL({emoji: reaction.emoji, isHovering: isHovering || tooltipHovering});
const isUnicodeEmoji = reaction.emoji.id == null;
const variants = {
up: {y: -20, opacity: 0},
down: {y: 20, opacity: 0},
center: {y: 0, opacity: 1},
};
const reactionCountText = reaction.count === 1 ? t`${reaction.count} reaction` : t`${reaction.count} reactions`;
const actionText = reaction.me ? t`press to remove reaction` : t`press to add reaction`;
const ariaLabel = t`${emojiName}: ${reactionCountText}, ${actionText}`;
const buttonContent = (
);
if (isMobile) {
return (
{buttonContent}
);
}
return (