From c54e9fbedfd0b94a6a810089ca7af849866e98f3 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 29 Aug 2025 23:34:46 +0400 Subject: [PATCH] Various fixes --- .../TelegramEngine/Themes/ChatThemes.swift | 16 ++-- .../Components/Gifts/GiftViewScreen/BUILD | 1 + .../Sources/GiftViewScreen.swift | 82 ++++++++++++++----- .../Sources/Panes/PeerInfoMembersPane.swift | 15 +++- 4 files changed, 83 insertions(+), 31 deletions(-) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift b/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift index ee07d49015..d946ce72ca 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift @@ -104,20 +104,20 @@ public enum ChatTheme: PostboxCoding, Codable, Equatable { } else { return false } - case let .gift(lhsGift, _): - if case let .gift(rhsGift, _) = rhs { + case let .gift(lhsGift, lhsThemeSettings): + if case let .gift(rhsGift, rhsThemeSettings) = rhs { switch lhsGift { - case .generic(let lhsGeneric): + case let .generic(lhsGeneric): switch rhsGift { - case .generic(let rhsGeneric): - return lhsGeneric == rhsGeneric + case let .generic(rhsGeneric): + return lhsGeneric == rhsGeneric && lhsThemeSettings == rhsThemeSettings default: return false } - case .unique(let lhsUnique): + case let .unique(lhsUnique): switch rhsGift { - case .unique(let rhsUnique): - return lhsUnique.slug == rhsUnique.slug + case let .unique(rhsUnique): + return lhsUnique.slug == rhsUnique.slug && lhsThemeSettings == rhsThemeSettings default: return false } diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/BUILD b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/BUILD index 9e0aca1b52..47ded4318a 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/BUILD +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/BUILD @@ -53,6 +53,7 @@ swift_library( "//submodules/ActivityIndicator", "//submodules/TelegramUI/Components/TabSelectorComponent", "//submodules/TelegramUI/Components/Stars/BalanceNeededScreen", + "//submodules/TelegramUI/Components/ChatThemeScreen", "//submodules/ImageBlur", ], visibility = [ diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift index ae78039072..d23dbbed52 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift @@ -36,6 +36,7 @@ import StarsBalanceOverlayComponent import BalanceNeededScreen import GiftItemComponent import GiftAnimationComponent +import ChatThemeScreen private final class GiftViewSheetContent: CombinedComponent { typealias EnvironmentType = ViewControllerComponentContainer.Environment @@ -809,27 +810,66 @@ private final class GiftViewSheetContent: CombinedComponent { } let context = self.context - let peerController = self.context.sharedContext.makePeerSelectionController(PeerSelectionControllerParams(context: self.context, filter: [.excludeRecent, .doNotSearchMessages], requestPeerType: [.user(.init(isBot: false, isPremium: false))], hasContactSelector: false, hasCreation: false)) + + let themePeerId = Promise() + themePeerId.set( + .single(gift.themePeerId) + |> then( + context.engine.payments.getUniqueStarGift(slug: gift.slug) + |> map { gift in + return gift?.themePeerId + } + ) + ) + + let peerController = context.sharedContext.makePeerSelectionController(PeerSelectionControllerParams(context: context, filter: [.excludeRecent, .doNotSearchMessages], requestPeerType: [.user(.init(isBot: false, isPremium: nil))], hasContactSelector: false, hasCreation: false)) peerController.peerSelected = { [weak peerController, weak navigationController] peer, _ in - let _ = context.engine.themes.setChatTheme(peerId: peer.id, chatTheme: .gift(.unique(gift), [])).start() - peerController?.dismiss() - if let navigationController { - context.sharedContext.navigateToChatController(NavigateToChatControllerParams( - navigationController: navigationController, - chatController: nil, - context: context, - chatLocation: .peer(peer), - subject: nil, - botStart: nil, - updateTextInputState: nil, - keepStack: .always, - useExisting: true, - purposefulAction: nil, - scrollToEndIfExists: false, - activateMessageSearch: nil, - animated: true - )) + let proceed = { + let _ = context.engine.themes.setChatTheme(peerId: peer.id, chatTheme: .gift(.unique(gift), [])).start() + peerController?.dismiss() + + context.sharedContext.navigateToChatController(NavigateToChatControllerParams( + navigationController: navigationController, + chatController: nil, + context: context, + chatLocation: .peer(peer), + subject: nil, + botStart: nil, + updateTextInputState: nil, + keepStack: .always, + useExisting: true, + purposefulAction: nil, + scrollToEndIfExists: false, + activateMessageSearch: nil, + animated: true + )) + } + + let _ = (themePeerId.get() + |> deliverOnMainQueue + |> take(1)).start(next: { [weak navigationController] themePeerId in + if let themePeerId, themePeerId != peer.id { + let _ = (context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: themePeerId)) + |> deliverOnMainQueue).start(next: { [weak navigationController] peer in + guard let peer else { + proceed() + return + } + let controller = giftThemeTransferAlertController( + context: context, + gift: gift, + previousPeer: peer, + commit: { + proceed() + } + ) + (navigationController?.viewControllers.last as? ViewController)?.present(controller, in: .window(.root)) + }) + } else { + proceed() + } + }) } } self.dismiss(animated: true) @@ -3278,8 +3318,8 @@ private final class GiftViewSheetContent: CombinedComponent { component: PlainButtonComponent( content: AnyComponent( HeaderButtonComponent( - title: uniqueGift.resellAmounts == nil ? strings.Gift_View_Sell : strings.Gift_View_Unlist, - iconName: uniqueGift.resellAmounts == nil ? "Premium/Collectible/Sell" : "Premium/Collectible/Unlist" + title: (uniqueGift.resellAmounts ?? []).isEmpty ? strings.Gift_View_Sell : strings.Gift_View_Unlist, + iconName: (uniqueGift.resellAmounts ?? []).isEmpty ? "Premium/Collectible/Sell" : "Premium/Collectible/Unlist" ) ), effectAlignment: .center, diff --git a/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/Panes/PeerInfoMembersPane.swift b/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/Panes/PeerInfoMembersPane.swift index ba9e3802b9..e7ce0f314a 100644 --- a/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/Panes/PeerInfoMembersPane.swift +++ b/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/Panes/PeerInfoMembersPane.swift @@ -127,7 +127,7 @@ private enum PeerMembersListEntry: Comparable, Identifiable { })) } - let presence: EnginePeer.Presence + var presence: EnginePeer.Presence if member.peer.id == context.account.peerId { presence = EnginePeer.Presence(status: .present(until: Int32.max), lastActivity: 0) } else if let value = member.presence { @@ -136,6 +136,17 @@ private enum PeerMembersListEntry: Comparable, Identifiable { presence = EnginePeer.Presence(status: .longTimeAgo, lastActivity: 0) } + var status: ContactsPeerItemStatus = .presence(presence, presentationData.dateTimeFormat) + if let user = member.peer as? TelegramUser, let botInfo = user.botInfo { + let botStatus: String + if botInfo.flags.contains(.hasAccessToChatHistory) { + botStatus = presentationData.strings.Bot_GroupStatusReadsHistory + } else { + botStatus = presentationData.strings.Bot_GroupStatusDoesNotReadHistory + } + status = .custom(string: NSAttributedString(string: botStatus, font: Font.regular(floor(presentationData.listsFontSize.itemListBaseFontSize * 14.0 / 17.0)), textColor: presentationData.theme.list.itemSecondaryTextColor), multiline: false, isActive: false, icon: nil) + } + return ContactsPeerItem( presentationData: ItemListPresentationData(presentationData), style: .plain, @@ -145,7 +156,7 @@ private enum PeerMembersListEntry: Comparable, Identifiable { context: context, peerMode: .memberList, peer: .peer(peer: EnginePeer(member.peer), chatPeer: EnginePeer(member.peer)), - status: .presence(presence, presentationData.dateTimeFormat), + status: status, rightLabelText: label, enabled: true, selection: .none,