From bdaf5f5a020829452ea6bd1c518f487e89aa04b8 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Mon, 18 Aug 2025 17:33:54 +0400 Subject: [PATCH] Various fixes --- .../Sources/AccountContext.swift | 1 + .../Sources/ListMessageFileItemNode.swift | 4 +-- .../ExternalMusicAlbumArtResources.swift | 2 +- .../ChatRecentActionsControllerNode.swift | 2 ++ .../Sources/TabSelectorComponent.swift | 3 +- .../TelegramUI/Sources/OpenResolvedUrl.swift | 14 +++++++++ submodules/TelegramUI/Sources/OpenUrl.swift | 31 +++++++++++++++++++ 7 files changed, 52 insertions(+), 5 deletions(-) diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index 22bd0501b8..e186981260 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -333,6 +333,7 @@ public enum ResolvedUrl { case shareStory(Int64) case storyFolder(peerId: PeerId, id: Int64) case giftCollection(peerId: PeerId, id: Int64) + case sendGift(peerId: PeerId?) } public enum ResolveUrlResult { diff --git a/submodules/ListMessageItem/Sources/ListMessageFileItemNode.swift b/submodules/ListMessageItem/Sources/ListMessageFileItemNode.swift index 7b4fe7a8b6..d72686925c 100644 --- a/submodules/ListMessageItem/Sources/ListMessageFileItemNode.swift +++ b/submodules/ListMessageItem/Sources/ListMessageFileItemNode.swift @@ -676,8 +676,8 @@ public final class ListMessageFileItemNode: ListMessageNode { } if descriptionString.isEmpty { descriptionString = authorString.first ?? "" - } else { - descriptionString = "\(descriptionString) • \(authorString.first ?? "")" + } else if let authorStringFirst = authorString.first { + descriptionString = "\(descriptionString) • \(authorStringFirst)" } } diff --git a/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift b/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift index 9949f1a771..755c5137b8 100644 --- a/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift +++ b/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift @@ -16,7 +16,7 @@ public struct ExternalMusicAlbumArtResourceId { } public var uniqueId: String { - return "ext-album-art-\(isThumbnail ? "thump" : "full")-\(self.title.replacingOccurrences(of: "/", with: "_"))-\(self.performer.replacingOccurrences(of: "/", with: "_"))" + return "ext-album-art-\(self.isThumbnail ? "thumb" : "full")-\(self.title.replacingOccurrences(of: "/", with: "_"))-\(self.performer.replacingOccurrences(of: "/", with: "_"))" } public var hashValue: Int { diff --git a/submodules/TelegramUI/Components/Chat/ChatRecentActionsController/Sources/ChatRecentActionsControllerNode.swift b/submodules/TelegramUI/Components/Chat/ChatRecentActionsController/Sources/ChatRecentActionsControllerNode.swift index 165f79ffa2..e5349d58ed 100644 --- a/submodules/TelegramUI/Components/Chat/ChatRecentActionsController/Sources/ChatRecentActionsControllerNode.swift +++ b/submodules/TelegramUI/Components/Chat/ChatRecentActionsController/Sources/ChatRecentActionsControllerNode.swift @@ -1462,6 +1462,8 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { break case .giftCollection: break + case .sendGift: + break } } })) diff --git a/submodules/TelegramUI/Components/TabSelectorComponent/Sources/TabSelectorComponent.swift b/submodules/TelegramUI/Components/TabSelectorComponent/Sources/TabSelectorComponent.swift index ad5852a1aa..f6bfb5ca17 100644 --- a/submodules/TelegramUI/Components/TabSelectorComponent/Sources/TabSelectorComponent.swift +++ b/submodules/TelegramUI/Components/TabSelectorComponent/Sources/TabSelectorComponent.swift @@ -633,8 +633,7 @@ public final class TabSelectorComponent: Component { let estimatedContentWidth = 2.0 * spacing + innerContentWidth + (CGFloat(component.items.count - 1) * (spacing + innerInset)) if component.customLayout?.fillWidth == true && estimatedContentWidth < availableSize.width { - spacing = (availableSize.width - innerContentWidth) / CGFloat(component.items.count + 1) - innerInset = 0.0 + spacing = (availableSize.width - innerContentWidth) / CGFloat(component.items.count + 1) - innerInset * 2.0 } else if estimatedContentWidth > availableSize.width && !allowScroll { spacing = (availableSize.width - innerContentWidth) / CGFloat(component.items.count + 1) innerInset = 0.0 diff --git a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift index fdfaf5add1..faa42dd134 100644 --- a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift @@ -1549,5 +1549,19 @@ func openResolvedUrlImpl( } navigationController?.pushViewController(controller) } + case let .sendGift(peerId): + Task { @MainActor [weak navigationController] in + if let peerId { + let giftOptions = await (context.engine.payments.premiumGiftCodeOptions(peerId: nil, onlyCached: true) |> filter { !$0.isEmpty }).get() + + let premiumOptions = giftOptions.filter { $0.users == 1 }.map { CachedPremiumGiftOption(months: $0.months, currency: $0.currency, amount: $0.amount, botUrl: "", storeProductId: $0.storeProductId) } + let controller = context.sharedContext.makeGiftOptionsController(context: context, peerId: peerId, premiumOptions: premiumOptions, hasBirthday: false, completion: nil) + controller.navigationPresentation = .modal + navigationController?.pushViewController(controller) + } else { + let controller = context.sharedContext.makePremiumGiftController(context: context, source: .settings(nil), completion: nil) + navigationController?.pushViewController(controller) + } + } } } diff --git a/submodules/TelegramUI/Sources/OpenUrl.swift b/submodules/TelegramUI/Sources/OpenUrl.swift index 0290a0d907..12c79166cd 100644 --- a/submodules/TelegramUI/Sources/OpenUrl.swift +++ b/submodules/TelegramUI/Sources/OpenUrl.swift @@ -1037,6 +1037,35 @@ func openExternalUrlImpl(context: AccountContext, urlContext: OpenURLContext, ur } } } + } else if parsedUrl.host == "send_gift" { + var recipient: String? + if let components = URLComponents(string: "/?" + query) { + if let queryItems = components.queryItems { + for queryItem in queryItems { + if let value = queryItem.value { + if queryItem.name == "to" { + recipient = value + break + } + } + } + } + } + if let recipient { + if let id = Int64(recipient) { + handleResolvedUrl(.sendGift(peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(id)))) + } else { + let _ = (context.engine.peers.resolvePeerByName(name: recipient, referrer: nil) + |> deliverOnMainQueue).start(next: { result in + guard case let .result(peer) = result, let peer else { + return + } + handleResolvedUrl(.sendGift(peerId: peer.id)) + }) + } + } else { + handleResolvedUrl(.sendGift(peerId: nil)) + } } } else { if parsedUrl.host == "stars" { @@ -1087,6 +1116,8 @@ func openExternalUrlImpl(context: AccountContext, urlContext: OpenURLContext, ur context.sharedContext.presentGlobalController(alertController, nil) } }) + } else if parsedUrl.host == "send_gift" { + handleResolvedUrl(.sendGift(peerId: nil)) } }