From 80f18e9f1cccddbe9806f77d7b7aee025972d3fc Mon Sep 17 00:00:00 2001 From: William Grant Date: Mon, 3 Apr 2023 14:09:06 +0200 Subject: [PATCH] feat: use correct timer options and set the defaults --- .../overlay/OverlayDisappearingMessages.tsx | 22 +++++++-------- ts/hooks/useParamSelector.ts | 27 ++++++++++++++++--- ts/util/expiringMessages.ts | 4 +++ ts/util/releaseFeature.ts | 3 +-- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/ts/components/conversation/right-panel/overlay/OverlayDisappearingMessages.tsx b/ts/components/conversation/right-panel/overlay/OverlayDisappearingMessages.tsx index 0cf2a8f4d..9ca547f11 100644 --- a/ts/components/conversation/right-panel/overlay/OverlayDisappearingMessages.tsx +++ b/ts/components/conversation/right-panel/overlay/OverlayDisappearingMessages.tsx @@ -18,7 +18,7 @@ import { getSelectedConversationKey, } from '../../../../state/selectors/conversations'; import { - DisappearingMessageConversationSetting, + DEFAULT_TIMER_OPTION, DisappearingMessageConversationType, } from '../../../../util/expiringMessages'; import { TimerOptionsArray } from '../../../../state/ducks/timerOptions'; @@ -204,22 +204,22 @@ export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesPr const { isGroup } = convoProps; const [modeSelected, setModeSelected] = useState(convoProps.expirationType); - const [timeSelected, setTimeSelected] = useState(convoProps.expireTimer); - // Legacy mode uses the default timer options depending on the conversation type - // TODO verify that this if fine compared to updating in the useEffect - const timerOptions = useTimerOptionsByMode( - modeSelected === 'legacy' - ? isGroup - ? DisappearingMessageConversationSetting[2] - : DisappearingMessageConversationSetting[1] - : modeSelected + const [timeSelected, setTimeSelected] = useState( + convoProps.expireTimer && convoProps.expireTimer > -1 + ? convoProps.expireTimer + : isGroup + ? DEFAULT_TIMER_OPTION.GROUP + : DEFAULT_TIMER_OPTION.PRIVATE_CONVERSATION ); + // TODO verify that this if fine compared to updating in the useEffect + const timerOptions = useTimerOptionsByMode(modeSelected); + useEffect(() => { if (modeSelected !== convoProps.expirationType) { setModeSelected(convoProps.expirationType); } - if (timeSelected !== convoProps.expireTimer) { + if (convoProps.expireTimer && timeSelected !== convoProps.expireTimer) { setTimeSelected(convoProps.expireTimer); } }, [convoProps.expirationType, convoProps.expireTimer]); diff --git a/ts/hooks/useParamSelector.ts b/ts/hooks/useParamSelector.ts index e1148488e..48a1b2564 100644 --- a/ts/hooks/useParamSelector.ts +++ b/ts/hooks/useParamSelector.ts @@ -190,11 +190,29 @@ export function useTimerOptionsByMode(disappearingMessageMode?: string) { const options = state.timerOptions.timerOptions; switch (disappearingMessageMode) { + // TODO legacy messages support will be removed in a future release + case 'legacy': + return options.filter(option => { + return ( + option.value === 5 || // 5 seconds + option.value === 10 || // 10 seconds + option.value === 30 || // 30 seconds + option.value === 60 || // 1 minute + option.value === 300 || // 5 minutes + option.value === 1800 || // 30 minutes + option.value === 3600 || // 1 hour + option.value === 21600 || // 6 hours + option.value === 43200 || // 12 hours + option.value === 86400 || // 1 day + option.value === 604800 // 1 week + ); + }); case 'deleteAfterSend': return options.filter(option => { return ( - option.value === 10 || // 10 seconds (for testing) - option.value === 30 || // 30 seconds (for testing) + option.value === 10 || // 10 seconds (for development) + option.value === 30 || // 30 seconds (for development) + option.value === 60 || // 1 minute (for testing) option.value === 43200 || // 12 hours option.value === 86400 || // 1 day option.value === 604800 || // 1 week @@ -204,8 +222,9 @@ export function useTimerOptionsByMode(disappearingMessageMode?: string) { case 'deleteAfterRead': return options.filter(option => { return ( - option.value === 10 || // 10 seconds (for testing) - option.value === 30 || // 30 seconds (for testing) + option.value === 10 || // 10 seconds (for development) + option.value === 30 || // 30 seconds (for development) + option.value === 60 || // 1 minute (for testing) option.value === 300 || // 5 minutes option.value === 3600 || // 1 hour option.value === 43200 || // 12 hours diff --git a/ts/util/expiringMessages.ts b/ts/util/expiringMessages.ts index 72160270f..8987c8c6e 100644 --- a/ts/util/expiringMessages.ts +++ b/ts/util/expiringMessages.ts @@ -15,6 +15,10 @@ export type DisappearingMessageType = typeof DisappearingMessageMode[number] | n export const DisappearingMessageConversationSetting = ['off', ...DisappearingMessageMode, 'legacy']; export type DisappearingMessageConversationType = typeof DisappearingMessageConversationSetting[number]; +export const DEFAULT_TIMER_OPTION = { + PRIVATE_CONVERSATION: 86400, // 1 day + GROUP: 43200, // 12 hours +}; export type DisappearingMessageUpdate = { expirationType: DisappearingMessageType; diff --git a/ts/util/releaseFeature.ts b/ts/util/releaseFeature.ts index dab877784..1dac194a2 100644 --- a/ts/util/releaseFeature.ts +++ b/ts/util/releaseFeature.ts @@ -1,8 +1,7 @@ import { Data } from '../data/data'; // TODO update to agreed value between platforms -const featureReleaseTimestamp = 1677574800000; // unix 28/02/2023 09:00 -// const featureReleaseTimestamp = 1676608378; // test value +const featureReleaseTimestamp = 1677488400; // unix 27/02/2023 09:00 let isFeatureReleased: boolean | undefined; /**