Chats: make chatsExpiration a conditional feature
This commit is contained in:
parent
239b2af553
commit
69d92b6f95
3 changed files with 54 additions and 42 deletions
|
@ -7,7 +7,7 @@ import List, { ListItem } from 'soapbox/components/list';
|
|||
import { Avatar, HStack, Icon, IconButton, Menu, MenuButton, MenuItem, MenuList, Stack, Text } from 'soapbox/components/ui';
|
||||
import VerificationBadge from 'soapbox/components/verification_badge';
|
||||
import { useChatContext } from 'soapbox/contexts/chat-context';
|
||||
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
|
||||
import { useAppDispatch, useAppSelector, useFeatures } from 'soapbox/hooks';
|
||||
import { MessageExpirationValues, useChatActions } from 'soapbox/queries/chats';
|
||||
import { secondsToDays } from 'soapbox/utils/numbers';
|
||||
|
||||
|
@ -41,6 +41,7 @@ const messages = defineMessages({
|
|||
const ChatPageMain = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
const intl = useIntl();
|
||||
const features = useFeatures();
|
||||
|
||||
const inputRef = useRef<HTMLTextAreaElement | null>(null);
|
||||
|
||||
|
@ -138,32 +139,34 @@ const ChatPageMain = () => {
|
|||
</Stack>
|
||||
</HStack>
|
||||
|
||||
<List>
|
||||
<ListItem
|
||||
label={intl.formatMessage(messages.autoDeleteLabel)}
|
||||
hint={intl.formatMessage(messages.autoDeleteHint)}
|
||||
/>
|
||||
<ListItem
|
||||
label={intl.formatMessage(messages.autoDelete7Days)}
|
||||
onSelect={() => handleUpdateChat(MessageExpirationValues.SEVEN)}
|
||||
isSelected={chat.message_expiration === MessageExpirationValues.SEVEN}
|
||||
/>
|
||||
<ListItem
|
||||
label={intl.formatMessage(messages.autoDelete14Days)}
|
||||
onSelect={() => handleUpdateChat(MessageExpirationValues.FOURTEEN)}
|
||||
isSelected={chat.message_expiration === MessageExpirationValues.FOURTEEN}
|
||||
/>
|
||||
<ListItem
|
||||
label={intl.formatMessage(messages.autoDelete30Days)}
|
||||
onSelect={() => handleUpdateChat(MessageExpirationValues.THIRTY)}
|
||||
isSelected={chat.message_expiration === MessageExpirationValues.THIRTY}
|
||||
/>
|
||||
<ListItem
|
||||
label={intl.formatMessage(messages.autoDelete90Days)}
|
||||
onSelect={() => handleUpdateChat(MessageExpirationValues.NINETY)}
|
||||
isSelected={chat.message_expiration === MessageExpirationValues.NINETY}
|
||||
/>
|
||||
</List>
|
||||
{features.chatsExpiration && (
|
||||
<List>
|
||||
<ListItem
|
||||
label={intl.formatMessage(messages.autoDeleteLabel)}
|
||||
hint={intl.formatMessage(messages.autoDeleteHint)}
|
||||
/>
|
||||
<ListItem
|
||||
label={intl.formatMessage(messages.autoDelete7Days)}
|
||||
onSelect={() => handleUpdateChat(MessageExpirationValues.SEVEN)}
|
||||
isSelected={chat.message_expiration === MessageExpirationValues.SEVEN}
|
||||
/>
|
||||
<ListItem
|
||||
label={intl.formatMessage(messages.autoDelete14Days)}
|
||||
onSelect={() => handleUpdateChat(MessageExpirationValues.FOURTEEN)}
|
||||
isSelected={chat.message_expiration === MessageExpirationValues.FOURTEEN}
|
||||
/>
|
||||
<ListItem
|
||||
label={intl.formatMessage(messages.autoDelete30Days)}
|
||||
onSelect={() => handleUpdateChat(MessageExpirationValues.THIRTY)}
|
||||
isSelected={chat.message_expiration === MessageExpirationValues.THIRTY}
|
||||
/>
|
||||
<ListItem
|
||||
label={intl.formatMessage(messages.autoDelete90Days)}
|
||||
onSelect={() => handleUpdateChat(MessageExpirationValues.NINETY)}
|
||||
isSelected={chat.message_expiration === MessageExpirationValues.NINETY}
|
||||
/>
|
||||
</List>
|
||||
)}
|
||||
|
||||
<Stack space={2}>
|
||||
<MenuItem
|
||||
|
|
|
@ -6,7 +6,7 @@ import { openModal } from 'soapbox/actions/modals';
|
|||
import List, { ListItem } from 'soapbox/components/list';
|
||||
import { Avatar, HStack, Icon, Select, Stack, Text } from 'soapbox/components/ui';
|
||||
import { 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 { secondsToDays } from 'soapbox/utils/numbers';
|
||||
|
||||
|
@ -33,6 +33,7 @@ const messages = defineMessages({
|
|||
const ChatSettings = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
const intl = useIntl();
|
||||
const features = useFeatures();
|
||||
|
||||
const { chat, setEditing, toggleChatPane } = useChatContext();
|
||||
const { deleteChat, updateChat } = useChatActions(chat?.id as string);
|
||||
|
@ -113,21 +114,23 @@ const ChatSettings = () => {
|
|||
</Stack>
|
||||
</HStack>
|
||||
|
||||
<List>
|
||||
<ListItem label={intl.formatMessage(messages.autoDeleteLabel)}>
|
||||
<Select defaultValue={chat.message_expiration} onChange={(event) => handleUpdateChat(Number(event.target.value))}>
|
||||
{messageExpirationOptions.map((duration) => {
|
||||
const inDays = secondsToDays(duration);
|
||||
{features.chatsExpiration && (
|
||||
<List>
|
||||
<ListItem label={intl.formatMessage(messages.autoDeleteLabel)}>
|
||||
<Select defaultValue={chat.message_expiration} onChange={(event) => handleUpdateChat(Number(event.target.value))}>
|
||||
{messageExpirationOptions.map((duration) => {
|
||||
const inDays = secondsToDays(duration);
|
||||
|
||||
return (
|
||||
<option key={duration} value={duration}>
|
||||
{intl.formatMessage(messages.autoDeleteDays, { day: inDays })}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
</ListItem>
|
||||
</List>
|
||||
return (
|
||||
<option key={duration} value={duration}>
|
||||
{intl.formatMessage(messages.autoDeleteDays, { day: inDays })}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
</ListItem>
|
||||
</List>
|
||||
)}
|
||||
|
||||
<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'>
|
||||
|
|
|
@ -204,6 +204,12 @@ const getInstanceFeatures = (instance: Instance) => {
|
|||
*/
|
||||
chats: v.software === TRUTHSOCIAL || (v.software === PLEROMA && gte(v.version, '2.1.0')),
|
||||
|
||||
/**
|
||||
* Ability to set disappearing messages on chats.
|
||||
* @see PATCH /api/v1/pleroma/chats/:id
|
||||
*/
|
||||
chatsExpiration: v.software === TRUTHSOCIAL,
|
||||
|
||||
/**
|
||||
* Ability to search among chats.
|
||||
* @see GET /api/v1/pleroma/chats
|
||||
|
|
Loading…
Reference in a new issue