Skip to content

Commit

Permalink
Limit options for "Delete Messages from Server" for chatmail accounts
Browse files Browse the repository at this point in the history
closes #4113
  • Loading branch information
Simon-Laux committed Oct 26, 2024
1 parent ffa54d6 commit 83d7168
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Changed
- style: avoid scrolling to account list items such that they're at the very edge of the list #4252
- Update local help (2024-10-25)
- Limit options for "Delete Messages from Server" for chatmail accounts

## Fixed
- image thumbnails not showing in chat list #4247
Expand Down
38 changes: 26 additions & 12 deletions packages/frontend/src/components/Settings/Autodelete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import useTranslationFunction from '../../hooks/useTranslationFunction'

import type { DialogProps } from '../../contexts/DialogContext'

function durationToString(configValue: number | string) {
function durationToString(configValue: number | string, is_chatmail: boolean) {
if (typeof configValue === 'string') configValue = Number(configValue)
const tx = window.static_translate
switch (configValue) {
case AutodeleteDuration.NEVER:
return tx('never')
return is_chatmail ? tx('automatic') : tx('never')
case AutodeleteDuration.AT_ONCE:
return tx('autodel_at_once')
case AutodeleteDuration.ONE_MINUTE:
Expand Down Expand Up @@ -56,24 +56,36 @@ export default function Autodelete({
const accountId = selectedAccountId()
const tx = useTranslationFunction()

const isChatMail = settingsStore.settings.is_chatmail === '1'

const AUTODELETE_DURATION_OPTIONS_DEVICE = [
AutodeleteDuration.NEVER,
AutodeleteDuration.ONE_HOUR,
AutodeleteDuration.ONE_DAY,
AutodeleteDuration.ONE_WEEK,
AutodeleteDuration.FIVE_WEEKS,
AutodeleteDuration.ONE_YEAR,
].map(value => [String(value), durationToString(value)] as SelectDialogOption)
].map(
value =>
[String(value), durationToString(value, false)] as SelectDialogOption
)

const AUTODELETE_DURATION_OPTIONS_SERVER = [
AutodeleteDuration.NEVER,
AutodeleteDuration.AT_ONCE,
AutodeleteDuration.ONE_HOUR,
AutodeleteDuration.ONE_DAY,
AutodeleteDuration.ONE_WEEK,
AutodeleteDuration.FIVE_WEEKS,
AutodeleteDuration.ONE_YEAR,
].map(value => [String(value), durationToString(value)] as SelectDialogOption)
...(isChatMail
? []
: [
AutodeleteDuration.ONE_HOUR,
AutodeleteDuration.ONE_DAY,
AutodeleteDuration.ONE_WEEK,
AutodeleteDuration.FIVE_WEEKS,
AutodeleteDuration.ONE_YEAR,
]),
].map(
value =>
[String(value), durationToString(value, isChatMail)] as SelectDialogOption
)

const onOpenDialog = async (fromServer: boolean) => {
openDialog(SmallSelectDialog, {
Expand Down Expand Up @@ -117,15 +129,17 @@ export default function Autodelete({
<SettingsSelector
onClick={onOpenDialog.bind(null, false)}
currentValue={durationToString(
settingsStore.settings['delete_device_after']
settingsStore.settings['delete_device_after'],
false
)}
>
{tx('autodel_device_title')}
</SettingsSelector>
<SettingsSelector
onClick={onOpenDialog.bind(null, true)}
currentValue={durationToString(
settingsStore.settings['delete_server_after']
settingsStore.settings['delete_server_after'],
isChatMail
)}
>
{tx('autodel_server_title')}
Expand Down Expand Up @@ -170,7 +184,7 @@ function AutodeleteConfirmationDialog({
<p style={{ whiteSpace: 'pre-line' }}>
{tx(fromServer ? 'autodel_server_ask' : 'autodel_device_ask', [
String(estimateCount),
durationToString(seconds),
durationToString(seconds, false),
])}
</p>
<div style={{ display: 'flex' }}>
Expand Down

0 comments on commit 83d7168

Please sign in to comment.