From a98c213b78900a52dbfd3349bc2b5ca266e38202 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Thu, 5 Sep 2024 11:20:37 +1000 Subject: [PATCH] fix disappearing messages strings --- .../Settings/ThreadSettingsViewModel.swift | 8 ++++---- .../Views & Modals/ConversationTitleView.swift | 8 ++++---- .../Models/DisappearingMessageConfiguration.swift | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Session/Conversations/Settings/ThreadSettingsViewModel.swift b/Session/Conversations/Settings/ThreadSettingsViewModel.swift index cdd3c7ac7..b8f8067dc 100644 --- a/Session/Conversations/Settings/ThreadSettingsViewModel.swift +++ b/Session/Conversations/Settings/ThreadSettingsViewModel.swift @@ -453,10 +453,10 @@ class ThreadSettingsViewModel: SessionTableViewModel, NavigationItemSource, Navi return "off".localized() } - return "disappearingMessagesDisappear" - .put(key: "disappearing_messages_type", value: (current.disappearingMessagesConfig.type?.localizedName ?? "")) - .put(key: "time", value: current.disappearingMessagesConfig.durationString) - .localized() + return (current.disappearingMessagesConfig.type ?? .unknown) + .localizedState( + durationString: current.disappearingMessagesConfig.durationString + ) }(), accessibility: Accessibility( identifier: "Disappearing messages", diff --git a/Session/Conversations/Views & Modals/ConversationTitleView.swift b/Session/Conversations/Views & Modals/ConversationTitleView.swift index 7824d4532..fa66701c1 100644 --- a/Session/Conversations/Views & Modals/ConversationTitleView.swift +++ b/Session/Conversations/Views & Modals/ConversationTitleView.swift @@ -233,10 +233,10 @@ final class ConversationTitleView: UIView { attributedText: NSAttributedString(attachment: imageAttachment) .appending(string: " ") .appending( - string: "disappearingMessagesDisappear" - .put(key: "disappearing_messages_type", value: (config.type?.localizedName ?? "")) - .put(key: "time", value: floor(config.durationSeconds).formatted(format: .short)) - .localized() + string: (config.type ?? .unknown) + .localizedState( + durationString: floor(config.durationSeconds).formatted(format: .short) + ) ), accessibility: Accessibility( identifier: "Disappearing messages type and time", diff --git a/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift b/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift index f0e92f4d4..b055f4ea0 100644 --- a/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift +++ b/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift @@ -83,6 +83,21 @@ public struct DisappearingMessagesConfiguration: Codable, Identifiable, Equatabl case .disappearAfterSend: return CONVO_EXPIRATION_AFTER_SEND } } + + public func localizedState(durationString: String) -> String { + switch self { + case .unknown: + return "" + case .disappearAfterRead: + return "disappearingMessagesDisappearAfterReadState" + .put(key: "time", value: durationString) + .localized() + case .disappearAfterSend: + return "disappearingMessagesDisappearAfterSendState" + .put(key: "time", value: durationString) + .localized() + } + } } public var id: String { threadId } // Identifiable