From cea2656c72cc1fb65c2de3e388c8f289d8876006 Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Wed, 28 Aug 2024 15:14:22 +1000 Subject: [PATCH] fix: refactor disappearing messages control messages --- .../conversation/TimerNotification.tsx | 60 +++++++------------ 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/ts/components/conversation/TimerNotification.tsx b/ts/components/conversation/TimerNotification.tsx index bbbb9fa7c..aed960a63 100644 --- a/ts/components/conversation/TimerNotification.tsx +++ b/ts/components/conversation/TimerNotification.tsx @@ -147,9 +147,8 @@ function useTextToRenderI18nProps(props: PropsForExpirationTimer) { const { pubkey, profileName, expirationMode, timespanText: time, type, disabled } = props; const isPrivate = useSelectedIsPrivate(); - const isMe = useSelectedIsNoteToSelf(); - // when in a 1o1 not NTS, we have a setting per side of the conversation - const ownSideOnly = isPrivate && !isMe; + const isNoteToSelf = useSelectedIsNoteToSelf(); + const isPrivateAndNotNoteToSelf = isPrivate && !isNoteToSelf; const name = profileName ?? pubkey; @@ -169,46 +168,27 @@ function useTextToRenderI18nProps(props: PropsForExpirationTimer) { ? window.i18n('disappearingMessagesTypeRead') : window.i18n('disappearingMessagesTypeSent'); - switch (type) { - case 'fromOther': - if (disabled) { - return { token: 'disappearingMessagesTurnedOff', args: { name } }; - } - + if (disabled) { + if (type === 'fromMe' || isPrivateAndNotNoteToSelf) { return { - token: 'disappearingMessagesSet', - args: { - name, - time, - disappearing_messages_type, - }, - }; - - case 'fromMe': - case 'fromSync': - if (disabled) { - return ownSideOnly - ? { token: 'disappearingMessagesTurnedOffYou' } - : { - token: 'disappearingMessagesTurnedOff', - args: { - name, - }, - }; - } - - return { - token: 'disappearingMessagesSetYou', - args: { - time, - disappearing_messages_type, - }, + token: 'disappearingMessagesTurnedOffYou', }; - - default: - assertUnreachable(type, `TimerNotification: Missing case error "${type}"`); + } + return { + token: 'disappearingMessagesTurnedOff', + args: { + name, + }, + }; } - throw new Error('unhandled case'); + + return { + token: 'disappearingMessagesSetYou', + args: { + time, + disappearing_messages_type, + }, + }; } export const TimerNotification = (props: PropsForExpirationTimer) => {