kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Merge remote-tracking branch 'origin/chats' into chats
commit
7451a52fc2
|
@ -3,6 +3,7 @@ import React from 'react';
|
||||||
import { VirtuosoMockContext } from 'react-virtuoso';
|
import { VirtuosoMockContext } from 'react-virtuoso';
|
||||||
|
|
||||||
import { ChatContext } from 'soapbox/contexts/chat-context';
|
import { ChatContext } from 'soapbox/contexts/chat-context';
|
||||||
|
import { normalizeInstance } from 'soapbox/normalizers';
|
||||||
import { IAccount } from 'soapbox/queries/accounts';
|
import { IAccount } from 'soapbox/queries/accounts';
|
||||||
|
|
||||||
import { __stub } from '../../../../api';
|
import { __stub } from '../../../../api';
|
||||||
|
@ -52,7 +53,9 @@ Object.assign(navigator, {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const store = rootState.set('me', '1');
|
const store = rootState
|
||||||
|
.set('me', '1')
|
||||||
|
.set('instance', normalizeInstance({ version: '3.4.1 (compatible; TruthSocial 1.0.0)' }));
|
||||||
|
|
||||||
const renderComponentWithChatContext = () => render(
|
const renderComponentWithChatContext = () => render(
|
||||||
<VirtuosoMockContext.Provider value={{ viewportHeight: 300, itemHeight: 100 }}>
|
<VirtuosoMockContext.Provider value={{ viewportHeight: 300, itemHeight: 100 }}>
|
||||||
|
|
|
@ -6,7 +6,7 @@ import RelativeTimestamp from 'soapbox/components/relative-timestamp';
|
||||||
import { Avatar, HStack, Stack, Text } from 'soapbox/components/ui';
|
import { Avatar, HStack, Stack, Text } from 'soapbox/components/ui';
|
||||||
import VerificationBadge from 'soapbox/components/verification_badge';
|
import VerificationBadge from 'soapbox/components/verification_badge';
|
||||||
import DropdownMenuContainer from 'soapbox/containers/dropdown_menu_container';
|
import DropdownMenuContainer from 'soapbox/containers/dropdown_menu_container';
|
||||||
import { useAppDispatch } from 'soapbox/hooks';
|
import { useAppDispatch, useFeatures } from 'soapbox/hooks';
|
||||||
import { IChat, useChatActions } from 'soapbox/queries/chats';
|
import { IChat, useChatActions } from 'soapbox/queries/chats';
|
||||||
|
|
||||||
import type { Menu } from 'soapbox/components/dropdown_menu';
|
import type { Menu } from 'soapbox/components/dropdown_menu';
|
||||||
|
@ -26,6 +26,7 @@ interface IChatListItemInterface {
|
||||||
const ChatListItem: React.FC<IChatListItemInterface> = ({ chat, onClick }) => {
|
const ChatListItem: React.FC<IChatListItemInterface> = ({ chat, onClick }) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const features = useFeatures();
|
||||||
|
|
||||||
const { deleteChat } = useChatActions(chat?.id as string);
|
const { deleteChat } = useChatActions(chat?.id as string);
|
||||||
|
|
||||||
|
@ -80,6 +81,7 @@ const ChatListItem: React.FC<IChatListItemInterface> = ({ chat, onClick }) => {
|
||||||
</HStack>
|
</HStack>
|
||||||
|
|
||||||
<HStack alignItems='center' space={2}>
|
<HStack alignItems='center' space={2}>
|
||||||
|
{features.chatsDelete && (
|
||||||
<div className='text-gray-600 hidden group-hover:block hover:text-gray-100'>
|
<div className='text-gray-600 hidden group-hover:block hover:text-gray-100'>
|
||||||
{/* TODO: fix nested buttons here */}
|
{/* TODO: fix nested buttons here */}
|
||||||
<DropdownMenuContainer
|
<DropdownMenuContainer
|
||||||
|
@ -88,6 +90,7 @@ const ChatListItem: React.FC<IChatListItemInterface> = ({ chat, onClick }) => {
|
||||||
title='Settings'
|
title='Settings'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{chat.last_message && (
|
{chat.last_message && (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { openModal } from 'soapbox/actions/modals';
|
||||||
import Link from 'soapbox/components/link';
|
import Link from 'soapbox/components/link';
|
||||||
import { Avatar, Button, HStack, Icon, Stack, Text } from 'soapbox/components/ui';
|
import { Avatar, Button, HStack, Icon, Stack, Text } from 'soapbox/components/ui';
|
||||||
import { useChatContext } from 'soapbox/contexts/chat-context';
|
import { useChatContext } from 'soapbox/contexts/chat-context';
|
||||||
import { useAppDispatch } from 'soapbox/hooks';
|
import { useAppDispatch, useFeatures } from 'soapbox/hooks';
|
||||||
import { useChatActions } from 'soapbox/queries/chats';
|
import { useChatActions } from 'soapbox/queries/chats';
|
||||||
import { secondsToDays } from 'soapbox/utils/numbers';
|
import { secondsToDays } from 'soapbox/utils/numbers';
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ const messages = defineMessages({
|
||||||
const ChatMessageListIntro = () => {
|
const ChatMessageListIntro = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const features = useFeatures();
|
||||||
|
|
||||||
const { chat, needsAcceptance } = useChatContext();
|
const { chat, needsAcceptance } = useChatContext();
|
||||||
const { acceptChat, deleteChat } = useChatActions(chat?.id as string);
|
const { acceptChat, deleteChat } = useChatActions(chat?.id as string);
|
||||||
|
@ -38,7 +39,7 @@ const ChatMessageListIntro = () => {
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!chat) {
|
if (!chat || !features.chatAcceptance) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,9 +98,11 @@ const ChatMessageListIntro = () => {
|
||||||
) : (
|
) : (
|
||||||
<HStack justifyContent='center' alignItems='center' space={1} className='flex-shrink-0'>
|
<HStack justifyContent='center' alignItems='center' space={1} className='flex-shrink-0'>
|
||||||
<Icon src={require('@tabler/icons/clock.svg')} className='text-gray-600 w-4 h-4' />
|
<Icon src={require('@tabler/icons/clock.svg')} className='text-gray-600 w-4 h-4' />
|
||||||
|
{chat.message_expiration && (
|
||||||
<Text size='sm' theme='muted'>
|
<Text size='sm' theme='muted'>
|
||||||
{intl.formatMessage(messages.messageLifespan, { day: secondsToDays(chat.message_expiration) })}
|
{intl.formatMessage(messages.messageLifespan, { day: secondsToDays(chat.message_expiration) })}
|
||||||
</Text>
|
</Text>
|
||||||
|
)}
|
||||||
</HStack>
|
</HStack>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
|
@ -14,7 +14,7 @@ import DropdownMenuContainer from 'soapbox/containers/dropdown_menu_container';
|
||||||
import PlaceholderChatMessage from 'soapbox/features/placeholder/components/placeholder-chat-message';
|
import PlaceholderChatMessage from 'soapbox/features/placeholder/components/placeholder-chat-message';
|
||||||
import Bundle from 'soapbox/features/ui/components/bundle';
|
import Bundle from 'soapbox/features/ui/components/bundle';
|
||||||
import { MediaGallery } from 'soapbox/features/ui/util/async-components';
|
import { MediaGallery } from 'soapbox/features/ui/util/async-components';
|
||||||
import { useAppSelector, useAppDispatch, useOwnAccount } from 'soapbox/hooks';
|
import { useAppSelector, useAppDispatch, useOwnAccount, useFeatures } from 'soapbox/hooks';
|
||||||
import { normalizeAccount } from 'soapbox/normalizers';
|
import { normalizeAccount } from 'soapbox/normalizers';
|
||||||
import { ChatKeys, IChat, IChatMessage, useChatActions, useChatMessages } from 'soapbox/queries/chats';
|
import { ChatKeys, IChat, IChatMessage, useChatActions, useChatMessages } from 'soapbox/queries/chats';
|
||||||
import { queryClient } from 'soapbox/queries/client';
|
import { queryClient } from 'soapbox/queries/client';
|
||||||
|
@ -73,6 +73,8 @@ const ChatMessageList: React.FC<IChatMessageList> = ({ chat, autosize }) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const account = useOwnAccount();
|
const account = useOwnAccount();
|
||||||
|
const features = useFeatures();
|
||||||
|
|
||||||
const lastReadMessageDateString = chat.latest_read_message_by_account.find((latest) => latest.id === chat.account.id)?.date;
|
const lastReadMessageDateString = chat.latest_read_message_by_account.find((latest) => latest.id === chat.account.id)?.date;
|
||||||
const lastReadMessageTimestamp = lastReadMessageDateString ? new Date(lastReadMessageDateString) : null;
|
const lastReadMessageTimestamp = lastReadMessageDateString ? new Date(lastReadMessageDateString) : null;
|
||||||
|
|
||||||
|
@ -245,11 +247,13 @@ const ChatMessageList: React.FC<IChatMessageList> = ({ chat, autosize }) => {
|
||||||
destructive: true,
|
destructive: true,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
if (features.reportChats) {
|
||||||
menu.push({
|
menu.push({
|
||||||
text: intl.formatMessage(messages.report),
|
text: intl.formatMessage(messages.report),
|
||||||
action: () => dispatch(initReport(normalizeAccount(chat.account) as any, { chatMessage } as any)),
|
action: () => dispatch(initReport(normalizeAccount(chat.account) as any, { chatMessage } as any)),
|
||||||
icon: require('@tabler/icons/flag.svg'),
|
icon: require('@tabler/icons/flag.svg'),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
menu.push({
|
menu.push({
|
||||||
text: intl.formatMessage(messages.deleteForMe),
|
text: intl.formatMessage(messages.deleteForMe),
|
||||||
action: () => handleDeleteMessage.mutate(chatMessage.id),
|
action: () => handleDeleteMessage.mutate(chatMessage.id),
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { openModal } from 'soapbox/actions/modals';
|
||||||
import List, { ListItem } from 'soapbox/components/list';
|
import List, { ListItem } from 'soapbox/components/list';
|
||||||
import { Avatar, HStack, Icon, IconButton, Menu, MenuButton, MenuItem, MenuList, Stack, Text } from 'soapbox/components/ui';
|
import { Avatar, HStack, Icon, IconButton, Menu, MenuButton, MenuItem, MenuList, Stack, Text } from 'soapbox/components/ui';
|
||||||
import VerificationBadge from 'soapbox/components/verification_badge';
|
import VerificationBadge from 'soapbox/components/verification_badge';
|
||||||
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
|
import { useAppDispatch, useAppSelector, useFeatures } from 'soapbox/hooks';
|
||||||
import { MessageExpirationValues, useChat, useChatActions } from 'soapbox/queries/chats';
|
import { MessageExpirationValues, useChat, useChatActions } from 'soapbox/queries/chats';
|
||||||
import { secondsToDays } from 'soapbox/utils/numbers';
|
import { secondsToDays } from 'soapbox/utils/numbers';
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ const messages = defineMessages({
|
||||||
const ChatPageMain = () => {
|
const ChatPageMain = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const features = useFeatures();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
const { chatId } = useParams<{ chatId: string }>();
|
const { chatId } = useParams<{ chatId: string }>();
|
||||||
|
@ -109,6 +110,7 @@ const ChatPageMain = () => {
|
||||||
{chat.account?.verified && <VerificationBadge />}
|
{chat.account?.verified && <VerificationBadge />}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{chat.message_expiration && (
|
||||||
<Text
|
<Text
|
||||||
align='left'
|
align='left'
|
||||||
size='sm'
|
size='sm'
|
||||||
|
@ -119,6 +121,7 @@ const ChatPageMain = () => {
|
||||||
>
|
>
|
||||||
{intl.formatMessage(messages.autoDeleteMessage, { day: secondsToDays(chat.message_expiration) })}
|
{intl.formatMessage(messages.autoDeleteMessage, { day: secondsToDays(chat.message_expiration) })}
|
||||||
</Text>
|
</Text>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</HStack>
|
</HStack>
|
||||||
|
|
||||||
|
@ -140,6 +143,7 @@ const ChatPageMain = () => {
|
||||||
</Stack>
|
</Stack>
|
||||||
</HStack>
|
</HStack>
|
||||||
|
|
||||||
|
{features.chatsExpiration && (
|
||||||
<List>
|
<List>
|
||||||
<ListItem
|
<ListItem
|
||||||
label={intl.formatMessage(messages.autoDeleteLabel)}
|
label={intl.formatMessage(messages.autoDeleteLabel)}
|
||||||
|
@ -166,6 +170,7 @@ const ChatPageMain = () => {
|
||||||
isSelected={chat.message_expiration === MessageExpirationValues.NINETY}
|
isSelected={chat.message_expiration === MessageExpirationValues.NINETY}
|
||||||
/>
|
/>
|
||||||
</List>
|
</List>
|
||||||
|
)}
|
||||||
|
|
||||||
<Stack space={2}>
|
<Stack space={2}>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
|
@ -179,6 +184,7 @@ const ChatPageMain = () => {
|
||||||
</div>
|
</div>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
||||||
|
{features.chatsDelete && (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
as='button'
|
as='button'
|
||||||
onSelect={handleLeaveChat}
|
onSelect={handleLeaveChat}
|
||||||
|
@ -189,6 +195,7 @@ const ChatPageMain = () => {
|
||||||
<span>{intl.formatMessage(messages.leaveChat)}</span>
|
<span>{intl.formatMessage(messages.leaveChat)}</span>
|
||||||
</div>
|
</div>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</MenuList>
|
</MenuList>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { useOwnAccount } from 'soapbox/hooks';
|
||||||
import { useUpdateCredentials } from 'soapbox/queries/accounts';
|
import { useUpdateCredentials } from 'soapbox/queries/accounts';
|
||||||
|
|
||||||
type FormData = {
|
type FormData = {
|
||||||
accepting_messages?: boolean
|
accepts_chat_messages?: boolean
|
||||||
chats_onboarded: boolean
|
chats_onboarded: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ const ChatPageSettings = () => {
|
||||||
|
|
||||||
const [data, setData] = useState<FormData>({
|
const [data, setData] = useState<FormData>({
|
||||||
chats_onboarded: true,
|
chats_onboarded: true,
|
||||||
accepting_messages: account?.accepting_messages,
|
accepts_chat_messages: account?.accepts_chat_messages,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = (event: React.FormEvent) => {
|
const handleSubmit = (event: React.FormEvent) => {
|
||||||
|
@ -49,8 +49,8 @@ const ChatPageSettings = () => {
|
||||||
hint={intl.formatMessage(messages.acceptingMessageHint)}
|
hint={intl.formatMessage(messages.acceptingMessageHint)}
|
||||||
>
|
>
|
||||||
<Toggle
|
<Toggle
|
||||||
checked={data.accepting_messages}
|
checked={data.accepts_chat_messages}
|
||||||
onChange={(event) => setData((prevData) => ({ ...prevData, accepting_messages: event.target.checked }))}
|
onChange={(event) => setData((prevData) => ({ ...prevData, accepts_chat_messages: event.target.checked }))}
|
||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</List>
|
</List>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { useOwnAccount } from 'soapbox/hooks';
|
||||||
import { useUpdateCredentials } from 'soapbox/queries/accounts';
|
import { useUpdateCredentials } from 'soapbox/queries/accounts';
|
||||||
|
|
||||||
type FormData = {
|
type FormData = {
|
||||||
accepting_messages?: boolean
|
accepts_chat_messages?: boolean
|
||||||
chats_onboarded: boolean
|
chats_onboarded: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ const Welcome = () => {
|
||||||
|
|
||||||
const [data, setData] = useState<FormData>({
|
const [data, setData] = useState<FormData>({
|
||||||
chats_onboarded: true,
|
chats_onboarded: true,
|
||||||
accepting_messages: account?.accepting_messages,
|
accepts_chat_messages: account?.accepts_chat_messages,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = (event: React.FormEvent) => {
|
const handleSubmit = (event: React.FormEvent) => {
|
||||||
|
@ -65,8 +65,8 @@ const Welcome = () => {
|
||||||
hint={intl.formatMessage(messages.acceptingMessageHint)}
|
hint={intl.formatMessage(messages.acceptingMessageHint)}
|
||||||
>
|
>
|
||||||
<Toggle
|
<Toggle
|
||||||
checked={data.accepting_messages}
|
checked={data.accepts_chat_messages}
|
||||||
onChange={(event) => setData((prevData) => ({ ...prevData, accepting_messages: event.target.checked }))}
|
onChange={(event) => setData((prevData) => ({ ...prevData, accepts_chat_messages: event.target.checked }))}
|
||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</List>
|
</List>
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { openModal } from 'soapbox/actions/modals';
|
||||||
import List, { ListItem } from 'soapbox/components/list';
|
import List, { ListItem } from 'soapbox/components/list';
|
||||||
import { Avatar, HStack, Icon, Select, Stack, Text } from 'soapbox/components/ui';
|
import { Avatar, HStack, Icon, Select, Stack, Text } from 'soapbox/components/ui';
|
||||||
import { ChatWidgetScreens, useChatContext } from 'soapbox/contexts/chat-context';
|
import { ChatWidgetScreens, useChatContext } from 'soapbox/contexts/chat-context';
|
||||||
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
|
import { useAppDispatch, useAppSelector, useFeatures } from 'soapbox/hooks';
|
||||||
import { messageExpirationOptions, MessageExpirationValues, useChatActions } from 'soapbox/queries/chats';
|
import { messageExpirationOptions, MessageExpirationValues, useChatActions } from 'soapbox/queries/chats';
|
||||||
import { secondsToDays } from 'soapbox/utils/numbers';
|
import { secondsToDays } from 'soapbox/utils/numbers';
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ const messages = defineMessages({
|
||||||
const ChatSettings = () => {
|
const ChatSettings = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const features = useFeatures();
|
||||||
|
|
||||||
const { chat, changeScreen, toggleChatPane } = useChatContext();
|
const { chat, changeScreen, toggleChatPane } = useChatContext();
|
||||||
const { deleteChat, updateChat } = useChatActions(chat?.id as string);
|
const { deleteChat, updateChat } = useChatActions(chat?.id as string);
|
||||||
|
@ -115,6 +116,7 @@ const ChatSettings = () => {
|
||||||
</Stack>
|
</Stack>
|
||||||
</HStack>
|
</HStack>
|
||||||
|
|
||||||
|
{features.chatsExpiration && (
|
||||||
<List>
|
<List>
|
||||||
<ListItem label={intl.formatMessage(messages.autoDeleteLabel)}>
|
<ListItem label={intl.formatMessage(messages.autoDeleteLabel)}>
|
||||||
<Select defaultValue={chat.message_expiration} onChange={(event) => handleUpdateChat(Number(event.target.value))}>
|
<Select defaultValue={chat.message_expiration} onChange={(event) => handleUpdateChat(Number(event.target.value))}>
|
||||||
|
@ -130,6 +132,7 @@ const ChatSettings = () => {
|
||||||
</Select>
|
</Select>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</List>
|
</List>
|
||||||
|
)}
|
||||||
|
|
||||||
<Stack space={5}>
|
<Stack space={5}>
|
||||||
<button onClick={isBlocking ? handleUnblockUser : handleBlockUser} className='w-full flex items-center space-x-2 font-bold text-sm text-primary-600 dark:text-accent-blue'>
|
<button onClick={isBlocking ? handleUnblockUser : handleBlockUser} className='w-full flex items-center space-x-2 font-bold text-sm text-primary-600 dark:text-accent-blue'>
|
||||||
|
@ -137,10 +140,12 @@ const ChatSettings = () => {
|
||||||
<span>{intl.formatMessage(isBlocking ? messages.unblockUser : messages.blockUser, { acct: chat.account.acct })}</span>
|
<span>{intl.formatMessage(isBlocking ? messages.unblockUser : messages.blockUser, { acct: chat.account.acct })}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
{features.chatsDelete && (
|
||||||
<button onClick={handleLeaveChat} className='w-full flex items-center space-x-2 font-bold text-sm text-danger-600'>
|
<button onClick={handleLeaveChat} className='w-full flex items-center space-x-2 font-bold text-sm text-danger-600'>
|
||||||
<Icon src={require('@tabler/icons/logout.svg')} className='w-5 h-5' />
|
<Icon src={require('@tabler/icons/logout.svg')} className='w-5 h-5' />
|
||||||
<span>{intl.formatMessage(messages.leaveChat)}</span>
|
<span>{intl.formatMessage(messages.leaveChat)}</span>
|
||||||
</button>
|
</button>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -90,9 +90,11 @@ const ChatWindow = () => {
|
||||||
<Text size='sm' weight='bold' truncate>{chat.account.display_name}</Text>
|
<Text size='sm' weight='bold' truncate>{chat.account.display_name}</Text>
|
||||||
{chat.account.verified && <VerificationBadge />}
|
{chat.account.verified && <VerificationBadge />}
|
||||||
</div>
|
</div>
|
||||||
|
{chat.message_expiration && (
|
||||||
<Text size='sm' weight='medium' theme='primary' truncate>
|
<Text size='sm' weight='medium' theme='primary' truncate>
|
||||||
{intl.formatMessage(messages.autoDeleteMessage, { day: secondsToDays(chat.message_expiration) })}
|
{intl.formatMessage(messages.autoDeleteMessage, { day: secondsToDays(chat.message_expiration) })}
|
||||||
</Text>
|
</Text>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</LinkWrapper>
|
</LinkWrapper>
|
||||||
</HStack>
|
</HStack>
|
||||||
|
|
|
@ -17,7 +17,7 @@ const MessagesSettings = () => {
|
||||||
const updateCredentials = useUpdateCredentials();
|
const updateCredentials = useUpdateCredentials();
|
||||||
|
|
||||||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
updateCredentials.mutate({ accepting_messages: event.target.checked });
|
updateCredentials.mutate({ accepts_chat_messages: event.target.checked });
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!account) {
|
if (!account) {
|
||||||
|
@ -31,7 +31,7 @@ const MessagesSettings = () => {
|
||||||
hint={intl.formatMessage(messages.hint)}
|
hint={intl.formatMessage(messages.hint)}
|
||||||
>
|
>
|
||||||
<Toggle
|
<Toggle
|
||||||
checked={account.accepting_messages}
|
checked={account.accepts_chat_messages}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|
|
@ -21,7 +21,7 @@ import type { Emoji, Field, EmbeddedEntity, Relationship } from 'soapbox/types/e
|
||||||
|
|
||||||
// https://docs.joinmastodon.org/entities/account/
|
// https://docs.joinmastodon.org/entities/account/
|
||||||
export const AccountRecord = ImmutableRecord({
|
export const AccountRecord = ImmutableRecord({
|
||||||
accepting_messages: false,
|
accepts_chat_messages: false,
|
||||||
acct: '',
|
acct: '',
|
||||||
avatar: '',
|
avatar: '',
|
||||||
avatar_static: '',
|
avatar_static: '',
|
||||||
|
@ -264,6 +264,12 @@ const normalizeDiscoverable = (account: ImmutableMap<string, any>) => {
|
||||||
return account.set('discoverable', discoverable);
|
return account.set('discoverable', discoverable);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Normalize message acceptance between Pleroma and Truth Social. */
|
||||||
|
const normalizeMessageAcceptance = (account: ImmutableMap<string, any>) => {
|
||||||
|
const acceptance = Boolean(account.getIn(['pleroma', 'accepts_chat_messages']) || account.get('accepting_messages'));
|
||||||
|
return account.set('accepts_chat_messages', acceptance);
|
||||||
|
};
|
||||||
|
|
||||||
/** Normalize undefined/null birthday to empty string. */
|
/** Normalize undefined/null birthday to empty string. */
|
||||||
const fixBirthday = (account: ImmutableMap<string, any>) => {
|
const fixBirthday = (account: ImmutableMap<string, any>) => {
|
||||||
const birthday = account.get('birthday');
|
const birthday = account.get('birthday');
|
||||||
|
@ -285,6 +291,7 @@ export const normalizeAccount = (account: Record<string, any>) => {
|
||||||
normalizeFqn(account);
|
normalizeFqn(account);
|
||||||
normalizeFavicon(account);
|
normalizeFavicon(account);
|
||||||
normalizeDiscoverable(account);
|
normalizeDiscoverable(account);
|
||||||
|
normalizeMessageAcceptance(account);
|
||||||
addDomain(account);
|
addDomain(account);
|
||||||
addStaffFields(account);
|
addStaffFields(account);
|
||||||
fixUsername(account);
|
fixUsername(account);
|
||||||
|
|
|
@ -15,13 +15,13 @@ export const ChatMessageRecord = ImmutableRecord({
|
||||||
card: null as Card | null,
|
card: null as Card | null,
|
||||||
chat_id: '',
|
chat_id: '',
|
||||||
content: '',
|
content: '',
|
||||||
created_at: new Date(),
|
created_at: '',
|
||||||
emojis: ImmutableList<Emoji>(),
|
emojis: ImmutableList<Emoji>(),
|
||||||
id: '',
|
id: '',
|
||||||
unread: false,
|
unread: false,
|
||||||
|
|
||||||
deleting: false,
|
deleting: false,
|
||||||
pending: false,
|
pending: false as boolean | undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const normalizeMedia = (status: ImmutableMap<string, any>) => {
|
const normalizeMedia = (status: ImmutableMap<string, any>) => {
|
||||||
|
|
|
@ -30,7 +30,7 @@ export type IAccount = {
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateCredentialsData = {
|
type UpdateCredentialsData = {
|
||||||
accepting_messages?: boolean
|
accepts_chat_messages?: boolean
|
||||||
chats_onboarded?: boolean
|
chats_onboarded?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import compareId from 'soapbox/compare_id';
|
||||||
import { ChatWidgetScreens, useChatContext } from 'soapbox/contexts/chat-context';
|
import { ChatWidgetScreens, useChatContext } from 'soapbox/contexts/chat-context';
|
||||||
import { useStatContext } from 'soapbox/contexts/stat-context';
|
import { useStatContext } from 'soapbox/contexts/stat-context';
|
||||||
import { useApi, useAppDispatch, useAppSelector, useFeatures } from 'soapbox/hooks';
|
import { useApi, useAppDispatch, useAppSelector, useFeatures } from 'soapbox/hooks';
|
||||||
|
import { normalizeChatMessage } from 'soapbox/normalizers';
|
||||||
import { flattenPages, PaginatedResult, updatePageItem } from 'soapbox/utils/queries';
|
import { flattenPages, PaginatedResult, updatePageItem } from 'soapbox/utils/queries';
|
||||||
|
|
||||||
import { queryClient } from './client';
|
import { queryClient } from './client';
|
||||||
|
@ -45,7 +46,7 @@ export interface IChat {
|
||||||
date: string
|
date: string
|
||||||
}[]
|
}[]
|
||||||
latest_read_message_created_at: null | string
|
latest_read_message_created_at: null | string
|
||||||
message_expiration: MessageExpirationValues
|
message_expiration?: MessageExpirationValues
|
||||||
unread: number
|
unread: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +93,7 @@ const useChatMessages = (chat: IChat) => {
|
||||||
|
|
||||||
const link = getNextLink(response);
|
const link = getNextLink(response);
|
||||||
const hasMore = !!link;
|
const hasMore = !!link;
|
||||||
const result = data.sort(reverseOrder);
|
const result = data.sort(reverseOrder).map(normalizeChatMessage);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result,
|
result,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
import { useApi, useOwnAccount } from 'soapbox/hooks';
|
import { useApi, useFeatures, useOwnAccount } from 'soapbox/hooks';
|
||||||
|
|
||||||
import { queryClient } from './client';
|
import { queryClient } from './client';
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ const PolicyKeys = {
|
||||||
function usePendingPolicy() {
|
function usePendingPolicy() {
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
const account = useOwnAccount();
|
const account = useOwnAccount();
|
||||||
|
const features = useFeatures();
|
||||||
|
|
||||||
const getPolicy = async() => {
|
const getPolicy = async() => {
|
||||||
const { data } = await api.get<IPolicy>('/api/v1/truth/policies/pending');
|
const { data } = await api.get<IPolicy>('/api/v1/truth/policies/pending');
|
||||||
|
@ -27,7 +28,7 @@ function usePendingPolicy() {
|
||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
staleTime: 60000, // 1 minute
|
staleTime: 60000, // 1 minute
|
||||||
cacheTime: Infinity,
|
cacheTime: Infinity,
|
||||||
enabled: !!account,
|
enabled: !!account && features.truthPolicies,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -198,12 +198,30 @@ const getInstanceFeatures = (instance: Instance) => {
|
||||||
v.software === PLEROMA,
|
v.software === PLEROMA,
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ability to accept a chat.
|
||||||
|
* POST /api/v1/pleroma/chats/:id/accept
|
||||||
|
*/
|
||||||
|
chatAcceptance: v.software === TRUTHSOCIAL,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pleroma chats API.
|
* Pleroma chats API.
|
||||||
* @see {@link https://docs.pleroma.social/backend/development/API/chats/}
|
* @see {@link https://docs.pleroma.social/backend/development/API/chats/}
|
||||||
*/
|
*/
|
||||||
chats: v.software === TRUTHSOCIAL || (v.software === PLEROMA && gte(v.version, '2.1.0')),
|
chats: v.software === TRUTHSOCIAL || (v.software === PLEROMA && gte(v.version, '2.1.0')),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ability to delete a chat.
|
||||||
|
* @see DELETE /api/v1/pleroma/chats/:id
|
||||||
|
*/
|
||||||
|
chatsDelete: v.software === TRUTHSOCIAL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ability to set disappearing messages on chats.
|
||||||
|
* @see PATCH /api/v1/pleroma/chats/:id
|
||||||
|
*/
|
||||||
|
chatsExpiration: v.software === TRUTHSOCIAL,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ability to search among chats.
|
* Ability to search among chats.
|
||||||
* @see GET /api/v1/pleroma/chats
|
* @see GET /api/v1/pleroma/chats
|
||||||
|
@ -514,10 +532,17 @@ const getInstanceFeatures = (instance: Instance) => {
|
||||||
v.software === PLEROMA && v.build === SOAPBOX && gte(v.version, '2.4.50'),
|
v.software === PLEROMA && v.build === SOAPBOX && gte(v.version, '2.4.50'),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
reportMultipleStatuses: any([
|
/**
|
||||||
v.software === MASTODON,
|
* Ability to report chat messages.
|
||||||
v.software === PLEROMA,
|
* @see POST /api/v1/reports
|
||||||
]),
|
*/
|
||||||
|
reportChats: v.software === TRUTHSOCIAL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ability to select more than one status when reporting.
|
||||||
|
* @see POST /api/v1/reports
|
||||||
|
*/
|
||||||
|
reportMultipleStatuses: v.software !== TRUTHSOCIAL,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can request a password reset email through the API.
|
* Can request a password reset email through the API.
|
||||||
|
@ -635,6 +660,13 @@ const getInstanceFeatures = (instance: Instance) => {
|
||||||
v.software === TRUTHSOCIAL,
|
v.software === TRUTHSOCIAL,
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Truth Social policies.
|
||||||
|
* @see GET /api/v1/truth/policies/pending
|
||||||
|
* @see PATCH /api/v1/truth/policies/:policyId/accept
|
||||||
|
*/
|
||||||
|
truthPolicies: v.software === TRUTHSOCIAL,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supports Truth suggestions.
|
* Supports Truth suggestions.
|
||||||
*/
|
*/
|
||||||
|
|
Ładowanie…
Reference in New Issue