From 2adffc2ebc3a6f654224ecd4ca79cfa5a6e577a6 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 1 Mar 2025 20:29:28 +0400 Subject: [PATCH] Various fixes --- .../IncomingMessagePrivacyScreen.swift | 2 +- .../PrivacyAndSecurityController.swift | 8 +++++-- .../Sources/StarsImageComponent.swift | 11 ++------- .../Sources/StarsTransactionScreen.swift | 23 +++++++++++++++---- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/submodules/SettingsUI/Sources/Privacy and Security/IncomingMessagePrivacyScreen.swift b/submodules/SettingsUI/Sources/Privacy and Security/IncomingMessagePrivacyScreen.swift index 0d6a43f888..3ab7c7b914 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/IncomingMessagePrivacyScreen.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/IncomingMessagePrivacyScreen.swift @@ -346,7 +346,7 @@ public func incomingMessagePrivacyScreen(context: AccountContext, value: GlobalP updateState { state in var updatedState = state updatedState.disableFor = updatedPeerIds - return state + return updatedState } let settings: SelectivePrivacySettings = .enableContacts(enableFor: updatedPeerIds, disableFor: [:], enableForPremium: false, enableForBots: false) let _ = context.engine.privacy.updateSelectiveAccountPrivacySettings(type: .noPaidMessages, settings: settings).start() diff --git a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift index 28784bb729..5647dd2603 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift @@ -432,7 +432,11 @@ private enum PrivacyAndSecurityEntry: ItemListNodeEntry { }) case let .messagePrivacy(theme, value, hasPremium): let label: String - switch value { + var effectiveValue = value + if !hasPremium { + effectiveValue = .everybody + } + switch effectiveValue { case .everybody: label = presentationData.strings.Settings_Privacy_Messages_ValueEveryone case .requirePremium: @@ -669,7 +673,7 @@ private func privacyAndSecurityControllerEntries( entries.append(.forwardPrivacy(presentationData.theme, presentationData.strings.Privacy_Forwards, stringForSelectiveSettings(strings: presentationData.strings, settings: privacySettings.forwards))) entries.append(.voiceCallPrivacy(presentationData.theme, presentationData.strings.Privacy_Calls, stringForSelectiveSettings(strings: presentationData.strings, settings: privacySettings.voiceCalls))) if !isPremiumDisabled || isPremium { - entries.append(.voiceMessagePrivacy(presentationData.theme, presentationData.strings.Privacy_VoiceMessages, stringForSelectiveSettings(strings: presentationData.strings, settings: privacySettings.voiceMessages), isPremium)) + entries.append(.voiceMessagePrivacy(presentationData.theme, presentationData.strings.Privacy_VoiceMessages, stringForSelectiveSettings(strings: presentationData.strings, settings: isPremium ? privacySettings.voiceMessages : .enableEveryone(disableFor: [:])), isPremium)) entries.append(.messagePrivacy(presentationData.theme, privacySettings.globalSettings.nonContactChatsPrivacy, isPremium)) } entries.append(.groupPrivacy(presentationData.theme, presentationData.strings.PrivacySettings_InviteItem, stringForSelectiveSettings(strings: presentationData.strings, settings: privacySettings.groupInvitations))) diff --git a/submodules/TelegramUI/Components/Stars/StarsImageComponent/Sources/StarsImageComponent.swift b/submodules/TelegramUI/Components/Stars/StarsImageComponent/Sources/StarsImageComponent.swift index 8e4fb473f6..1fb207d8a0 100644 --- a/submodules/TelegramUI/Components/Stars/StarsImageComponent/Sources/StarsImageComponent.swift +++ b/submodules/TelegramUI/Components/Stars/StarsImageComponent/Sources/StarsImageComponent.swift @@ -253,7 +253,7 @@ public final class StarsImageComponent: Component { case media([AnyMediaReference]) case extendedMedia([TelegramExtendedMedia]) case transactionPeer(StarsContext.State.Transaction.Peer) - case gift(Int64) + case gift(Int32) case color(UIColor) public static func == (lhs: StarsImageComponent.Subject, rhs: StarsImageComponent.Subject) -> Bool { @@ -850,14 +850,7 @@ public final class StarsImageComponent: Component { if let current = self.animationNode { animationNode = current } else { - let stickerName: String - if count <= 1000 { - stickerName = "Gift3" - } else if count < 2500 { - stickerName = "Gift6" - } else { - stickerName = "Gift12" - } + let stickerName: String = "Gift\(count)" animationNode = DefaultAnimatedStickerNodeImpl() animationNode.autoplay = true animationNode.setup(source: AnimatedStickerNodeLocalFileSource(name: stickerName), width: 384, height: 384, playbackMode: .still(.end), mode: .direct(cachePathPrefix: nil)) diff --git a/submodules/TelegramUI/Components/Stars/StarsTransactionScreen/Sources/StarsTransactionScreen.swift b/submodules/TelegramUI/Components/Stars/StarsTransactionScreen/Sources/StarsTransactionScreen.swift index 866ea7e55a..39de43b8ec 100644 --- a/submodules/TelegramUI/Components/Stars/StarsTransactionScreen/Sources/StarsTransactionScreen.swift +++ b/submodules/TelegramUI/Components/Stars/StarsTransactionScreen/Sources/StarsTransactionScreen.swift @@ -243,6 +243,7 @@ private final class StarsTransactionSheetContent: CombinedComponent { var giftAvailability: StarGift.Gift.Availability? var isRefProgram = false var isPaidMessage = false + var premiumGiftMonths: Int32? var delayedCloseOnOpenPeer = true switch subject { @@ -456,6 +457,7 @@ private final class StarsTransactionSheetContent: CombinedComponent { switch transaction.peer { case let .peer(peer): if let months = transaction.premiumGiftMonths { + premiumGiftMonths = months titleText = strings.Stars_Transaction_TelegramPremium(months) } else if transaction.flags.contains(.isPaidMessage) { isPaidMessage = true @@ -679,8 +681,18 @@ private final class StarsTransactionSheetContent: CombinedComponent { let imageSubject: StarsImageComponent.Subject var imageIcon: StarsImageComponent.Icon? - if isGift { - imageSubject = .gift(count.value) + if let premiumGiftMonths { + imageSubject = .gift(premiumGiftMonths) + } else if isGift { + var value: Int32 = 3 + if count.value <= 1000 { + value = 3 + } else if count.value < 2500 { + value = 6 + } else { + value = 12 + } + imageSubject = .gift(value) } else if !media.isEmpty { imageSubject = .media(media) } else if let photo { @@ -1852,13 +1864,16 @@ public class StarsTransactionScreen: ViewControllerComponentContainer { guard let self, let navigationController = self.navigationController as? NavigationController else { return } - self.dismissAnimated() let _ = (context.engine.privacy.requestAccountPrivacySettings() - |> deliverOnMainQueue).start(next: { [weak navigationController] privacySettings in + |> deliverOnMainQueue).start(next: { [weak self, weak navigationController] privacySettings in let controller = context.sharedContext.makeIncomingMessagePrivacyScreen(context: context, value: privacySettings.globalSettings.nonContactChatsPrivacy, exceptions: privacySettings.noPaidMessages, update: { settingValue in let _ = context.engine.privacy.updateNonContactChatsPrivacy(value: settingValue).start() }) navigationController?.pushViewController(controller) + + Queue.mainQueue().after(0.6) { + self?.dismissAnimated() + } }) }