From 31af9c2ab977e0330a62e27e6a02c7048504e997 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 19 May 2023 13:45:14 +1000 Subject: [PATCH] refactor & fix default duration of legacy disappearing message, and fix typo --- ...isappearingMessagesSettingsViewModel.swift | 26 +++++------------- .../Translations/de.lproj/Localizable.strings | 6 ++--- .../Translations/en.lproj/Localizable.strings | 6 ++--- .../Translations/es.lproj/Localizable.strings | 6 ++--- .../Translations/fa.lproj/Localizable.strings | 6 ++--- .../Translations/fi.lproj/Localizable.strings | 6 ++--- .../Translations/hi.lproj/Localizable.strings | 6 ++--- .../Translations/hr.lproj/Localizable.strings | 6 ++--- .../id-ID.lproj/Localizable.strings | 6 ++--- .../Translations/it.lproj/Localizable.strings | 6 ++--- .../Translations/ja.lproj/Localizable.strings | 6 ++--- .../Translations/nl.lproj/Localizable.strings | 6 ++--- .../Translations/pl.lproj/Localizable.strings | 6 ++--- .../pt_BR.lproj/Localizable.strings | 6 ++--- .../Translations/ru.lproj/Localizable.strings | 6 ++--- .../Translations/si.lproj/Localizable.strings | 6 ++--- .../Translations/sk.lproj/Localizable.strings | 6 ++--- .../Translations/sv.lproj/Localizable.strings | 6 ++--- .../Translations/th.lproj/Localizable.strings | 6 ++--- .../vi-VN.lproj/Localizable.strings | 6 ++--- .../zh-Hant.lproj/Localizable.strings | 6 ++--- .../zh_CN.lproj/Localizable.strings | 6 ++--- .../DisappearingMessageConfiguration.swift | 27 ++++++++++++------- .../MessageReceiver+ExpirationTimers.swift | 10 ++++++- 24 files changed, 97 insertions(+), 92 deletions(-) diff --git a/Session/Conversations/Settings/ThreadDisappearingMessagesSettingsViewModel.swift b/Session/Conversations/Settings/ThreadDisappearingMessagesSettingsViewModel.swift index 8aea2a83e..c1327d539 100644 --- a/Session/Conversations/Settings/ThreadDisappearingMessagesSettingsViewModel.swift +++ b/Session/Conversations/Settings/ThreadDisappearingMessagesSettingsViewModel.swift @@ -140,7 +140,7 @@ class ThreadDisappearingMessagesSettingsViewModel: SessionTableViewModel 0 else { - return "YOU_DISAPPERING_MESSAGES_INFO_DISABLE".localized() + return "YOU_DISAPPEARING_MESSAGES_INFO_DISABLE".localized() } guard isPreviousOff == true else { return String( - format: "YOU_DISAPPERING_MESSAGES_INFO_UPDATE".localized(), + format: "YOU_DISAPPEARING_MESSAGES_INFO_UPDATE".localized(), floor(durationSeconds).formatted(format: .long), (type == .disappearAfterRead ? "MESSAGE_STATE_READ".localized() : "MESSAGE_STATE_SENT".localized()) ) } return String( - format: "YOU_DISAPPERING_MESSAGES_INFO_ENABLE".localized(), + format: "YOU_DISAPPEARING_MESSAGES_INFO_ENABLE".localized(), floor(durationSeconds).formatted(format: .long), (type == .disappearAfterRead ? "MESSAGE_STATE_READ".localized() : "MESSAGE_STATE_SENT".localized()) ) diff --git a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ExpirationTimers.swift b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ExpirationTimers.swift index 99cb3bd57..ee6b4f061 100644 --- a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ExpirationTimers.swift +++ b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ExpirationTimers.swift @@ -33,6 +33,14 @@ extension MessageReceiver { guard let defaultType: DisappearingMessagesConfiguration.DisappearingMessageType = maybeDefaultType else { return } + let defaultDuration: DisappearingMessagesConfiguration.DefaultDuration = { + switch defaultType { + case .unknown: return .unknown + case .disappearAfterRead: return .disappearAfterRead + case .disappearAfterSend: return .disappearAfterSend + } + }() + let localConfig: DisappearingMessagesConfiguration = try DisappearingMessagesConfiguration .filter(id: threadId) .fetchOne(db) @@ -43,7 +51,7 @@ extension MessageReceiver { isEnabled: ((message.duration ?? 0) > 0), durationSeconds: ( message.duration.map { TimeInterval($0) } ?? - defaultType.defaultDuration + defaultDuration.seconds ), type: defaultType )