/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/
import {Tooltip} from '@wireapp/react-ui-kit';
import {useMessageFocusedTabIndex} from 'Components/MessagesList/Message/util';
import {getEmojiTitleFromEmojiUnicode} from 'Util/EmojiUtil';
import {isTabKey} from 'Util/KeyboardUtil';
import {t} from 'Util/LocalizerUtil';
import {replaceReactComponents} from 'Util/LocalizerUtil/ReactLocalizerUtil';
import {EmojiChar} from './EmojiChar';
import {
getReactionsButtonCSS,
messageReactionButton,
messageReactionButtonTooltip,
messageReactionButtonTooltipImage,
messageReactionButtonTooltipText,
messageReactionButtonTooltipTextLink,
messageReactionCount,
userBoldStyle,
} from './MessageReactions.styles';
import {User} from '../../../../../../entity/User';
export interface EmojiPillProps {
emoji: string;
emojiUnicode: string;
handleReactionClick: (emoji: string) => void;
isMessageFocused: boolean;
onTooltipReactionCountClick: () => void;
onLastReactionKeyEvent: () => void;
isRemovedFromConversation: boolean;
index: number;
emojiListCount: number;
hasUserReacted: boolean;
reactingUsers: User[];
}
const MAX_USER_NAMES_TO_SHOW = 2;
export const EmojiPill = ({
emoji,
emojiUnicode,
handleReactionClick,
isMessageFocused,
onTooltipReactionCountClick,
onLastReactionKeyEvent,
isRemovedFromConversation,
index,
emojiListCount,
hasUserReacted,
reactingUsers,
}: EmojiPillProps) => {
const messageFocusedTabIndex = useMessageFocusedTabIndex(isMessageFocused);
const emojiName = getEmojiTitleFromEmojiUnicode(emojiUnicode);
const isActive = hasUserReacted && !isRemovedFromConversation;
const emojiCount = reactingUsers.length;
const reactingUserNames = reactingUsers.slice(0, MAX_USER_NAMES_TO_SHOW).map(user => user.name());
const conversationReactionCaption = () => {
if (emojiCount > MAX_USER_NAMES_TO_SHOW) {
return t(
'conversationLikesCaptionPluralMoreThan2',
{
number: (emojiCount - MAX_USER_NAMES_TO_SHOW).toString(),
userNames: reactingUserNames.join(', '),
},
{},
true,
);
}
if (emojiCount === MAX_USER_NAMES_TO_SHOW) {
return t(
'conversationLikesCaptionPlural',
{
firstUser: reactingUserNames[0],
secondUser: reactingUserNames[1],
},
{},
true,
);
}
return t('conversationLikesCaptionSingular', {userName: reactingUserNames?.[0] || ''}, {}, true);
};
const caption = conversationReactionCaption();
const content = replaceReactComponents(caption, [
{
start: '',
end: '',
render: text => (
{text}
),
},
{
start: '[showmore]',
end: '[/showmore]',
render: text => (
),
},
]);
return (
!!emojiCount && (