Chats: make chat acceptance and deletion feature-gated
This commit is contained in:
parent
4dc0ab2d00
commit
9802257751
|
@ -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,14 +81,16 @@ const ChatListItem: React.FC<IChatListItemInterface> = ({ chat, onClick }) => {
|
||||||
</HStack>
|
</HStack>
|
||||||
|
|
||||||
<HStack alignItems='center' space={2}>
|
<HStack alignItems='center' space={2}>
|
||||||
<div className='text-gray-600 hidden group-hover:block hover:text-gray-100'>
|
{features.chatsDelete && (
|
||||||
{/* TODO: fix nested buttons here */}
|
<div className='text-gray-600 hidden group-hover:block hover:text-gray-100'>
|
||||||
<DropdownMenuContainer
|
{/* TODO: fix nested buttons here */}
|
||||||
items={menu}
|
<DropdownMenuContainer
|
||||||
src={require('@tabler/icons/dots.svg')}
|
items={menu}
|
||||||
title='Settings'
|
src={require('@tabler/icons/dots.svg')}
|
||||||
/>
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,16 +180,18 @@ const ChatPageMain = () => {
|
||||||
</div>
|
</div>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
||||||
<MenuItem
|
{features.chatsDelete && (
|
||||||
as='button'
|
<MenuItem
|
||||||
onSelect={handleLeaveChat}
|
as='button'
|
||||||
className='!px-0 hover:!bg-transparent'
|
onSelect={handleLeaveChat}
|
||||||
>
|
className='!px-0 hover:!bg-transparent'
|
||||||
<div className='w-full flex items-center space-x-2 font-bold text-sm text-danger-600 dark:text-danger-500'>
|
>
|
||||||
<Icon src={require('@tabler/icons/logout.svg')} className='w-5 h-5' />
|
<div className='w-full flex items-center space-x-2 font-bold text-sm text-danger-600 dark:text-danger-500'>
|
||||||
<span>{intl.formatMessage(messages.leaveChat)}</span>
|
<Icon src={require('@tabler/icons/logout.svg')} className='w-5 h-5' />
|
||||||
</div>
|
<span>{intl.formatMessage(messages.leaveChat)}</span>
|
||||||
</MenuItem>
|
</div>
|
||||||
|
</MenuItem>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</MenuList>
|
</MenuList>
|
||||||
|
|
|
@ -138,10 +138,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>
|
||||||
|
|
||||||
<button onClick={handleLeaveChat} className='w-full flex items-center space-x-2 font-bold text-sm text-danger-600'>
|
{features.chatsDelete && (
|
||||||
<Icon src={require('@tabler/icons/logout.svg')} className='w-5 h-5' />
|
<button onClick={handleLeaveChat} className='w-full flex items-center space-x-2 font-bold text-sm text-danger-600'>
|
||||||
<span>{intl.formatMessage(messages.leaveChat)}</span>
|
<Icon src={require('@tabler/icons/logout.svg')} className='w-5 h-5' />
|
||||||
</button>
|
<span>{intl.formatMessage(messages.leaveChat)}</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -198,12 +198,24 @@ 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.
|
* Ability to set disappearing messages on chats.
|
||||||
* @see PATCH /api/v1/pleroma/chats/:id
|
* @see PATCH /api/v1/pleroma/chats/:id
|
||||||
|
|
Loading…
Reference in New Issue