From a22cf29e1905fe3de0a9c597b074c61475768670 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 21 Jun 2022 15:57:37 +0500 Subject: [PATCH 1/6] Various fixes --- .../Sources/Account/AccountManager.swift | 2 +- .../Sources/ApiUtils/BotInfo.swift | 2 +- .../ApiUtils/StoreMessage_Telegram.swift | 40 ++++++++++--------- .../Sources/ApiUtils/TelegramMediaFile.swift | 5 +-- .../PendingMessageUploadedContent.swift | 4 +- .../StandaloneUploadedMedia.swift | 4 +- .../State/AccountStateManagementUtils.swift | 6 ++- .../Sources/State/ApplyUpdateMessage.swift | 7 +++- .../SyncCore_NonPremiumMessageAttribute.swift | 16 ++++++++ .../TelegramEngineAccountData.swift | 4 -- .../AccountData/TermsOfService.swift | 6 --- .../Auth/TelegramEngineAuth.swift | 4 +- .../Sources/ApplicationContext.swift | 2 +- .../ChatMessageAnimatedStickerItemNode.swift | 16 ++++++-- 14 files changed, 71 insertions(+), 47 deletions(-) create mode 100644 submodules/TelegramCore/Sources/SyncCore/SyncCore_NonPremiumMessageAttribute.swift diff --git a/submodules/TelegramCore/Sources/Account/AccountManager.swift b/submodules/TelegramCore/Sources/Account/AccountManager.swift index 691717140c..49e753f554 100644 --- a/submodules/TelegramCore/Sources/Account/AccountManager.swift +++ b/submodules/TelegramCore/Sources/Account/AccountManager.swift @@ -188,7 +188,7 @@ private var declaredEncodables: Void = { declareEncodable(ForwardOptionsMessageAttribute.self, f: { ForwardOptionsMessageAttribute(decoder: $0) }) declareEncodable(SendAsMessageAttribute.self, f: { SendAsMessageAttribute(decoder: $0) }) declareEncodable(AudioTranscriptionMessageAttribute.self, f: { AudioTranscriptionMessageAttribute(decoder: $0) }) - + declareEncodable(NonPremiumMessageAttribute.self, f: { NonPremiumMessageAttribute(decoder: $0) }) return }() diff --git a/submodules/TelegramCore/Sources/ApiUtils/BotInfo.swift b/submodules/TelegramCore/Sources/ApiUtils/BotInfo.swift index e57e2dd6c4..7ee722d35d 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/BotInfo.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/BotInfo.swift @@ -18,7 +18,7 @@ extension BotInfo { switch apiBotInfo { case let .botInfo(_, _, description, descriptionPhoto, descriptionDocument, apiCommands, apiMenuButton): let photo: TelegramMediaImage? = descriptionPhoto.flatMap(telegramMediaImageFromApiPhoto) - let video: TelegramMediaFile? = descriptionDocument.flatMap { telegramMediaFileFromApiDocument($0, noPremium: false) } + let video: TelegramMediaFile? = descriptionDocument.flatMap(telegramMediaFileFromApiDocument) var commands: [BotCommand] = [] if let apiCommands = apiCommands { commands = apiCommands.map { command in diff --git a/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift b/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift index a9726d26a4..12a65b62e0 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift @@ -256,48 +256,48 @@ func apiMessageAssociatedMessageIds(_ message: Api.Message) -> [MessageId]? { return nil } -func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerId:PeerId) -> (Media?, Int32?) { +func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerId:PeerId) -> (Media?, Int32?, Bool?) { if let media = media { switch media { case let .messageMediaPhoto(_, photo, ttlSeconds): if let photo = photo { if let mediaImage = telegramMediaImageFromApiPhoto(photo) { - return (mediaImage, ttlSeconds) + return (mediaImage, ttlSeconds, nil) } } else { - return (TelegramMediaExpiredContent(data: .image), nil) + return (TelegramMediaExpiredContent(data: .image), nil, nil) } case let .messageMediaContact(phoneNumber, firstName, lastName, vcard, userId): let contactPeerId: PeerId? = userId == 0 ? nil : PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId)) let mediaContact = TelegramMediaContact(firstName: firstName, lastName: lastName, phoneNumber: phoneNumber, peerId: contactPeerId, vCardData: vcard.isEmpty ? nil : vcard) - return (mediaContact, nil) + return (mediaContact, nil, nil) case let .messageMediaGeo(geo): let mediaMap = telegramMediaMapFromApiGeoPoint(geo, title: nil, address: nil, provider: nil, venueId: nil, venueType: nil, liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil, heading: nil) - return (mediaMap, nil) + return (mediaMap, nil, nil) case let .messageMediaVenue(geo, title, address, provider, venueId, venueType): let mediaMap = telegramMediaMapFromApiGeoPoint(geo, title: title, address: address, provider: provider, venueId: venueId, venueType: venueType, liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil, heading: nil) - return (mediaMap, nil) + return (mediaMap, nil, nil) case let .messageMediaGeoLive(_, geo, heading, period, proximityNotificationRadius): let mediaMap = telegramMediaMapFromApiGeoPoint(geo, title: nil, address: nil, provider: nil, venueId: nil, venueType: nil, liveBroadcastingTimeout: period, liveProximityNotificationRadius: proximityNotificationRadius, heading: heading) - return (mediaMap, nil) + return (mediaMap, nil, nil) case let .messageMediaDocument(flags, document, ttlSeconds): if let document = document { - if let mediaFile = telegramMediaFileFromApiDocument(document, noPremium: (flags & (1 << 3)) != 0) { - return (mediaFile, ttlSeconds) + if let mediaFile = telegramMediaFileFromApiDocument(document) { + return (mediaFile, ttlSeconds, (flags & (1 << 3)) != 0) } } else { - return (TelegramMediaExpiredContent(data: .file), nil) + return (TelegramMediaExpiredContent(data: .file), nil, nil) } case let .messageMediaWebPage(webpage): if let mediaWebpage = telegramMediaWebpageFromApiWebpage(webpage, url: nil) { - return (mediaWebpage, nil) + return (mediaWebpage, nil, nil) } case .messageMediaUnsupported: - return (TelegramMediaUnsupported(), nil) + return (TelegramMediaUnsupported(), nil, nil) case .messageMediaEmpty: break case let .messageMediaGame(game): - return (TelegramMediaGame(apiGame: game), nil) + return (TelegramMediaGame(apiGame: game), nil, nil) case let .messageMediaInvoice(flags, title, description, photo, receiptMsgId, currency, totalAmount, startParam): var parsedFlags = TelegramMediaInvoiceFlags() if (flags & (1 << 3)) != 0 { @@ -306,7 +306,7 @@ func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerI if (flags & (1 << 1)) != 0 { parsedFlags.insert(.shippingAddressRequested) } - return (TelegramMediaInvoice(title: title, description: description, photo: photo.flatMap(TelegramMediaWebFile.init), receiptMessageId: receiptMsgId.flatMap { MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) }, currency: currency, totalAmount: totalAmount, startParam: startParam, flags: parsedFlags), nil) + return (TelegramMediaInvoice(title: title, description: description, photo: photo.flatMap(TelegramMediaWebFile.init), receiptMessageId: receiptMsgId.flatMap { MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) }, currency: currency, totalAmount: totalAmount, startParam: startParam, flags: parsedFlags), nil, nil) case let .messageMediaPoll(poll, results): switch poll { case let .poll(id, flags, question, answers, closePeriod, _): @@ -322,14 +322,14 @@ func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerI } else { kind = .poll(multipleAnswers: (flags & (1 << 2)) != 0) } - return (TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.CloudPoll, id: id), publicity: publicity, kind: kind, text: question, options: answers.map(TelegramMediaPollOption.init(apiOption:)), correctAnswers: nil, results: TelegramMediaPollResults(apiResults: results), isClosed: (flags & (1 << 0)) != 0, deadlineTimeout: closePeriod), nil) + return (TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.CloudPoll, id: id), publicity: publicity, kind: kind, text: question, options: answers.map(TelegramMediaPollOption.init(apiOption:)), correctAnswers: nil, results: TelegramMediaPollResults(apiResults: results), isClosed: (flags & (1 << 0)) != 0, deadlineTimeout: closePeriod), nil, nil) } case let .messageMediaDice(value, emoticon): - return (TelegramMediaDice(emoji: emoticon, value: value), nil) + return (TelegramMediaDice(emoji: emoticon, value: value), nil, nil) } } - return (nil, nil) + return (nil, nil, nil) } func messageTextEntitiesFromApiEntities(_ entities: [Api.MessageEntity]) -> [MessageTextEntity] { @@ -474,7 +474,7 @@ extension StoreMessage { var consumableContent: (Bool, Bool)? = nil if let media = media { - let (mediaValue, expirationTimer) = textMediaAndExpirationTimerFromApiMedia(media, peerId) + let (mediaValue, expirationTimer, nonPremium) = textMediaAndExpirationTimerFromApiMedia(media, peerId) if let mediaValue = mediaValue { medias.append(mediaValue) @@ -483,6 +483,10 @@ extension StoreMessage { consumableContent = (true, false) } + + if let nonPremium = nonPremium, nonPremium { + attributes.append(NonPremiumMessageAttribute()) + } } } diff --git a/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaFile.swift b/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaFile.swift index aeba4307ac..e8517f499d 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaFile.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaFile.swift @@ -141,14 +141,11 @@ func telegramMediaFileThumbnailRepresentationsFromApiSizes(datacenterId: Int32, return (immediateThumbnailData, representations) } -func telegramMediaFileFromApiDocument(_ document: Api.Document, noPremium: Bool = false) -> TelegramMediaFile? { +func telegramMediaFileFromApiDocument(_ document: Api.Document) -> TelegramMediaFile? { switch document { case let .document(_, id, accessHash, fileReference, _, mimeType, size, thumbs, videoThumbs, dcId, attributes): var parsedAttributes = telegramMediaFileAttributesFromApiAttributes(attributes) parsedAttributes.append(.hintIsValidated) - if noPremium { - parsedAttributes.append(.NoPremium) - } let (immediateThumbnail, previewRepresentations) = telegramMediaFileThumbnailRepresentationsFromApiSizes(datacenterId: dcId, documentId: id, accessHash: accessHash, fileReference: fileReference.makeData(), sizes: thumbs ?? []) diff --git a/submodules/TelegramCore/Sources/PendingMessages/PendingMessageUploadedContent.swift b/submodules/TelegramCore/Sources/PendingMessages/PendingMessageUploadedContent.swift index e5eab30f3f..10110ca08c 100644 --- a/submodules/TelegramCore/Sources/PendingMessages/PendingMessageUploadedContent.swift +++ b/submodules/TelegramCore/Sources/PendingMessages/PendingMessageUploadedContent.swift @@ -784,8 +784,8 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, auxili |> mapError { _ -> PendingMessageUploadError in return .generic } |> mapToSignal { result -> Signal in switch result { - case let .messageMediaDocument(flags, document, _): - if let document = document, let mediaFile = telegramMediaFileFromApiDocument(document, noPremium: (flags & (1 << 3)) != 0), let resource = mediaFile.resource as? CloudDocumentMediaResource, let fileReference = resource.fileReference { + case let .messageMediaDocument(_, document, _): + if let document = document, let mediaFile = telegramMediaFileFromApiDocument(document), let resource = mediaFile.resource as? CloudDocumentMediaResource, let fileReference = resource.fileReference { return maybeCacheUploadedResource(postbox: postbox, key: referenceKey, result: .content(PendingMessageUploadedContentAndReuploadInfo(content: .media(.inputMediaDocument(flags: 0, id: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: fileReference)), ttlSeconds: nil, query: nil), text), reuploadInfo: nil)), media: mediaFile) } default: diff --git a/submodules/TelegramCore/Sources/PendingMessages/StandaloneUploadedMedia.swift b/submodules/TelegramCore/Sources/PendingMessages/StandaloneUploadedMedia.swift index c1e49909a2..47d33f6db9 100644 --- a/submodules/TelegramCore/Sources/PendingMessages/StandaloneUploadedMedia.swift +++ b/submodules/TelegramCore/Sources/PendingMessages/StandaloneUploadedMedia.swift @@ -162,9 +162,9 @@ public func standaloneUploadedFile(account: Account, peerId: PeerId, text: Strin |> mapError { _ -> StandaloneUploadMediaError in return .generic } |> mapToSignal { media -> Signal in switch media { - case let .messageMediaDocument(flags, document, _): + case let .messageMediaDocument(_, document, _): if let document = document { - if let mediaFile = telegramMediaFileFromApiDocument(document, noPremium: (flags & (1 << 3)) != 0) { + if let mediaFile = telegramMediaFileFromApiDocument(document) { return .single(.result(.media(.standalone(media: mediaFile)))) } } diff --git a/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift b/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift index 5084d33e57..73fa894fba 100644 --- a/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift +++ b/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift @@ -1048,7 +1048,7 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo let messageText = text var medias: [Media] = [] - let (mediaValue, expirationTimer) = textMediaAndExpirationTimerFromApiMedia(media, peerId) + let (mediaValue, expirationTimer, nonPremium) = textMediaAndExpirationTimerFromApiMedia(media, peerId) if let mediaValue = mediaValue { medias.append(mediaValue) } @@ -1056,6 +1056,10 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo attributes.append(AutoclearTimeoutMessageAttribute(timeout: expirationTimer, countdownBeginTime: nil)) } + if let nonPremium = nonPremium, nonPremium { + attributes.append(NonPremiumMessageAttribute()) + } + if type.hasPrefix("auth") { updatedState.authorizationListUpdated = true } diff --git a/submodules/TelegramCore/Sources/State/ApplyUpdateMessage.swift b/submodules/TelegramCore/Sources/State/ApplyUpdateMessage.swift index c87e7e0ff5..901b66591f 100644 --- a/submodules/TelegramCore/Sources/State/ApplyUpdateMessage.swift +++ b/submodules/TelegramCore/Sources/State/ApplyUpdateMessage.swift @@ -117,7 +117,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes text = updatedMessage.text forwardInfo = updatedMessage.forwardInfo } else if case let .updateShortSentMessage(_, _, _, _, _, apiMedia, entities, ttlPeriod) = result { - let (mediaValue, _) = textMediaAndExpirationTimerFromApiMedia(apiMedia, currentMessage.id.peerId) + let (mediaValue, _, nonPremium) = textMediaAndExpirationTimerFromApiMedia(apiMedia, currentMessage.id.peerId) if let mediaValue = mediaValue { media = [mediaValue] } else { @@ -140,6 +140,11 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes updatedAttributes.append(AutoremoveTimeoutMessageAttribute(timeout: ttlPeriod, countdownBeginTime: updatedTimestamp)) } + updatedAttributes = updatedAttributes.filter({ !($0 is NonPremiumMessageAttribute) }) + if let nonPremium = nonPremium, nonPremium { + updatedAttributes.append(NonPremiumMessageAttribute()) + } + if Namespaces.Message.allScheduled.contains(message.id.namespace) && updatedId.namespace == Namespaces.Message.Cloud { for i in 0 ..< updatedAttributes.count { if updatedAttributes[i] is OutgoingScheduleInfoMessageAttribute { diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_NonPremiumMessageAttribute.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_NonPremiumMessageAttribute.swift new file mode 100644 index 0000000000..10fd57df67 --- /dev/null +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_NonPremiumMessageAttribute.swift @@ -0,0 +1,16 @@ +import Foundation +import Postbox + +public class NonPremiumMessageAttribute: MessageAttribute { + public var associatedMessageIds: [MessageId] = [] + + public init() { + + } + + required public init(decoder: PostboxDecoder) { + } + + public func encode(_ encoder: PostboxEncoder) { + } +} diff --git a/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift index a58e04f9a9..4e732b6f3c 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift @@ -14,10 +14,6 @@ public extension TelegramEngine { return _internal_acceptTermsOfService(account: self.account, id: id) } - public func resetAccountDueTermsOfService() -> Signal { - return _internal_resetAccountDueTermsOfService(network: self.account.network) - } - public func requestChangeAccountPhoneNumberVerification(phoneNumber: String) -> Signal { return _internal_requestChangeAccountPhoneNumberVerification(account: self.account, phoneNumber: phoneNumber) } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TermsOfService.swift b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TermsOfService.swift index a52082f7a2..77c05cc977 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TermsOfService.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TermsOfService.swift @@ -44,12 +44,6 @@ func _internal_acceptTermsOfService(account: Account, id: String) -> Signal Signal { - return network.request(Api.functions.account.deleteAccount(reason: "Decline ToS update")) - |> retryRequest - |> map { _ in return } -} - func managedTermsOfServiceUpdates(postbox: Postbox, network: Network, stateManager: AccountStateManager) -> Signal { let poll = network.request(Api.functions.help.getTermsOfServiceUpdate()) |> retryRequest diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift b/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift index e44a0c06a3..09b6201252 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift @@ -90,8 +90,8 @@ public extension TelegramEngine { return _internal_updateTwoStepVerificationPassword(network: self.account.network, currentPassword: currentPassword, updatedPassword: updatedPassword) } - public func deleteAccount() -> Signal { - return self.account.network.request(Api.functions.account.deleteAccount(reason: "GDPR")) + public func deleteAccount(reason: String) -> Signal { + return self.account.network.request(Api.functions.account.deleteAccount(reason: reason)) |> mapError { _ -> DeleteAccountError in return .generic } diff --git a/submodules/TelegramUI/Sources/ApplicationContext.swift b/submodules/TelegramUI/Sources/ApplicationContext.swift index bceb64a595..edba458be9 100644 --- a/submodules/TelegramUI/Sources/ApplicationContext.swift +++ b/submodules/TelegramUI/Sources/ApplicationContext.swift @@ -486,7 +486,7 @@ final class AuthorizedApplicationContext { } let accountId = strongSelf.context.account.id let accountManager = strongSelf.context.sharedContext.accountManager - let _ = (strongSelf.context.engine.auth.deleteAccount() + let _ = (strongSelf.context.engine.auth.deleteAccount(reason: "GDPR") |> deliverOnMainQueue).start(error: { _ in guard let strongSelf = self else { return diff --git a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift index f519798185..8df35f3722 100644 --- a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift @@ -1614,12 +1614,12 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { private var playedPremiumStickerAnimation = false func playPremiumStickerAnimation() { - guard !self.playedPremiumStickerAnimation, let file = self.telegramFile, file.isPremiumSticker, let effect = file.videoThumbnails.first else { + guard !self.playedPremiumStickerAnimation, let item = self.item, let file = self.telegramFile, file.isPremiumSticker, let effect = file.videoThumbnails.first else { return } self.playedPremiumStickerAnimation = true - if file.attributes.contains(where: { attribute in - if case .NoPremium = attribute { + if item.message.attributes.contains(where: { attribute in + if attribute is NonPremiumMessageAttribute { return true } else { return false @@ -1768,7 +1768,15 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { if let item = self.item, self.imageNode.frame.contains(location) { if let file = self.telegramFile { - if file.isPremiumSticker { + let noPremium = item.message.attributes.contains(where: { attribute in + if attribute is NonPremiumMessageAttribute { + return true + } else { + return false + } + }) + + if file.isPremiumSticker && !noPremium { return .optionalAction({ if self.additionalAnimationNodes.isEmpty { self.playedPremiumStickerAnimation = false From 6566fc18227795c118021477e89dfc470a903480 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 21 Jun 2022 20:35:30 +0500 Subject: [PATCH 2/6] Fix startattach --- .../Sources/PresentationThemeCodable.swift | 5 ++--- submodules/TelegramUI/Sources/OpenUrl.swift | 14 ++++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift index fcd002deb2..869195ef5f 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift @@ -850,7 +850,6 @@ extension PresentationThemeList: Codable { public convenience init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) - let codingPath = decoder.codingPath.map { $0.stringValue }.joined(separator: ".") let freePlainInputField: PresentationInputFieldTheme if let value = try? values.decode(PresentationInputFieldTheme.self, forKey: .freePlainInputField) { @@ -863,7 +862,7 @@ extension PresentationThemeList: Codable { self.init( blocksBackgroundColor: try decodeColor(values, .blocksBg), - modalBlocksBackgroundColor: try decodeColor(values, .modalBlocksBg, fallbackKey: "\(codingPath).blocksBg"), + modalBlocksBackgroundColor: try decodeColor(values, .modalBlocksBg, decoder: decoder, fallbackKey: "list.blocksBg"), plainBackgroundColor: try decodeColor(values, .plainBg), itemPrimaryTextColor: try decodeColor(values, .primaryText), itemSecondaryTextColor: try decodeColor(values, .secondaryText), @@ -873,7 +872,7 @@ extension PresentationThemeList: Codable { itemDestructiveColor: try decodeColor(values, .destructive), itemPlaceholderTextColor: try decodeColor(values, .placeholderText), itemBlocksBackgroundColor: try decodeColor(values, .itemBlocksBg), - itemModalBlocksBackgroundColor: try decodeColor(values, .itemModalBlocksBg, fallbackKey: "\(codingPath).itemBlocksBg"), + itemModalBlocksBackgroundColor: try decodeColor(values, .itemModalBlocksBg, decoder: decoder, fallbackKey: "list.itemBlocksBg"), itemHighlightedBackgroundColor: try decodeColor(values, .itemHighlightedBg), itemBlocksSeparatorColor: try decodeColor(values, .blocksSeparator), itemPlainSeparatorColor: try decodeColor(values, .plainSeparator), diff --git a/submodules/TelegramUI/Sources/OpenUrl.swift b/submodules/TelegramUI/Sources/OpenUrl.swift index 5428f9c155..f52302a028 100644 --- a/submodules/TelegramUI/Sources/OpenUrl.swift +++ b/submodules/TelegramUI/Sources/OpenUrl.swift @@ -696,11 +696,17 @@ func openExternalUrlImpl(context: AccountContext, urlContext: OpenURLContext, ur } } else if let attach = attach { result += "?attach=\(attach)" - } else if let startAttach = startAttach { - if !startAttach.isEmpty { - result += "?startattach=\(startAttach)" + } + if let startAttach = startAttach { + if attach == nil { + result += "?" } else { - result += "?startattach" + result += "&" + } + if !startAttach.isEmpty { + result += "startattach=\(startAttach)" + } else { + result += "startattach" } if let choose = choose { result += "&choose=\(choose)" From 3eff8819ffa5d157871a03b8c3bc6d9f11f9423a Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 21 Jun 2022 21:17:49 +0500 Subject: [PATCH 3/6] Various fixes --- .../ComposePollUI/Sources/CreatePollController.swift | 12 +++--------- .../Sources/DefaultDarkPresentationTheme.swift | 1 + .../Sources/DefaultDarkTintedPresentationTheme.swift | 1 + .../Sources/DefaultDayPresentationTheme.swift | 1 + .../Sources/PresentationTheme.swift | 9 ++++++--- .../Sources/PresentationThemeCodable.swift | 2 ++ .../Sources/AttachmentFileController.swift | 4 ++-- submodules/WebUI/Sources/WebAppController.swift | 4 ++-- 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/submodules/ComposePollUI/Sources/CreatePollController.swift b/submodules/ComposePollUI/Sources/CreatePollController.swift index b7d9c384e9..8d8e493a9f 100644 --- a/submodules/ComposePollUI/Sources/CreatePollController.swift +++ b/submodules/ComposePollUI/Sources/CreatePollController.swift @@ -932,15 +932,9 @@ public func createPollController(context: AccountContext, updatedPresentationDat weak var currentTooltipController: TooltipController? let controller = CreatePollControllerImpl(context: context, state: signal) controller.navigationPresentation = .modal -// controller.visibleBottomContentOffsetChanged = { [weak controller] offset in -// switch offset { -// case let .known(value): -// let backgroundAlpha: CGFloat = min(30.0, value) / 30.0 -// controller?.updateTabBarAlpha(backgroundAlpha, .immediate) -// case .unknown, .none: -// controller?.updateTabBarAlpha(1.0, .immediate) -// } -// } + controller.visibleBottomContentOffsetChanged = { [weak controller] _ in + controller?.updateTabBarAlpha(1.0, .immediate) + } presentControllerImpl = { [weak controller] c, a in controller?.present(c, in: .window(.root), with: a) } diff --git a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift index 6d186f0120..1257695a51 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift @@ -378,6 +378,7 @@ public func makeDefaultDarkPresentationTheme(extendingThemeReference: Presentati blocksBackgroundColor: UIColor(rgb: 0x000000), modalBlocksBackgroundColor: UIColor(rgb: 0x1c1c1d), plainBackgroundColor: UIColor(rgb: 0x000000), + modalPlainBackgroundColor: UIColor(rgb: 0x1c1c1d), itemPrimaryTextColor: UIColor(rgb: 0xffffff), itemSecondaryTextColor: UIColor(rgb: 0x98989e), itemDisabledTextColor: UIColor(rgb: 0x8f8f8f), diff --git a/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift index 234bfd7798..b351d10941 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift @@ -606,6 +606,7 @@ public func makeDefaultDarkTintedPresentationTheme(extendingThemeReference: Pres blocksBackgroundColor: additionalBackgroundColor, modalBlocksBackgroundColor: additionalBackgroundColor, plainBackgroundColor: additionalBackgroundColor, + modalPlainBackgroundColor: mainBackgroundColor, itemPrimaryTextColor: UIColor(rgb: 0xffffff), itemSecondaryTextColor: mainSecondaryTextColor.withAlphaComponent(0.5), itemDisabledTextColor: mainSecondaryTextColor.withAlphaComponent(0.5), diff --git a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift index 573f275c9f..0a9c295e36 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift @@ -449,6 +449,7 @@ public func makeDefaultDayPresentationTheme(extendingThemeReference: Presentatio blocksBackgroundColor: UIColor(rgb: 0xefeff4), modalBlocksBackgroundColor: UIColor(rgb: 0xefeff4), plainBackgroundColor: UIColor(rgb: 0xffffff), + modalPlainBackgroundColor: UIColor(rgb: 0xffffff), itemPrimaryTextColor: UIColor(rgb: 0x000000), itemSecondaryTextColor: UIColor(rgb: 0x8e8e93), itemDisabledTextColor: UIColor(rgb: 0x8e8e93), diff --git a/submodules/TelegramPresentationData/Sources/PresentationTheme.swift b/submodules/TelegramPresentationData/Sources/PresentationTheme.swift index 85cbcefa86..cbe4d11d2c 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationTheme.swift @@ -427,8 +427,9 @@ public final class PresentationThemeList { } public let blocksBackgroundColor: UIColor - public let plainBackgroundColor: UIColor public let modalBlocksBackgroundColor: UIColor + public let plainBackgroundColor: UIColor + public let modalPlainBackgroundColor: UIColor public let itemPrimaryTextColor: UIColor public let itemSecondaryTextColor: UIColor public let itemDisabledTextColor: UIColor @@ -465,6 +466,7 @@ public final class PresentationThemeList { blocksBackgroundColor: UIColor, modalBlocksBackgroundColor: UIColor, plainBackgroundColor: UIColor, + modalPlainBackgroundColor: UIColor, itemPrimaryTextColor: UIColor, itemSecondaryTextColor: UIColor, itemDisabledTextColor: UIColor, @@ -500,6 +502,7 @@ public final class PresentationThemeList { self.blocksBackgroundColor = blocksBackgroundColor self.modalBlocksBackgroundColor = modalBlocksBackgroundColor self.plainBackgroundColor = plainBackgroundColor + self.modalPlainBackgroundColor = modalPlainBackgroundColor self.itemPrimaryTextColor = itemPrimaryTextColor self.itemSecondaryTextColor = itemSecondaryTextColor self.itemDisabledTextColor = itemDisabledTextColor @@ -533,8 +536,8 @@ public final class PresentationThemeList { self.paymentOption = paymentOption } - public func withUpdated(blocksBackgroundColor: UIColor? = nil, modalBlocksBackgroundColor: UIColor? = nil, plainBackgroundColor: UIColor? = nil, itemPrimaryTextColor: UIColor? = nil, itemSecondaryTextColor: UIColor? = nil, itemDisabledTextColor: UIColor? = nil, itemAccentColor: UIColor? = nil, itemHighlightedColor: UIColor? = nil, itemDestructiveColor: UIColor? = nil, itemPlaceholderTextColor: UIColor? = nil, itemBlocksBackgroundColor: UIColor? = nil, itemModalBlocksBackgroundColor: UIColor? = nil, itemHighlightedBackgroundColor: UIColor? = nil, itemBlocksSeparatorColor: UIColor? = nil, itemPlainSeparatorColor: UIColor? = nil, disclosureArrowColor: UIColor? = nil, sectionHeaderTextColor: UIColor? = nil, freeTextColor: UIColor? = nil, freeTextErrorColor: UIColor? = nil, freeTextSuccessColor: UIColor? = nil, freeMonoIconColor: UIColor? = nil, itemSwitchColors: PresentationThemeSwitch? = nil, itemDisclosureActions: PresentationThemeItemDisclosureActions? = nil, itemCheckColors: PresentationThemeFillStrokeForeground? = nil, controlSecondaryColor: UIColor? = nil, freeInputField: PresentationInputFieldTheme? = nil, freePlainInputField: PresentationInputFieldTheme? = nil, mediaPlaceholderColor: UIColor? = nil, scrollIndicatorColor: UIColor? = nil, pageIndicatorInactiveColor: UIColor? = nil, inputClearButtonColor: UIColor? = nil, itemBarChart: PresentationThemeItemBarChart? = nil, itemInputField: PresentationInputFieldTheme? = nil, paymentOption: PaymentOption? = nil) -> PresentationThemeList { - return PresentationThemeList(blocksBackgroundColor: blocksBackgroundColor ?? self.blocksBackgroundColor, modalBlocksBackgroundColor: modalBlocksBackgroundColor ?? self.modalBlocksBackgroundColor, plainBackgroundColor: plainBackgroundColor ?? self.plainBackgroundColor, itemPrimaryTextColor: itemPrimaryTextColor ?? self.itemPrimaryTextColor, itemSecondaryTextColor: itemSecondaryTextColor ?? self.itemSecondaryTextColor, itemDisabledTextColor: itemDisabledTextColor ?? self.itemDisabledTextColor, itemAccentColor: itemAccentColor ?? self.itemAccentColor, itemHighlightedColor: itemHighlightedColor ?? self.itemHighlightedColor, itemDestructiveColor: itemDestructiveColor ?? self.itemDestructiveColor, itemPlaceholderTextColor: itemPlaceholderTextColor ?? self.itemPlaceholderTextColor, itemBlocksBackgroundColor: itemBlocksBackgroundColor ?? self.itemBlocksBackgroundColor, itemModalBlocksBackgroundColor: itemModalBlocksBackgroundColor ?? self.itemModalBlocksBackgroundColor, itemHighlightedBackgroundColor: itemHighlightedBackgroundColor ?? self.itemHighlightedBackgroundColor, itemBlocksSeparatorColor: itemBlocksSeparatorColor ?? self.itemBlocksSeparatorColor, itemPlainSeparatorColor: itemPlainSeparatorColor ?? self.itemPlainSeparatorColor, disclosureArrowColor: disclosureArrowColor ?? self.disclosureArrowColor, sectionHeaderTextColor: sectionHeaderTextColor ?? self.sectionHeaderTextColor, freeTextColor: freeTextColor ?? self.freeTextColor, freeTextErrorColor: freeTextErrorColor ?? self.freeTextErrorColor, freeTextSuccessColor: freeTextSuccessColor ?? self.freeTextSuccessColor, freeMonoIconColor: freeMonoIconColor ?? self.freeMonoIconColor, itemSwitchColors: itemSwitchColors ?? self.itemSwitchColors, itemDisclosureActions: itemDisclosureActions ?? self.itemDisclosureActions, itemCheckColors: itemCheckColors ?? self.itemCheckColors, controlSecondaryColor: controlSecondaryColor ?? self.controlSecondaryColor, freeInputField: freeInputField ?? self.freeInputField, freePlainInputField: freePlainInputField ?? self.freePlainInputField, mediaPlaceholderColor: mediaPlaceholderColor ?? self.mediaPlaceholderColor, scrollIndicatorColor: scrollIndicatorColor ?? self.scrollIndicatorColor, pageIndicatorInactiveColor: pageIndicatorInactiveColor ?? self.pageIndicatorInactiveColor, inputClearButtonColor: inputClearButtonColor ?? self.inputClearButtonColor, itemBarChart: itemBarChart ?? self.itemBarChart, itemInputField: itemInputField ?? self.itemInputField, paymentOption: paymentOption ?? self.paymentOption) + public func withUpdated(blocksBackgroundColor: UIColor? = nil, modalBlocksBackgroundColor: UIColor? = nil, plainBackgroundColor: UIColor? = nil, modalPlainBackgroundColor: UIColor? = nil, itemPrimaryTextColor: UIColor? = nil, itemSecondaryTextColor: UIColor? = nil, itemDisabledTextColor: UIColor? = nil, itemAccentColor: UIColor? = nil, itemHighlightedColor: UIColor? = nil, itemDestructiveColor: UIColor? = nil, itemPlaceholderTextColor: UIColor? = nil, itemBlocksBackgroundColor: UIColor? = nil, itemModalBlocksBackgroundColor: UIColor? = nil, itemHighlightedBackgroundColor: UIColor? = nil, itemBlocksSeparatorColor: UIColor? = nil, itemPlainSeparatorColor: UIColor? = nil, disclosureArrowColor: UIColor? = nil, sectionHeaderTextColor: UIColor? = nil, freeTextColor: UIColor? = nil, freeTextErrorColor: UIColor? = nil, freeTextSuccessColor: UIColor? = nil, freeMonoIconColor: UIColor? = nil, itemSwitchColors: PresentationThemeSwitch? = nil, itemDisclosureActions: PresentationThemeItemDisclosureActions? = nil, itemCheckColors: PresentationThemeFillStrokeForeground? = nil, controlSecondaryColor: UIColor? = nil, freeInputField: PresentationInputFieldTheme? = nil, freePlainInputField: PresentationInputFieldTheme? = nil, mediaPlaceholderColor: UIColor? = nil, scrollIndicatorColor: UIColor? = nil, pageIndicatorInactiveColor: UIColor? = nil, inputClearButtonColor: UIColor? = nil, itemBarChart: PresentationThemeItemBarChart? = nil, itemInputField: PresentationInputFieldTheme? = nil, paymentOption: PaymentOption? = nil) -> PresentationThemeList { + return PresentationThemeList(blocksBackgroundColor: blocksBackgroundColor ?? self.blocksBackgroundColor, modalBlocksBackgroundColor: modalBlocksBackgroundColor ?? self.modalBlocksBackgroundColor, plainBackgroundColor: plainBackgroundColor ?? self.plainBackgroundColor, modalPlainBackgroundColor: modalPlainBackgroundColor ?? self.modalPlainBackgroundColor, itemPrimaryTextColor: itemPrimaryTextColor ?? self.itemPrimaryTextColor, itemSecondaryTextColor: itemSecondaryTextColor ?? self.itemSecondaryTextColor, itemDisabledTextColor: itemDisabledTextColor ?? self.itemDisabledTextColor, itemAccentColor: itemAccentColor ?? self.itemAccentColor, itemHighlightedColor: itemHighlightedColor ?? self.itemHighlightedColor, itemDestructiveColor: itemDestructiveColor ?? self.itemDestructiveColor, itemPlaceholderTextColor: itemPlaceholderTextColor ?? self.itemPlaceholderTextColor, itemBlocksBackgroundColor: itemBlocksBackgroundColor ?? self.itemBlocksBackgroundColor, itemModalBlocksBackgroundColor: itemModalBlocksBackgroundColor ?? self.itemModalBlocksBackgroundColor, itemHighlightedBackgroundColor: itemHighlightedBackgroundColor ?? self.itemHighlightedBackgroundColor, itemBlocksSeparatorColor: itemBlocksSeparatorColor ?? self.itemBlocksSeparatorColor, itemPlainSeparatorColor: itemPlainSeparatorColor ?? self.itemPlainSeparatorColor, disclosureArrowColor: disclosureArrowColor ?? self.disclosureArrowColor, sectionHeaderTextColor: sectionHeaderTextColor ?? self.sectionHeaderTextColor, freeTextColor: freeTextColor ?? self.freeTextColor, freeTextErrorColor: freeTextErrorColor ?? self.freeTextErrorColor, freeTextSuccessColor: freeTextSuccessColor ?? self.freeTextSuccessColor, freeMonoIconColor: freeMonoIconColor ?? self.freeMonoIconColor, itemSwitchColors: itemSwitchColors ?? self.itemSwitchColors, itemDisclosureActions: itemDisclosureActions ?? self.itemDisclosureActions, itemCheckColors: itemCheckColors ?? self.itemCheckColors, controlSecondaryColor: controlSecondaryColor ?? self.controlSecondaryColor, freeInputField: freeInputField ?? self.freeInputField, freePlainInputField: freePlainInputField ?? self.freePlainInputField, mediaPlaceholderColor: mediaPlaceholderColor ?? self.mediaPlaceholderColor, scrollIndicatorColor: scrollIndicatorColor ?? self.scrollIndicatorColor, pageIndicatorInactiveColor: pageIndicatorInactiveColor ?? self.pageIndicatorInactiveColor, inputClearButtonColor: inputClearButtonColor ?? self.inputClearButtonColor, itemBarChart: itemBarChart ?? self.itemBarChart, itemInputField: itemInputField ?? self.itemInputField, paymentOption: paymentOption ?? self.paymentOption) } } diff --git a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift index 869195ef5f..b302e7529f 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift @@ -815,6 +815,7 @@ extension PresentationThemeList: Codable { case blocksBg case modalBlocksBg case plainBg + case modalPlainBg case primaryText case secondaryText case disabledText @@ -864,6 +865,7 @@ extension PresentationThemeList: Codable { blocksBackgroundColor: try decodeColor(values, .blocksBg), modalBlocksBackgroundColor: try decodeColor(values, .modalBlocksBg, decoder: decoder, fallbackKey: "list.blocksBg"), plainBackgroundColor: try decodeColor(values, .plainBg), + modalPlainBackgroundColor: try decodeColor(values, .modalPlainBg, decoder: decoder, fallbackKey: "list.plainBg"), itemPrimaryTextColor: try decodeColor(values, .primaryText), itemSecondaryTextColor: try decodeColor(values, .secondaryText), itemDisabledTextColor: try decodeColor(values, .disabledText), diff --git a/submodules/TelegramUI/Sources/AttachmentFileController.swift b/submodules/TelegramUI/Sources/AttachmentFileController.swift index 7860dbbf9f..0f383c5b5c 100644 --- a/submodules/TelegramUI/Sources/AttachmentFileController.swift +++ b/submodules/TelegramUI/Sources/AttachmentFileController.swift @@ -310,7 +310,7 @@ public func attachmentFileController(context: AccountContext, updatedPresentatio controller.visibleBottomContentOffsetChanged = { [weak controller] offset in switch offset { case let .known(value): - let backgroundAlpha: CGFloat = min(30.0, max(0.0, value)) / 30.0 + let backgroundAlpha: CGFloat = min(30.0, max(0.0, value)) / 30.0 if backgroundAlpha.isZero && controller?.delayDisappear == true { Queue.mainQueue().after(0.25, { controller?.updateTabBarAlpha(backgroundAlpha, .animated(duration: 0.1, curve: .easeInOut)) @@ -320,7 +320,7 @@ public func attachmentFileController(context: AccountContext, updatedPresentatio } case .unknown, .none: controller?.updateTabBarAlpha(1.0, .immediate) - controller?.delayDisappear = false + controller?.delayDisappear = false } } controller.resetForReuseImpl = { diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index bd5958885d..216afd8217 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -162,7 +162,7 @@ public func generateWebAppThemeParams(_ presentationTheme: PresentationTheme) -> var backgroundColor = presentationTheme.list.plainBackgroundColor.rgb var secondaryBackgroundColor = presentationTheme.list.blocksBackgroundColor.rgb if presentationTheme.list.blocksBackgroundColor.rgb == presentationTheme.list.plainBackgroundColor.rgb { - backgroundColor = presentationTheme.list.modalBlocksBackgroundColor.rgb + backgroundColor = presentationTheme.list.modalPlainBackgroundColor.rgb secondaryBackgroundColor = presentationTheme.list.plainBackgroundColor.rgb } return [ @@ -734,7 +734,7 @@ public final class WebAppController: ViewController, AttachmentContainable { var backgroundColor = self.presentationData.theme.list.plainBackgroundColor var secondaryBackgroundColor = self.presentationData.theme.list.blocksBackgroundColor if self.presentationData.theme.list.blocksBackgroundColor.rgb == self.presentationData.theme.list.plainBackgroundColor.rgb { - backgroundColor = self.presentationData.theme.list.modalBlocksBackgroundColor + backgroundColor = self.presentationData.theme.list.modalPlainBackgroundColor secondaryBackgroundColor = self.presentationData.theme.list.plainBackgroundColor } if let headerColorKey = self.headerColorKey { From 12f3b4b64a04667b40719b05341daaf4955550a6 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 21 Jun 2022 21:53:31 +0500 Subject: [PATCH 4/6] Various fixes --- submodules/TelegramUI/Sources/ChatMediaInputNode.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift index 719b0ed586..3eda31a7fb 100644 --- a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift +++ b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift @@ -365,7 +365,7 @@ func chatMediaInputGridEntries(view: ItemCollectionsView, savedStickers: Ordered } } - if let cloudPremiumStickers = cloudPremiumStickers { + if let cloudPremiumStickers = cloudPremiumStickers, existingStickerIds.isEmpty { for i in 0 ..< cloudPremiumStickers.items.count { if let item = cloudPremiumStickers.items[i].contents.get(RecentMediaItem.self) { let file = item.media From 699f709f2e7f6334fa2ad70c9255b326523283da Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 21 Jun 2022 22:33:52 +0500 Subject: [PATCH 5/6] Various fixes --- .../Sources/InAppPurchaseManager.swift | 20 +++++++++--- .../VoiceChatFullscreenParticipantItem.swift | 32 +++++++++---------- .../TelegramEngine/Payments/AppStore.swift | 9 ++++-- submodules/TelegramUI/Sources/OpenUrl.swift | 12 ++++--- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/submodules/InAppPurchaseManager/Sources/InAppPurchaseManager.swift b/submodules/InAppPurchaseManager/Sources/InAppPurchaseManager.swift index df32f8ba53..91eb0e8231 100644 --- a/submodules/InAppPurchaseManager/Sources/InAppPurchaseManager.swift +++ b/submodules/InAppPurchaseManager/Sources/InAppPurchaseManager.swift @@ -35,7 +35,7 @@ public final class InAppPurchaseManager: NSObject { } public enum RestoreState { - case succeed + case succeed(Bool) case failed } @@ -61,7 +61,7 @@ public final class InAppPurchaseManager: NSObject { private let premiumProductId: String private var products: [Product] = [] - private var productsPromise = Promise<[Product]>() + private var productsPromise = Promise<[Product]>([]) private var productRequest: SKProductsRequest? private let stateQueue = Queue() @@ -290,16 +290,28 @@ extension InAppPurchaseManager: SKPaymentTransactionObserver { 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: { + self.engine.payments.sendAppStoreReceipt(receipt: receiptData, restore: true).start(error: { error in + Queue.mainQueue().async { + if case .serverProvided = error { + onRestoreCompletion(.succeed(true)) + } else { + onRestoreCompletion(.succeed(false)) + } + } + }, completed: { + Queue.mainQueue().async { + onRestoreCompletion(.succeed(false)) + } Logger.shared.log("InAppPurchaseManager", "Sent restored receipt") }), forKey: "restore" ) + } else { + onRestoreCompletion(.succeed(false)) } } } diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatFullscreenParticipantItem.swift b/submodules/TelegramCallsUI/Sources/VoiceChatFullscreenParticipantItem.swift index d19750bf78..2563a57678 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatFullscreenParticipantItem.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatFullscreenParticipantItem.swift @@ -495,24 +495,24 @@ class VoiceChatFullscreenParticipantItemNode: ItemListRevealOptionsItemNode { let leftInset: CGFloat = 58.0 + params.leftInset - let premiumConfiguration = PremiumConfiguration.with(appConfiguration: item.context.currentAppConfiguration.with { $0 }) +// let premiumConfiguration = PremiumConfiguration.with(appConfiguration: item.context.currentAppConfiguration.with { $0 }) var titleIconsWidth: CGFloat = 0.0 - var currentCredibilityIconImage: UIImage? - var credibilityIconOffset: CGFloat = 0.0 - if item.peer.isScam { - currentCredibilityIconImage = PresentationResourcesChatList.scamIcon(item.presentationData.theme, strings: item.presentationData.strings, type: .regular) - credibilityIconOffset = 2.0 - } else if item.peer.isFake { - currentCredibilityIconImage = PresentationResourcesChatList.fakeIcon(item.presentationData.theme, strings: item.presentationData.strings, type: .regular) - credibilityIconOffset = 2.0 - } else if item.peer.isVerified { - currentCredibilityIconImage = PresentationResourcesChatList.verifiedIcon(item.presentationData.theme) - credibilityIconOffset = 3.0 - } else if item.peer.isPremium && !premiumConfiguration.isPremiumDisabled { - currentCredibilityIconImage = PresentationResourcesChatList.premiumIcon(item.presentationData.theme) - credibilityIconOffset = 3.0 - } + let currentCredibilityIconImage: UIImage? = nil + let credibilityIconOffset: CGFloat = 0.0 +// if item.peer.isScam { +// currentCredibilityIconImage = PresentationResourcesChatList.scamIcon(item.presentationData.theme, strings: item.presentationData.strings, type: .regular) +// credibilityIconOffset = 2.0 +// } else if item.peer.isFake { +// currentCredibilityIconImage = PresentationResourcesChatList.fakeIcon(item.presentationData.theme, strings: item.presentationData.strings, type: .regular) +// credibilityIconOffset = 2.0 +// } else if item.peer.isVerified { +// currentCredibilityIconImage = PresentationResourcesChatList.verifiedIcon(item.presentationData.theme) +// credibilityIconOffset = 3.0 +// } else if item.peer.isPremium && !premiumConfiguration.isPremiumDisabled { +// currentCredibilityIconImage = PresentationResourcesChatList.premiumIcon(item.presentationData.theme) +// credibilityIconOffset = 3.0 +// } if let currentCredibilityIconImage = currentCredibilityIconImage { titleIconsWidth += 4.0 + currentCredibilityIconImage.size.width diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/AppStore.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/AppStore.swift index 4a8b1c68b0..b7e51a0c15 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/AppStore.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/AppStore.swift @@ -7,6 +7,7 @@ import TelegramApi public enum AssignAppStoreTransactionError { case generic case timeout + case serverProvided } func _internal_sendAppStoreReceipt(account: Account, receipt: Data, restore: Bool) -> Signal { @@ -15,8 +16,12 @@ func _internal_sendAppStoreReceipt(account: Account, receipt: Data, restore: Boo flags |= (1 << 0) } return account.network.request(Api.functions.payments.assignAppStoreTransaction(flags: flags, receipt: Buffer(data: receipt))) - |> mapError { _ -> AssignAppStoreTransactionError in - return .generic + |> mapError { error -> AssignAppStoreTransactionError in + if error.errorCode == 406 { + return .serverProvided + } else { + return .generic + } } |> mapToSignal { updates -> Signal in account.stateManager.addUpdates(updates) diff --git a/submodules/TelegramUI/Sources/OpenUrl.swift b/submodules/TelegramUI/Sources/OpenUrl.swift index f52302a028..c81e1bfe17 100644 --- a/submodules/TelegramUI/Sources/OpenUrl.swift +++ b/submodules/TelegramUI/Sources/OpenUrl.swift @@ -778,15 +778,17 @@ func openExternalUrlImpl(context: AccountContext, urlContext: OpenURLContext, ur context.inAppPurchaseManager?.restorePurchases(completion: { [weak statusController] result in statusController?.dismiss() - let text: String + let text: String? switch result { - case .succeed: - text = presentationData.strings.Premium_Restore_Success + case let .succeed(serverProvided): + text = serverProvided ? nil : presentationData.strings.Premium_Restore_Success case .failed: text = presentationData.strings.Premium_Restore_ErrorUnknown } - let alertController = textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]) - context.sharedContext.presentGlobalController(alertController, nil) + if let text = text { + let alertController = textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]) + context.sharedContext.presentGlobalController(alertController, nil) + } }) } } From f2efd60154dcba1d9da230e3b6aa6a9ca132f6e8 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 22 Jun 2022 18:59:00 +0500 Subject: [PATCH 6/6] Various fixes --- submodules/TelegramUI/Sources/ChatMediaInputNode.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift index 3eda31a7fb..e50820d4b6 100644 --- a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift +++ b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift @@ -295,7 +295,7 @@ func chatMediaInputGridEntries(view: ItemCollectionsView, savedStickers: Ordered let filteredTrending = trendingPacks.filter { !installedPacks.contains($0.info.id) } if !trendingIsDismissed && !filteredTrending.isEmpty { - entries.append(.trendingList(theme: theme, strings: strings, packs: filteredTrending, isPremium: false)) + entries.append(.trendingList(theme: theme, strings: strings, packs: filteredTrending, isPremium: trendingIsPremium)) } if let recentStickers = recentStickers, !recentStickers.items.isEmpty {