import clsx from 'clsx'; import React from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { useHistory } from 'react-router-dom'; import { openModal } from 'soapbox/actions/modals'; import Link from 'soapbox/components/link'; import { Avatar, Button, HStack, Icon, Stack, Text } from 'soapbox/components/ui'; import { useChatContext } from 'soapbox/contexts/chat-context'; import { useAppDispatch, useFeatures } from 'soapbox/hooks'; import { useChatActions } from 'soapbox/queries/chats'; import { secondsToDays } from 'soapbox/utils/numbers'; const messages = defineMessages({ leaveChatHeading: { id: 'chat_message_list_intro.leave_chat.heading', defaultMessage: 'Leave Chat' }, leaveChatMessage: { id: 'chat_message_list_intro.leave_chat.message', defaultMessage: 'Are you sure you want to leave this chat? Messages will be deleted for you and this chat will be removed from your inbox.' }, leaveChatConfirm: { id: 'chat_message_list_intro.leave_chat.confirm', defaultMessage: 'Leave Chat' }, intro: { id: 'chat_message_list_intro.intro', defaultMessage: 'wants to start a chat with you' }, accept: { id: 'chat_message_list_intro.actions.accept', defaultMessage: 'Accept' }, leaveChat: { id: 'chat_message_list_intro.actions.leave_chat', defaultMessage: 'Leave chat' }, report: { id: 'chat_message_list_intro.actions.report', defaultMessage: 'Report' }, messageLifespan: { id: 'chat_message_list_intro.actions.message_lifespan', defaultMessage: 'Messages older than {day, plural, one {# day} other {# days}} are deleted.' }, }); const ChatMessageListIntro = () => { const dispatch = useAppDispatch(); const intl = useIntl(); const features = useFeatures(); const history = useHistory(); const { chat, isUsingMainChatPage, needsAcceptance } = useChatContext(); const { acceptChat, deleteChat } = useChatActions(chat?.id as string); const handleLeaveChat = () => { dispatch(openModal('CONFIRM', { heading: intl.formatMessage(messages.leaveChatHeading), message: intl.formatMessage(messages.leaveChatMessage), confirm: intl.formatMessage(messages.leaveChatConfirm), confirmationTheme: 'primary', onConfirm: () => { deleteChat.mutate(undefined, { onSuccess() { if (isUsingMainChatPage) { history.push('/chats'); } }, }); }, })); }; if (!chat || !features.chatAcceptance) { return null; } return ( {needsAcceptance ? ( <> @{chat.account.acct} {' '} {intl.formatMessage(messages.intro)} ) : ( @{chat.account.acct} )} {needsAcceptance ? ( ) : ( {chat.message_expiration && ( {intl.formatMessage(messages.messageLifespan, { day: secondsToDays(chat.message_expiration) })} )} )} ); }; export default ChatMessageListIntro;