From eaf6a69cfbea60fcecf6bb98b1a031c5717ed6c3 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 11 Jun 2022 14:38:44 +0400 Subject: [PATCH] Various fixes --- .../Telegram-iOS/en.lproj/Localizable.strings | 4 +++ .../Sources/InAppPurchaseManager.swift | 36 ++++++++++--------- .../Sources/ChatAvatarNavigationNode.swift | 2 +- .../Sources/ChatMessageDateHeader.swift | 2 +- submodules/TelegramUI/Sources/OpenUrl.swift | 15 ++++++++ 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 3745e0790a..619b58a565 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -7722,6 +7722,10 @@ Sorry for the inconvenience."; "Premium.Purchase.ErrorNotAllowed" = "The device is not not allowed to make the payment."; "Premium.Purchase.ErrorCantMakePayments" = "In-app purchases are not allowed on this device."; +"Premium.Restore.Success" = "Done"; +"Premium.Restore.ErrorUnknown" = "An error occurred. Please try again."; + + "Settings.Premium" = "Telegram Premium"; "Settings.AddAnotherAccount.PremiumHelp" = "You can add up to four accounts with different phone numbers."; diff --git a/submodules/InAppPurchaseManager/Sources/InAppPurchaseManager.swift b/submodules/InAppPurchaseManager/Sources/InAppPurchaseManager.swift index b1df3d7b7a..594272e10b 100644 --- a/submodules/InAppPurchaseManager/Sources/InAppPurchaseManager.swift +++ b/submodules/InAppPurchaseManager/Sources/InAppPurchaseManager.swift @@ -276,27 +276,31 @@ extension InAppPurchaseManager: SKPaymentTransactionObserver { } public func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) { - if let onRestoreCompletion = self.onRestoreCompletion { - Logger.shared.log("InAppPurchaseManager", "Transactions restoration finished") - onRestoreCompletion(.succeed) - self.onRestoreCompletion = nil - - if let receiptData = getReceiptData() { - self.disposableSet.set( - self.engine.payments.sendAppStoreReceipt(receipt: receiptData, restore: true).start(completed: { - Logger.shared.log("InAppPurchaseManager", "Sent restored receipt") - }), - forKey: "restore" - ) + Queue.mainQueue().async { + if let onRestoreCompletion = self.onRestoreCompletion { + Logger.shared.log("InAppPurchaseManager", "Transactions restoration finished") + onRestoreCompletion(.succeed) + self.onRestoreCompletion = nil + + if let receiptData = getReceiptData() { + self.disposableSet.set( + self.engine.payments.sendAppStoreReceipt(receipt: receiptData, restore: true).start(completed: { + Logger.shared.log("InAppPurchaseManager", "Sent restored receipt") + }), + forKey: "restore" + ) + } } } } public func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) { - if let onRestoreCompletion = self.onRestoreCompletion { - Logger.shared.log("InAppPurchaseManager", "Transactions restoration failed with error \((error as? SKError)?.localizedDescription ?? "")") - onRestoreCompletion(.failed) - self.onRestoreCompletion = nil + Queue.mainQueue().async { + if let onRestoreCompletion = self.onRestoreCompletion { + Logger.shared.log("InAppPurchaseManager", "Transactions restoration failed with error \((error as? SKError)?.localizedDescription ?? "")") + onRestoreCompletion(.failed) + self.onRestoreCompletion = nil + } } } } diff --git a/submodules/TelegramUI/Sources/ChatAvatarNavigationNode.swift b/submodules/TelegramUI/Sources/ChatAvatarNavigationNode.swift index 97e5ca823d..90277dc65a 100644 --- a/submodules/TelegramUI/Sources/ChatAvatarNavigationNode.swift +++ b/submodules/TelegramUI/Sources/ChatAvatarNavigationNode.swift @@ -96,7 +96,7 @@ final class ChatAvatarNavigationNode: ASDisplayNode { if let photo = cachedPeerData.photo, let video = smallestVideoRepresentation(photo.videoRepresentations), let peerReference = PeerReference(peer._asPeer()) { let videoId = photo.id?.id ?? peer.id.id._internalGetInt64Value() let videoFileReference = FileMediaReference.avatarList(peer: peerReference, media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: 0), partialReference: nil, resource: video.resource, previewRepresentations: photo.representations, videoThumbnails: [], immediateThumbnailData: photo.immediateThumbnailData, mimeType: "video/mp4", size: nil, attributes: [.Animated, .Video(duration: 0, size: video.dimensions, flags: [])])) - let videoContent = NativeVideoContent(id: .profileVideo(videoId, nil), fileReference: videoFileReference, streamVideo: isMediaStreamable(resource: video.resource) ? .conservative : .none, loopVideo: true, enableSound: false, fetchAutomatically: true, onlyFullSizeThumbnail: false, useLargeThumbnail: true, autoFetchFullSizeThumbnail: true, startTimestamp: video.startTimestamp, continuePlayingWithoutSoundOnLostAudioSession: false, placeholderColor: .clear, captureProtected: false) + let videoContent = NativeVideoContent(id: .profileVideo(videoId, "header"), fileReference: videoFileReference, streamVideo: isMediaStreamable(resource: video.resource) ? .conservative : .none, loopVideo: true, enableSound: false, fetchAutomatically: true, onlyFullSizeThumbnail: false, useLargeThumbnail: true, autoFetchFullSizeThumbnail: true, startTimestamp: video.startTimestamp, continuePlayingWithoutSoundOnLostAudioSession: false, placeholderColor: .clear, captureProtected: false) if videoContent.id != strongSelf.videoContent?.id { strongSelf.videoNode?.removeFromSupernode() strongSelf.videoContent = videoContent diff --git a/submodules/TelegramUI/Sources/ChatMessageDateHeader.swift b/submodules/TelegramUI/Sources/ChatMessageDateHeader.swift index b848d6ace2..52b374d55e 100644 --- a/submodules/TelegramUI/Sources/ChatMessageDateHeader.swift +++ b/submodules/TelegramUI/Sources/ChatMessageDateHeader.swift @@ -483,7 +483,7 @@ final class ChatMessageAvatarHeaderNode: ListViewItemHeaderNode { if let photo = cachedPeerData.photo, let video = photo.videoRepresentations.last, let peerReference = PeerReference(peer) { let videoId = photo.id?.id ?? peer.id.id._internalGetInt64Value() let videoFileReference = FileMediaReference.avatarList(peer: peerReference, media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: 0), partialReference: nil, resource: video.resource, previewRepresentations: photo.representations, videoThumbnails: [], immediateThumbnailData: photo.immediateThumbnailData, mimeType: "video/mp4", size: nil, attributes: [.Animated, .Video(duration: 0, size: video.dimensions, flags: [])])) - let videoContent = NativeVideoContent(id: .profileVideo(videoId, nil), fileReference: videoFileReference, streamVideo: isMediaStreamable(resource: video.resource) ? .conservative : .none, loopVideo: true, enableSound: false, fetchAutomatically: true, onlyFullSizeThumbnail: false, useLargeThumbnail: true, autoFetchFullSizeThumbnail: true, startTimestamp: video.startTimestamp, continuePlayingWithoutSoundOnLostAudioSession: false, placeholderColor: .clear, captureProtected: false) + let videoContent = NativeVideoContent(id: .profileVideo(videoId, "\(Int32.random(in: 0 ..< Int32.max))"), fileReference: videoFileReference, streamVideo: isMediaStreamable(resource: video.resource) ? .conservative : .none, loopVideo: true, enableSound: false, fetchAutomatically: true, onlyFullSizeThumbnail: false, useLargeThumbnail: true, autoFetchFullSizeThumbnail: true, startTimestamp: video.startTimestamp, continuePlayingWithoutSoundOnLostAudioSession: false, placeholderColor: .clear, captureProtected: false) if videoContent.id != strongSelf.videoContent?.id { strongSelf.videoNode?.removeFromSupernode() strongSelf.videoContent = videoContent diff --git a/submodules/TelegramUI/Sources/OpenUrl.swift b/submodules/TelegramUI/Sources/OpenUrl.swift index 310c76af18..e06417714c 100644 --- a/submodules/TelegramUI/Sources/OpenUrl.swift +++ b/submodules/TelegramUI/Sources/OpenUrl.swift @@ -763,6 +763,21 @@ func openExternalUrlImpl(context: AccountContext, urlContext: OpenURLContext, ur } } else if parsedUrl.host == "premium_offer" { handleResolvedUrl(.premiumOffer(reference: nil)) + } else if parsedUrl.host == "restore_purchases" { + context.inAppPurchaseManager?.restorePurchases(completion: { result in + let text: String + switch result { + case .succeed: + text = presentationData.strings.Premium_Restore_Success + case .failed: + text = presentationData.strings.Premium_Restore_ErrorUnknown + } + context.sharedContext.presentGlobalController(standardTextAlertController(theme: AlertControllerTheme(presentationData: presentationData), title: nil, text: text, actions: [ + TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: { + }), + ], parseMarkdown: true), nil) + + }) } }