From 784b43934a3d952fedd106b08673d7f8c1c7cbb9 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 27 Mar 2026 22:59:36 +0100 Subject: [PATCH] Update text styles data --- .../TelegramEngine/Messages/Translate.swift | 18 +++++++------- ...ProcessingLanguageSelectionComponent.swift | 15 ++++-------- .../Sources/TextProcessingScreen.swift | 16 ++++++------- ...extProcessingStyleSelectionComponent.swift | 24 ++----------------- ...tProcessingTranslateContentComponent.swift | 4 ++-- 5 files changed, 25 insertions(+), 52 deletions(-) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/Translate.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Translate.swift index ee447599d6..42cd3a48d1 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/Translate.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Translate.swift @@ -415,17 +415,17 @@ public enum TelegramComposeAIMessageMode { } public struct Style: Equatable { - public let name: String - public let emoji: String + public let type: String + public let title: String public let emojiFileId: Int64? public var id: StyleId { - return .style(self.name) + return .style(self.type) } - public init(name: String, emoji: String, emojiFileId: Int64?) { - self.name = name - self.emoji = emoji + public init(type: String, title: String, emojiFileId: Int64?) { + self.type = type + self.title = title self.emojiFileId = emojiFileId } } @@ -459,9 +459,9 @@ func _internal_composeAIMessageStyles(account: Account) -> Signal<[TelegramCompo var result: [TelegramComposeAIMessageMode.Style] = [] if let data = currentAppConfiguration(transaction: transaction).data, let value = data["ai_compose_styles"] as? [[String]] { for item in value { - if item.count >= 2 { - let emojiFileId: Int64? = item.count > 2 ? Int64(item[2]) : nil - result.append(TelegramComposeAIMessageMode.Style(name: item[1], emoji: item[0], emojiFileId: emojiFileId)) + if item.count >= 3 { + let emojiFileId: Int64? = Int64(item[1]) + result.append(TelegramComposeAIMessageMode.Style(type: item[0], title: item[2], emojiFileId: emojiFileId)) } } } diff --git a/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingLanguageSelectionComponent.swift b/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingLanguageSelectionComponent.swift index fb3d20a3cd..5a992b9db6 100644 --- a/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingLanguageSelectionComponent.swift +++ b/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingLanguageSelectionComponent.swift @@ -475,10 +475,10 @@ final class TextProcessingLanguageSelectionComponent: Component { var selectedStyleItemFrame: CGRect? let stylesSpacing: CGFloat = 8.0 if let displayStyles = component.displayStyles { - var styleData: [(id: TelegramComposeAIMessageMode.StyleId, icon: String, iconFileId: Int64?, iconFile: TelegramMediaFile?, title: String)] = [] - styleData.append((.neutral, "🏳️", nil, nil, localizedStyleName(strings: component.strings, styleId: .neutral))) + var styleData: [(id: TelegramComposeAIMessageMode.StyleId, iconFileId: Int64?, iconFile: TelegramMediaFile?, title: String)] = [] + styleData.append((.neutral, nil, nil, component.strings.TextProcessingStyle_Neutral)) for item in displayStyles { - styleData.append((item.id, item.emoji, item.emojiFileId, item.emojiFile, localizedStyleName(strings: component.strings, styleId: item.id))) + styleData.append((item.id, item.emojiFileId, item.emojiFile, item.title)) } let stylesItemSize = CGSize(width: 82.0, height: 60.0) @@ -500,7 +500,6 @@ final class TextProcessingLanguageSelectionComponent: Component { component: AnyComponent(StyleItemComponent( context: component.context, theme: component.theme, - icon: item.icon, iconFileId: item.iconFileId, iconFile: item.iconFile, title: item.title, @@ -854,7 +853,6 @@ private final class LanguageItemComponent: Component { private final class StyleItemComponent: Component { let context: AccountContext let theme: PresentationTheme - let icon: String let iconFileId: Int64? let iconFile: TelegramMediaFile? let title: String @@ -863,7 +861,6 @@ private final class StyleItemComponent: Component { init( context: AccountContext, theme: PresentationTheme, - icon: String, iconFileId: Int64?, iconFile: TelegramMediaFile?, title: String, @@ -871,7 +868,6 @@ private final class StyleItemComponent: Component { ) { self.context = context self.theme = theme - self.icon = icon self.iconFileId = iconFileId self.iconFile = iconFile self.title = title @@ -882,9 +878,6 @@ private final class StyleItemComponent: Component { if lhs.theme !== rhs.theme { return false } - if lhs.icon != rhs.icon { - return false - } if lhs.iconFileId != rhs.iconFileId { return false } @@ -973,7 +966,7 @@ private final class StyleItemComponent: Component { )) } else { iconComponent = AnyComponent(MultilineTextComponent( - text: .plain(NSAttributedString(string: component.icon, font: Font.regular(25.0), textColor: .black)) + text: .plain(NSAttributedString(string: "❌", font: Font.regular(25.0), textColor: .black)) )) } diff --git a/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingScreen.swift b/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingScreen.swift index db3c9e4245..47168fe6e1 100644 --- a/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingScreen.swift +++ b/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingScreen.swift @@ -1065,18 +1065,18 @@ public class TextProcessingScreen: ViewControllerComponentContainer { } public struct Style: Equatable { - public let name: String - public let emoji: String + public let type: String + public let title: String public let emojiFileId: Int64? public let emojiFile: TelegramMediaFile? public var id: TelegramComposeAIMessageMode.StyleId { - return .style(self.name) + return .style(self.type) } - public init(name: String, emoji: String, emojiFileId: Int64?, emojiFile: TelegramMediaFile?) { - self.name = name - self.emoji = emoji + public init(type: String, title: String, emojiFileId: Int64?, emojiFile: TelegramMediaFile?) { + self.type = type + self.title = title self.emojiFileId = emojiFileId self.emojiFile = emojiFile } @@ -1100,8 +1100,8 @@ public class TextProcessingScreen: ViewControllerComponentContainer { let resolvedEmojiFiles: [Int64: TelegramMediaFile] = await context.engine.stickers.resolveInlineStickersLocal(fileIds: Array(Set(rawStyles.compactMap({ $0.emojiFileId })))).get() for value in rawStyles { styles.append(Style( - name: value.name, - emoji: value.emoji, + type: value.type, + title: value.title, emojiFileId: value.emojiFileId, emojiFile: value.emojiFileId.flatMap { resolvedEmojiFiles[$0] } )) diff --git a/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingStyleSelectionComponent.swift b/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingStyleSelectionComponent.swift index 566eb50b2f..7cdaccce1b 100644 --- a/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingStyleSelectionComponent.swift +++ b/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingStyleSelectionComponent.swift @@ -8,19 +8,6 @@ import TelegramCore import EmojiStatusComponent import AccountContext -func localizedStyleName(strings: PresentationStrings, styleId: TelegramComposeAIMessageMode.StyleId) -> String { - switch styleId { - case .neutral: - return strings.TextProcessingStyle_Neutral - case let .style(name): - if let value = strings.primaryComponent.dict["TextProcessingStyle.\(name)"] { - return value - } else { - return name.capitalized - } - } -} - final class TextProcessingStyleSelectionComponent: Component { let context: AccountContext let theme: PresentationTheme @@ -160,10 +147,9 @@ final class TextProcessingStyleSelectionComponent: Component { component: AnyComponent(ItemComponent( context: component.context, theme: component.theme, - icon: style.emoji, iconFileId: style.emojiFileId, iconFile: style.emojiFile, - title: localizedStyleName(strings: component.strings, styleId: .style(style.name)) + title: style.title )), environment: {}, containerSize: CGSize(width: maxItemWidth, height: availableSize.height) @@ -272,7 +258,6 @@ final class TextProcessingStyleSelectionComponent: Component { private final class ItemComponent: Component { let context: AccountContext let theme: PresentationTheme - let icon: String let iconFileId: Int64? let iconFile: TelegramMediaFile? let title: String @@ -280,14 +265,12 @@ private final class ItemComponent: Component { init( context: AccountContext, theme: PresentationTheme, - icon: String, iconFileId: Int64?, iconFile: TelegramMediaFile?, title: String ) { self.context = context self.theme = theme - self.icon = icon self.iconFileId = iconFileId self.iconFile = iconFile self.title = title @@ -297,9 +280,6 @@ private final class ItemComponent: Component { if lhs.theme !== rhs.theme { return false } - if lhs.icon != rhs.icon { - return false - } if lhs.iconFileId != rhs.iconFileId { return false } @@ -377,7 +357,7 @@ private final class ItemComponent: Component { )) } else { iconComponent = AnyComponent(MultilineTextComponent( - text: .plain(NSAttributedString(string: component.icon, font: Font.regular(25.0), textColor: .black)) + text: .plain(NSAttributedString(string: "❌", font: Font.regular(25.0), textColor: .black)) )) } diff --git a/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingTranslateContentComponent.swift b/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingTranslateContentComponent.swift index 5fd3943ee1..0c4436537f 100644 --- a/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingTranslateContentComponent.swift +++ b/submodules/TelegramUI/Components/TextProcessingScreen/Sources/TextProcessingTranslateContentComponent.swift @@ -311,8 +311,8 @@ final class TextProcessingTranslateContentComponent: Component { fromFormat = component.strings.TextProcessing_Translate_FromLanguage toFormat = component.strings.TextProcessing_Translate_ToLanguage toTitle = localizedLanguageName(strings: component.strings, language: component.externalState.result?.language ?? "", kind: .translateTo) - if case .style = component.externalState.style { - toTitle = component.strings.TextProcessing_Translate_LanguageStyle(toTitle, localizedStyleName(strings: component.strings, styleId: component.externalState.style)).string + if case .style = component.externalState.style, let styleTitle = component.styles.first(where: { $0.id == component.externalState.style })?.title { + toTitle = component.strings.TextProcessing_Translate_LanguageStyle(toTitle, styleTitle).string } case .stylize, .fix: fromFormat = component.strings.TextProcessing_OriginalBadge