From fd2a56b57efeaccb51524358db71108bd671ea08 Mon Sep 17 00:00:00 2001 From: Denis Shilovich Date: Wed, 30 Oct 2024 13:21:33 +0000 Subject: [PATCH] 1.8.7 (357) --- MODULE.bazel.lock | 6 +- Nicegram/NGUtils/Sources/Peer.swift | 15 -- Package.resolved | 8 +- Package.swift | 4 +- ng-env.txt | 2 +- .../Sources/ChatListController.swift | 14 -- .../Sources/Node/ChatListItem.swift | 73 +----- .../Sources/Node/ChatListNode.swift | 37 ++- .../Sources/DebugController.swift | 24 +- .../Source/Signal_Combine.swift | 6 - .../Nicegram/ShareController+Nicegram.swift | 63 ----- .../Sources/ShareController.swift | 24 +- .../TelegramCore/Sources/Utils/Log.swift | 30 ++- .../Components/Chat/ChatHistoryEntry/BUILD | 6 +- .../Sources/ChatHistoryEntry.swift | 68 +----- .../Components/Chat/ChatMessageItemImpl/BUILD | 1 - .../Chat/ChatMessageNicegramAdNode/BUILD | 26 --- .../Sources/ChatMessageNicegramAdItem.swift | 70 ------ .../Sources/ChatMessageNicegramAdNode.swift | 162 ------------- .../TelegramUI/Sources/AppDelegate.swift | 1 - .../TelegramUI/Sources/ChatController.swift | 27 --- .../Sources/ChatHistoryListNode.swift | 70 +----- .../Sources/Nicegram/NGDeeplinkHandler.swift | 99 +++++--- .../NicegramMapChatHistoryEntries.swift | 218 ------------------ submodules/TgVoipWebrtc/tgcalls | 2 +- 25 files changed, 164 insertions(+), 892 deletions(-) delete mode 100644 submodules/ShareController/Sources/Nicegram/ShareController+Nicegram.swift delete mode 100644 submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/BUILD delete mode 100644 submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/Sources/ChatMessageNicegramAdItem.swift delete mode 100644 submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/Sources/ChatMessageNicegramAdNode.swift delete mode 100644 submodules/TelegramUI/Sources/Nicegram/NicegramMapChatHistoryEntries.swift diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 3176c3bac51..0d98f1e6e70 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -635,8 +635,8 @@ "bzlTransitiveDigest": "8/YWyYftd8THfVoADvrOmQLl45wUGfP2MVjLM5FFn50=", "usagesDigest": "voXBMcSNlo2fnK6JIvInIrncYhBKKG8nBeKvToaUA0Y=", "recordedFileInputs": { - "@@//Package.resolved": "bb0a4c54031f3dd1fdd9c99cfb1e50a6731d9d2964a00bc761099e3165db060d", - "@@//Package.swift": "80e04236345b77f28883526f6b7b5dc4218ab63fadd749141de4deacf8237b87" + "@@//Package.resolved": "6dd0cb4827ef0c9ff99686ccfd442cbc0261597cd8f7bb03fda649c28bf125ad", + "@@//Package.swift": "fb3cb1d48066e64f8bf17fe1a49f689b7a6bf4bfc07aa90b9b80a02188501951" }, "recordedDirentsInputs": {}, "envVariables": {}, @@ -1121,7 +1121,7 @@ "ruleClassName": "swift_package", "attributes": { "bazel_package_name": "swiftpkg_nicegram_assistant_ios", - "commit": "17449ccb313e2de4f41a00571fba08ceb3ae83da", + "commit": "b1d4897f36e71c8faef3a06278d503c42f737e98", "remote": "git@bitbucket.org:mobyrix/nicegram-assistant-ios.git", "version": "", "init_submodules": false, diff --git a/Nicegram/NGUtils/Sources/Peer.swift b/Nicegram/NGUtils/Sources/Peer.swift index 0341acf73af..f9c5249dc1e 100644 --- a/Nicegram/NGUtils/Sources/Peer.swift +++ b/Nicegram/NGUtils/Sources/Peer.swift @@ -14,18 +14,3 @@ public func extractPeerId(peer: Peer) -> Int64 { return Int64(idText) ?? peer.id.id._internalGetInt64Value() } - -public func getMembersCount(cachedPeerData: CachedPeerData?) -> Int? { - guard let cachedPeerData else { - return nil - } - - switch cachedPeerData { - case let channel as CachedChannelData: - return channel.participantsSummary.memberCount.flatMap(Int.init) - case let group as CachedGroupData: - return group.participants?.participants.count - default: - return nil - } -} diff --git a/Package.resolved b/Package.resolved index 9243328e649..1be2a815190 100644 --- a/Package.resolved +++ b/Package.resolved @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "git@bitbucket.org:mobyrix/nicegram-assistant-ios.git", "state" : { - "branch" : "feat/attention-economy", - "revision" : "4e25d9a908597c1849f853026af0c60ca1fa35cd" + "branch" : "develop", + "revision" : "b1d4897f36e71c8faef3a06278d503c42f737e98" } }, { @@ -122,8 +122,8 @@ "kind" : "remoteSourceControl", "location" : "git@bitbucket.org:mobyrix/nicegram-wallet-ios.git", "state" : { - "branch" : "feat/attention-economy", - "revision" : "6b32239cc639c4cd27874b44b4d5426732a84da2" + "branch" : "develop", + "revision" : "ee32c2836b5ba333342d4c73b98561f8f0fb1ae2" } }, { diff --git a/Package.swift b/Package.swift index 13792cdaa1f..fbff9b5bdb3 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let package = Package( name: "nicegram-package", dependencies: [ - .package(url: "git@bitbucket.org:mobyrix/nicegram-assistant-ios.git", branch: "feat/attention-economy"), - .package(url: "git@bitbucket.org:mobyrix/nicegram-wallet-ios.git", branch: "feat/attention-economy") + .package(url: "git@bitbucket.org:mobyrix/nicegram-assistant-ios.git", branch: "develop"), + .package(url: "git@bitbucket.org:mobyrix/nicegram-wallet-ios.git", branch: "develop") ] ) diff --git a/ng-env.txt b/ng-env.txt index 30d74d25844..c23f7a80886 100644 --- a/ng-env.txt +++ b/ng-env.txt @@ -1 +1 @@ -test \ No newline at end of file +prod \ No newline at end of file diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 9bbda9df066..485a4cd873b 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -2244,10 +2244,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController override public func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - // MARK: Nicegram PinnedChats - updateChatListNode(isOnScreen: true) - // - // MARK: Nicegram if #available(iOS 15.0, *), !didAppear { Task { @@ -2678,10 +2674,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController override public func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) - // MARK: Nicegram PinnedChats - updateChatListNode(isOnScreen: false) - // - if self.dismissSearchOnDisappear { self.dismissSearchOnDisappear = false self.deactivateSearch(animated: false) @@ -2701,12 +2693,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController } } - // MARK: Nicegram PinnedChats - private func updateChatListNode(isOnScreen: Bool) { - chatListDisplayNode.effectiveContainerNode.currentItemNode.isOnScreen.value = isOnScreen - } - // - func updateHeaderContent() -> (primaryContent: ChatListHeaderComponent.Content?, secondaryContent: ChatListHeaderComponent.Content?) { var primaryContent: ChatListHeaderComponent.Content? if let primaryContext = self.primaryContext { diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index b8e8081a7dd..6b31a117b32 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -1,7 +1,3 @@ -// MARK: Nicegram ATT -import class Combine.AnyCancellable -import FeatAttentionEconomy -// // MARK: Nicegram HideReactions, HideStories import FeatPinnedChats import NGData @@ -404,12 +400,6 @@ public class ChatListItem: ListViewItem, ChatListSearchItemNeighbour { // MARK: Nicegram PinnedChats let nicegramItem: PinnedChatToDisplay? // - - // MARK: Nicegram ATT - let attBannerFeature = AttBannerFeature() - var attAd: AttAd? { nicegramItem?.chat.attAd } - // - let presentationData: ChatListPresentationData let context: AccountContext let chatListLocation: ChatListControllerLocation @@ -518,12 +508,8 @@ public class ChatListItem: ListViewItem, ChatListSearchItemNeighbour { if let nicegramItem { if #available(iOS 13.0, *) { Task { @MainActor in - if let attAd { - attBannerFeature.onClick(ad: attAd) - } else { - let openPinnedChatUseCase = PinnedChatsContainer.shared.openPinnedChatUseCase() - openPinnedChatUseCase(nicegramItem.chat) - } + let openPinnedChatUseCase = PinnedChatsContainer.shared.openPinnedChatUseCase() + openPinnedChatUseCase(nicegramItem.chat) interaction.clearHighlightAnimated(true) } @@ -1224,11 +1210,6 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { var item: ChatListItem? - // MARK: Nicegram ATT - private var attClaimAnimationView: AttClaimAnimationView? - private var attClaimAnimationCancellable: AnyCancellable? - // - private let backgroundNode: ASDisplayNode private let highlightedBackgroundNode: ASDisplayNode @@ -1483,16 +1464,6 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { ) } self.authorNode.visibilityStatus = self.visibilityStatus - - // MARK: Nicegram ATT - if self.visibilityStatus, let item { - if let attAd = item.attAd { - item.attBannerFeature.onView(ad: attAd) - } else if let nicegramItem = item.nicegramItem { - PinnedChatsUI.trackChatView(nicegramItem.chat) - } - } - // } } } @@ -1854,13 +1825,6 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { } // - // MARK: Nicegram ATT - attClaimAnimationCancellable = item.attBannerFeature.claimAnimationPublisher - .sink { [weak self] result in - self?.attClaimAnimationView?.animate(value: result.claimAmount) - } - // - self.contextContainer.isGestureEnabled = enablePreview && !item.editing } @@ -4515,27 +4479,6 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { strongSelf.mutedIconNode.isHidden = true } - // MARK: Nicegram ATT - if item.attAd != nil { - let attClaimAnimationView: AttClaimAnimationView - if let current = strongSelf.attClaimAnimationView { - attClaimAnimationView = current - } else { - attClaimAnimationView = AttClaimAnimationView() - attClaimAnimationView.set(coinOpacity: 0) - strongSelf.attClaimAnimationView = attClaimAnimationView - strongSelf.mainContentContainerNode.view.addSubview(attClaimAnimationView) - } - - let iconSize = CGSize(width: 20, height: 20) - transition.updateFrame(view: attClaimAnimationView, frame: CGRect(origin: CGPoint(x: nextTitleIconOrigin, y: floorToScreenPixels(titleFrame.maxY - lastLineRect.height * 0.5 - iconSize.height / 2.0) - UIScreenPixel), size: iconSize)) - nextTitleIconOrigin += attClaimAnimationView.bounds.width + 4.0 - } else if let attClaimAnimationView = strongSelf.attClaimAnimationView { - strongSelf.attClaimAnimationView = nil - attClaimAnimationView.removeFromSuperview() - } - // - let separatorInset: CGFloat if case let .groupReference(groupReferenceData) = item.content, groupReferenceData.hiddenByDefault { separatorInset = 0.0 @@ -4723,14 +4666,10 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { case RevealOptionKey.unpin.rawValue: self.setRevealOptionsOpened(false, animated: true) - if let ad = item.attAd { - item.attBannerFeature.onRemoveAdClick(ad: ad) - } else { - Task { @MainActor in - PinnedChatsUI.unpin( - nicegramItem.chat - ) - } + Task { @MainActor in + PinnedChatsUI.unpin( + nicegramItem.chat + ) } default: break diff --git a/submodules/ChatListUI/Sources/Node/ChatListNode.swift b/submodules/ChatListUI/Sources/Node/ChatListNode.swift index 3c85c19b737..28044a4f450 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListNode.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListNode.swift @@ -1276,11 +1276,6 @@ public final class ChatListNode: ListView { private var dequeuedInitialTransitionOnLayout = false private var enqueuedTransition: (ChatListNodeListViewTransition, () -> Void)? - // MARK: Nicegram PinnedChats - public let isOnScreen = CurrentValueSubject(false) - private var cancellables = Set() - // - public private(set) var currentState: ChatListNodeState private let statePromise: ValuePromise public var state: Signal { @@ -2259,24 +2254,16 @@ public final class ChatListNode: ListView { } // MARK: Nicegram PinnedChats - let nicegramItems = CurrentValueSubject<[PinnedChatToDisplay], Never>([]) - let nicegramItemsSignal = nicegramItems - .eraseToAnyPublisher() - .toSignal() - .skipError() - - PinnedChatsContainer.shared.getPinnedChatsToDisplayUseCase() - .publisher() - .map { $0.reversed() } - .combineLatestThreadSafe( - isOnScreen.eraseToAnyPublisher() - ) - .sink { items, isOnScreen in - if isOnScreen { - nicegramItems.value = items - } - } - .store(in: &cancellables) + let nicegramItemsSignal: Signal<[PinnedChatToDisplay], NoError> + if #available(iOS 13.0, *) { + nicegramItemsSignal = PinnedChatsContainer.shared.getPinnedChatsToDisplayUseCase() + .publisher() + .map { $0.reversed() } + .toSignal() + .skipError() + } else { + nicegramItemsSignal = .single([]) + } // // MARK: Nicegram HiddenChats @@ -2367,6 +2354,10 @@ public final class ChatListNode: ListView { if case .forum(_) = location { nicegramItems = [] } + + if #available(iOS 13.0, *) { + PinnedChatsUI.trackChatsView(nicegramItems.map(\.chat)) + } // let innerIsMainTab = location == .chatList(groupId: .root) && chatListFilter == nil diff --git a/submodules/DebugSettingsUI/Sources/DebugController.swift b/submodules/DebugSettingsUI/Sources/DebugController.swift index 4f86b53c075..a32e0ccb42c 100644 --- a/submodules/DebugSettingsUI/Sources/DebugController.swift +++ b/submodules/DebugSettingsUI/Sources/DebugController.swift @@ -739,8 +739,24 @@ private enum DebugControllerEntry: ItemListNodeEntry { }) case .sendNGLogs: return ItemListDisclosureItem(presentationData: presentationData, title: "Send Nicegram Logs", label: "", sectionId: self.section, style: .blocks, action: { - let _ = (Logger(rootPath: arguments.sharedContext.basePath, basePath: arguments.sharedContext.basePath + "/ngLogs").collectLogs() - |> deliverOnMainQueue).start(next: { logs in + let ngLogs = Logger( + rootPath: arguments.sharedContext.basePath, + basePath: arguments.sharedContext.basePath + "/ngLogs" + ).collectLogs() + + let accountPathName: String? = if let context = arguments.context { + accountRecordIdPathName(context.account.id) + } else { + nil + } + let callRecorderLogs = Logger.shared.collectLogs( + with: arguments.sharedContext.basePath, + accountPathName: accountPathName + ) + + let _ = (combineLatest(ngLogs, callRecorderLogs) |> deliverOnMainQueue) + .start(next: { logs in + let allLogs = logs.0 + logs.1 guard let context = arguments.context else { return } @@ -750,8 +766,8 @@ private enum DebugControllerEntry: ItemListNodeEntry { if let strongController = controller { strongController.dismiss() - - let messages = logs.map { (name, path) -> EnqueueMessage in + + let messages = allLogs.map { (name, path) -> EnqueueMessage in let id = Int64.random(in: Int64.min ... Int64.max) let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: id), partialReference: nil, resource: LocalFileReferenceMediaResource(localFilePath: path, randomId: id), previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "application/text", size: nil, attributes: [.FileName(fileName: name)], alternativeRepresentations: []) return .message(text: "", attributes: [], inlineStickers: [:], mediaReference: .standalone(media: file), threadId: nil, replyToMessageId: nil, replyToStoryId: nil, localGroupingKey: nil, correlationId: nil, bubbleUpEmojiOrStickersets: []) diff --git a/submodules/SSignalKit/SwiftSignalKit/Source/Signal_Combine.swift b/submodules/SSignalKit/SwiftSignalKit/Source/Signal_Combine.swift index 0e3a0301aed..675ccef464b 100644 --- a/submodules/SSignalKit/SwiftSignalKit/Source/Signal_Combine.swift +++ b/submodules/SSignalKit/SwiftSignalKit/Source/Signal_Combine.swift @@ -244,12 +244,6 @@ public func combineLatest(queue: Queue? = nil, _ s1: Signal, _ s2: Signal, _ s3: Signal, _ s4: Signal, _ s5: Signal, _ s6: Signal, _ s7: Signal, _ s8: Signal, _ s9: Signal, _ s10: Signal, _ s11: Signal, _ s12: Signal, _ s13: Signal, _ s14: Signal, _ s15: Signal, _ s16: Signal, _ s17: Signal, _ s18: Signal, _ s19: Signal, _ s20: Signal, _ s21: Signal, _ s22: Signal, _ s23: Signal, _ s24: Signal, _ s25: Signal, _ s26: Signal, _ s27: Signal) -> Signal<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27), E> { - return combineLatestAny([signalOfAny(s1), signalOfAny(s2), signalOfAny(s3), signalOfAny(s4), signalOfAny(s5), signalOfAny(s6), signalOfAny(s7), signalOfAny(s8), signalOfAny(s9), signalOfAny(s10), signalOfAny(s11), signalOfAny(s12), signalOfAny(s13), signalOfAny(s14), signalOfAny(s15), signalOfAny(s16), signalOfAny(s17), signalOfAny(s18), signalOfAny(s19), signalOfAny(s20), signalOfAny(s21), signalOfAny(s22), signalOfAny(s23), signalOfAny(s24), signalOfAny(s25), signalOfAny(s26), signalOfAny(s27)], combine: { values in - return (values[0] as! T1, values[1] as! T2, values[2] as! T3, values[3] as! T4, values[4] as! T5, values[5] as! T6, values[6] as! T7, values[7] as! T8, values[8] as! T9, values[9] as! T10, values[10] as! T11, values[11] as! T12, values[12] as! T13, values[13] as! T14, values[14] as! T15, values[15] as! T16, values[16] as! T17, values[17] as! T18, values[18] as! T19, values[19] as! T20, values[20] as! T21, values[21] as! T22, values[22] as! T23, values[23] as! T24, values[24] as! T25, values[25] as! T26, values[26] as! T27) - }, initialValues: [:], queue: queue) -} - public func combineLatest(queue: Queue? = nil, _ signals: [Signal]) -> Signal<[T], E> { if signals.count == 0 { return single([T](), E.self) diff --git a/submodules/ShareController/Sources/Nicegram/ShareController+Nicegram.swift b/submodules/ShareController/Sources/Nicegram/ShareController+Nicegram.swift deleted file mode 100644 index def44c6141c..00000000000 --- a/submodules/ShareController/Sources/Nicegram/ShareController+Nicegram.swift +++ /dev/null @@ -1,63 +0,0 @@ -import AccountContext -import TelegramCore -import UIKit - -public func shareController( - image: UIImage?, - text: String, - context: AccountContext -) async -> ShareController { - let media = await prepareImage(image: image, context: context) - - let subject: ShareControllerSubject - if let media { - subject = .media(media, text: text) - } else { - subject = .text(text) - } - - return await ShareController( - context: context, - subject: subject - ) -} - -private func prepareImage( - image: UIImage?, - context: AccountContext -) async -> AnyMediaReference? { - guard let image else { - return nil - } - - let account = context.account - let postbox = account.postbox - let network = account.network - let peerId = account.peerId - - // Copied from - // https://bitbucket.org/mobyrix/nicegram-ios/src/develop/submodules/ShareItems/Sources/ShareItems.swift - let nativeImageSize = CGSize(width: image.size.width * image.scale, height: image.size.height * image.scale) - let dimensions = nativeImageSize.fitted(CGSize(width: 1280.0, height: 1280.0)) - if let scaledImage = scalePhotoImage(image, dimensions: dimensions), - let imageData = scaledImage.jpegData(compressionQuality: 0.52) { - let stream = standaloneUploadedImage(postbox: postbox, network: network, peerId: peerId, text: "", data: imageData, dimensions: PixelDimensions(dimensions)).asyncStream(.bufferingNewest(1)) - for await event in stream { - if case let .result(result) = event, - case let .media(media) = result { - return media - } - } - } - - return nil -} - -private func scalePhotoImage(_ image: UIImage, dimensions: CGSize) -> UIImage? { - let format = UIGraphicsImageRendererFormat() - format.scale = 1.0 - let renderer = UIGraphicsImageRenderer(size: dimensions, format: format) - return renderer.image { _ in - image.draw(in: CGRect(origin: .zero, size: dimensions)) - } -} diff --git a/submodules/ShareController/Sources/ShareController.swift b/submodules/ShareController/Sources/ShareController.swift index 3b8eaa433a8..799f962ad19 100644 --- a/submodules/ShareController/Sources/ShareController.swift +++ b/submodules/ShareController/Sources/ShareController.swift @@ -74,8 +74,7 @@ public enum ShareControllerSubject { case quote(text: String, url: String) case messages([Message]) case image([ImageRepresentationWithReference]) - // MARK: Nicegram, text added - case media(AnyMediaReference, text: String = "") + case media(AnyMediaReference) case mapMedia(TelegramMediaMap) case fromExternal(([PeerId], [PeerId: Int64], String, ShareControllerAccountContext, Bool) -> Signal) } @@ -573,8 +572,7 @@ public final class ShareController: ViewController { self?.actionCompleted?() }) } - // MARK: Nicegram, text added - case let .media(mediaReference, _): + case let .media(mediaReference): var canSave = false var isVideo = false if mediaReference.media is TelegramMediaImage { @@ -815,8 +813,7 @@ public final class ShareController: ViewController { return false } } - // MARK: Nicegram, text added - case let .media(mediaReference, _): + case let .media(mediaReference): var sendTextAsCaption = false if mediaReference.media is TelegramMediaImage || mediaReference.media is TelegramMediaFile { sendTextAsCaption = true @@ -1032,9 +1029,8 @@ public final class ShareController: ViewController { case let .image(representations): let media = TelegramMediaImage(imageId: MediaId(namespace: Namespaces.Media.LocalImage, id: Int64.random(in: Int64.min ... Int64.max)), representations: representations.map({ $0.representation }), immediateThumbnailData: nil, reference: nil, partialReference: nil, flags: []) collectableItems.append(CollectableExternalShareItem(url: "", text: "", author: nil, timestamp: nil, mediaReference: .standalone(media: media))) - // MARK: Nicegram, text added - case let .media(mediaReference, text): - collectableItems.append(CollectableExternalShareItem(url: "", text: text, author: nil, timestamp: nil, mediaReference: mediaReference)) + case let .media(mediaReference): + collectableItems.append(CollectableExternalShareItem(url: "", text: "", author: nil, timestamp: nil, mediaReference: mediaReference)) case let .mapMedia(media): let latLong = "\(media.latitude),\(media.longitude)" collectableItems.append(CollectableExternalShareItem(url: "https://maps.apple.com/maps?ll=\(latLong)&q=\(latLong)&t=m", text: "", author: nil, timestamp: nil, mediaReference: nil)) @@ -1574,10 +1570,7 @@ public final class ShareController: ViewController { messages: messages )) } - // MARK: Nicegram, text added - case let .media(mediaReference, string): - let text = "\(text)\n\n\(string)".trimmingCharacters(in: .whitespacesAndNewlines) - + case let .media(mediaReference): var sendTextAsCaption = false if mediaReference.media is TelegramMediaImage || mediaReference.media is TelegramMediaFile { sendTextAsCaption = true @@ -2100,10 +2093,7 @@ public final class ShareController: ViewController { messages = transformMessages(messages, showNames: showNames, silently: silently) shareSignals.append(enqueueMessages(account: currentContext.context.account, peerId: peerId, messages: messages)) } - // MARK: Nicegram, text added - case let .media(mediaReference, string): - let text = "\(text)\n\n\(string)".trimmingCharacters(in: .whitespacesAndNewlines) - + case let .media(mediaReference): var sendTextAsCaption = false if mediaReference.media is TelegramMediaImage || mediaReference.media is TelegramMediaFile { sendTextAsCaption = true diff --git a/submodules/TelegramCore/Sources/Utils/Log.swift b/submodules/TelegramCore/Sources/Utils/Log.swift index 4278b78c028..8936eb663cb 100644 --- a/submodules/TelegramCore/Sources/Utils/Log.swift +++ b/submodules/TelegramCore/Sources/Utils/Log.swift @@ -212,7 +212,35 @@ public final class Logger { return EmptyDisposable } } - +// MARK: Nicegram NCG-5828 call recording + public func collectLogs( + with basePath: String, + accountPathName: String? + ) -> Signal<[(String, String)], NoError> { + guard let accountPathName else { return .never() } + + return Signal { subscriber in + self.queue.async { + let logsPath: String = basePath + "/\(accountPathName)/calls" + var result: [(Date, String, String)] = [] + if let files = try? FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: logsPath), includingPropertiesForKeys: [URLResourceKey.creationDateKey], options: []) { + for url in files { + if url.lastPathComponent.hasSuffix(".log") { + if let creationDate = (try? url.resourceValues(forKeys: Set([.creationDateKey])))?.creationDate { + result.append((creationDate, url.lastPathComponent, url.path)) + } + } + } + } + result.sort(by: { $0.0 < $1.0 }) + subscriber.putNext(result.map { ($0.1, $0.2) }) + subscriber.putCompletion() + } + + return EmptyDisposable + } + } +// public func collectShortLog() -> Signal<[(Double, String)], NoError> { return Signal { subscriber in self.queue.async { diff --git a/submodules/TelegramUI/Components/Chat/ChatHistoryEntry/BUILD b/submodules/TelegramUI/Components/Chat/ChatHistoryEntry/BUILD index 5558de6603f..1d884b45166 100644 --- a/submodules/TelegramUI/Components/Chat/ChatHistoryEntry/BUILD +++ b/submodules/TelegramUI/Components/Chat/ChatHistoryEntry/BUILD @@ -1,9 +1,5 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") -NGDEPS = [ - "@swiftpkg_nicegram_assistant_ios//:FeatAttentionEconomy", -] - swift_library( name = "ChatHistoryEntry", module_name = "ChatHistoryEntry", @@ -13,7 +9,7 @@ swift_library( copts = [ #"-warnings-as-errors", ], - deps = NGDEPS + [ + deps = [ "//submodules/Postbox", "//submodules/TelegramCore", "//submodules/TelegramPresentationData", diff --git a/submodules/TelegramUI/Components/Chat/ChatHistoryEntry/Sources/ChatHistoryEntry.swift b/submodules/TelegramUI/Components/Chat/ChatHistoryEntry/Sources/ChatHistoryEntry.swift index a61de31a34b..79be541f9a3 100644 --- a/submodules/TelegramUI/Components/Chat/ChatHistoryEntry/Sources/ChatHistoryEntry.swift +++ b/submodules/TelegramUI/Components/Chat/ChatHistoryEntry/Sources/ChatHistoryEntry.swift @@ -1,6 +1,3 @@ -// MARK: Nicegram ATT -import FeatAttentionEconomy -// import Postbox import TelegramCore import TelegramPresentationData @@ -51,30 +48,8 @@ public enum ChatHistoryEntry: Identifiable, Comparable { case ReplyCountEntry(MessageIndex, Bool, Int, ChatPresentationData) case ChatInfoEntry(String, String, TelegramMediaImage?, TelegramMediaFile?, ChatPresentationData) case SearchEntry(PresentationTheme, PresentationStrings) - // MARK: Nicegram ATT - case NicegramAdEntry(String, AttAd, ChatPresentationData) - // - // MARK: Nicegram ATT - public enum StableId: Hashable, Comparable { - case uint64(UInt64) - case nicegramAd(String) - - public var uint64Value: UInt64 { - switch self { - case let .uint64(uint64): uint64 - case .nicegramAd: 0 - } - } - - public static func <(lhs: StableId, rhs: StableId) -> Bool { - lhs.uint64Value < rhs.uint64Value - } - } - // - - // MARK: Nicegram ATT, changed UInt64 to StableId - public var stableId: StableId { + public var stableId: UInt64 { switch self { case let .MessageEntry(message, _, _, _, _, attributes): let type: UInt64 @@ -86,27 +61,17 @@ public enum ChatHistoryEntry: Identifiable, Comparable { case .animatedEmoji: type = 4 } - // MARK: Nicegram ATT, wrap in .uint64() - return .uint64(UInt64(message.stableId) | ((type << 40))) + return UInt64(message.stableId) | ((type << 40)) case let .MessageGroupEntry(groupInfo, _, _): - // MARK: Nicegram ATT, wrap in .uint64() - return .uint64(UInt64(bitPattern: groupInfo) | ((UInt64(2) << 40))) + return UInt64(bitPattern: groupInfo) | ((UInt64(2) << 40)) case .UnreadEntry: - // MARK: Nicegram ATT, wrap in .uint64() - return .uint64(UInt64(4) << 40) + return UInt64(4) << 40 case .ReplyCountEntry: - // MARK: Nicegram ATT, wrap in .uint64() - return .uint64(UInt64(5) << 40) + return UInt64(5) << 40 case .ChatInfoEntry: - // MARK: Nicegram ATT, wrap in .uint64() - return .uint64(UInt64(6) << 40) + return UInt64(6) << 40 case .SearchEntry: - // MARK: Nicegram ATT, wrap in .uint64() - return .uint64(UInt64(7) << 40) - // MARK: Nicegram ATT - case let .NicegramAdEntry(id, _, _): - return .nicegramAd(id) - // + return UInt64(7) << 40 } } @@ -124,10 +89,6 @@ public enum ChatHistoryEntry: Identifiable, Comparable { return MessageIndex.absoluteLowerBound() case .SearchEntry: return MessageIndex.absoluteLowerBound() - // MARK: Nicegram ATT - case .NicegramAdEntry: - return MessageIndex.absoluteLowerBound() - // } } @@ -145,10 +106,6 @@ public enum ChatHistoryEntry: Identifiable, Comparable { return MessageIndex.absoluteLowerBound() case .SearchEntry: return MessageIndex.absoluteLowerBound() - // MARK: Nicegram ATT - case .NicegramAdEntry: - return MessageIndex.absoluteLowerBound() - // } } @@ -327,17 +284,6 @@ public enum ChatHistoryEntry: Identifiable, Comparable { } else { return false } - // MARK: Nicegram ATT - case let .NicegramAdEntry(lhsId, lhsAd, lhsPresentationData): - if case let .NicegramAdEntry(rhsId, rhsAd, rhsPresentationData) = rhs, - lhsId == rhsId, - lhsAd == rhsAd, - lhsPresentationData === rhsPresentationData { - return true - } else { - return false - } - // } } diff --git a/submodules/TelegramUI/Components/Chat/ChatMessageItemImpl/BUILD b/submodules/TelegramUI/Components/Chat/ChatMessageItemImpl/BUILD index 07c49d0beec..26c721aa8e7 100644 --- a/submodules/TelegramUI/Components/Chat/ChatMessageItemImpl/BUILD +++ b/submodules/TelegramUI/Components/Chat/ChatMessageItemImpl/BUILD @@ -28,7 +28,6 @@ swift_library( "//submodules/TelegramUI/Components/Chat/ChatMessageStickerItemNode", "//submodules/TelegramUI/Components/Chat/ChatMessageAnimatedStickerItemNode", "//submodules/TelegramUI/Components/Chat/ChatMessageBubbleItemNode", - "//submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode", "//submodules/AvatarNode", "//submodules/TelegramUniversalVideoContent", "//submodules/MediaPlayer:UniversalMediaPlayer", diff --git a/submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/BUILD b/submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/BUILD deleted file mode 100644 index 21bc4c974bc..00000000000 --- a/submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/BUILD +++ /dev/null @@ -1,26 +0,0 @@ -load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") - -# todo: cleanup -swift_library( - name = "ChatMessageNicegramAdNode", - module_name = "ChatMessageNicegramAdNode", - srcs = glob([ - "Sources/**/*.swift", - ]), - copts = [ - #"-warnings-as-errors", - ], - deps = [ - "//submodules/AsyncDisplayKit", - "//submodules/TelegramUI/Components/ChatControllerInteraction", - "//submodules/TelegramUI/Components/Chat/ChatMessageItemCommon", - "//submodules/TelegramUI/Components/Chat/ChatMessageItemView", - "//submodules/Display", - "//submodules/SSignalKit/SwiftSignalKit", - "//submodules/TelegramPresentationData", - "@swiftpkg_nicegram_assistant_ios//:FeatAttentionEconomy", - ], - visibility = [ - "//visibility:public", - ], -) diff --git a/submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/Sources/ChatMessageNicegramAdItem.swift b/submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/Sources/ChatMessageNicegramAdItem.swift deleted file mode 100644 index cd3880cde63..00000000000 --- a/submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/Sources/ChatMessageNicegramAdItem.swift +++ /dev/null @@ -1,70 +0,0 @@ -import FeatAttentionEconomy - -import AccountContext -import ChatControllerInteraction -import Display -import Foundation -import SwiftSignalKit -import TelegramPresentationData - -@available(iOS 15.0, *) -public final class ChatMessageNicegramAdItem: ListViewItem { - public let ad: AttAd - public let context: AccountContext - public let controllerInteraction: ChatControllerInteraction - public let presentationData: ChatPresentationData - - public init(ad: AttAd, context: AccountContext, controllerInteraction: ChatControllerInteraction, presentationData: ChatPresentationData) { - self.ad = ad - self.context = context - self.controllerInteraction = controllerInteraction - self.presentationData = presentationData - } - - public func nodeConfiguredForParams( - async: @escaping (@escaping () -> Void) -> Void, - params: ListViewItemLayoutParams, - synchronousLoads: Bool, - previousItem: ListViewItem?, - nextItem: ListViewItem?, - completion: @escaping (ListViewItemNode, @escaping () -> (Signal?, (ListViewItemApply) -> Void)) -> Void - ) { - let configure = { () -> Void in - let node = ChatMessageNicegramAdNode(rotated: self.controllerInteraction.chatIsRotated) - node.setupItem(self) - - let nodeLayout = node.asyncLayout() - let (layout, apply) = nodeLayout(self, params, false, false, false) - - node.contentSize = layout.contentSize - node.insets = layout.insets - - completion(node, { - return (nil, { _ in apply(.None) }) - }) - } - if Thread.isMainThread { - configure() - } else { - Queue.mainQueue().async(configure) - } - } - - public func updateNode(async: @escaping (@escaping () -> Void) -> Void, node: @escaping () -> ListViewItemNode, params: ListViewItemLayoutParams, previousItem: ListViewItem?, nextItem: ListViewItem?, animation: ListViewItemUpdateAnimation, completion: @escaping (ListViewItemNodeLayout, @escaping (ListViewItemApply) -> Void) -> Void) { - Queue.mainQueue().async { - if let nodeValue = node() as? ChatMessageNicegramAdNode { - nodeValue.setupItem(self) - - let nodeLayout = nodeValue.asyncLayout() - - let (layout, apply) = nodeLayout(self, params, false, false, false) - - completion(layout, { _ in - apply(animation) - }) - } else { - assertionFailure() - } - } - } -} diff --git a/submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/Sources/ChatMessageNicegramAdNode.swift b/submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/Sources/ChatMessageNicegramAdNode.swift deleted file mode 100644 index e006426efa3..00000000000 --- a/submodules/TelegramUI/Components/Chat/ChatMessageNicegramAdNode/Sources/ChatMessageNicegramAdNode.swift +++ /dev/null @@ -1,162 +0,0 @@ -import FeatAttentionEconomy - -import AsyncDisplayKit -import ChatMessageItemCommon -import ChatMessageItemView -import Display -import ShareController - -@available(iOS 15.0, *) -class ChatMessageNicegramAdNode: ListViewItemNode { - private let layoutConstants = (ChatMessageItemLayoutConstants.compact, ChatMessageItemLayoutConstants.regular) - - var item: ChatMessageNicegramAdItem? - - private let bannerView: AttChatBanner - private let bannerNode: ASDisplayNode - - override var visibility: ListViewItemNodeVisibility { - didSet { - let visiblePart: Double - switch visibility { - case .none: - visiblePart = 0.0 - case let .visible(part, _): - visiblePart = part - } - - bannerView.set(visiblePart: visiblePart) - } - } - - required init(rotated: Bool) { - let bannerView = AttChatBanner() - self.bannerView = bannerView - self.bannerNode = ASDisplayNode { - bannerView - } - - super.init(layerBacked: false, dynamicBounce: true, rotated: rotated) - - if rotated { - self.transform = CATransform3DMakeRotation(CGFloat.pi, 0.0, 0.0, 1.0) - } - - self.addSubnode(bannerNode) - - bannerView.share = { [weak self] image, text in - guard let item = self?.item else { return } - Task { @MainActor in - let shareController = await shareController( - image: image, - text: text, - context: item.context - ) - item.controllerInteraction.presentController(shareController, nil) - } - } - } - - func setupItem(_ item: ChatMessageNicegramAdItem) { - self.item = item - } - - override func layoutForParams(_ params: ListViewItemLayoutParams, item: ListViewItem, previousItem: ListViewItem?, nextItem: ListViewItem?) { - - } - - func asyncLayout() -> (_ item: ChatMessageNicegramAdItem, _ params: ListViewItemLayoutParams, _ mergedTop: Bool, _ mergedBottom: Bool, _ dateAtBottom: Bool) -> (ListViewItemNodeLayout, (ListViewItemUpdateAnimation) -> Void) { - return { [weak self] item, params, mergedTop, mergedBottom, dateHeaderAtBottom -> (ListViewItemNodeLayout, (ListViewItemUpdateAnimation) -> Void) in - guard let self else { - return ( - ListViewItemNodeLayout( - contentSize: .zero, - insets: .zero - ), - { _ in } - ) - } - - let presentationData = item.presentationData - let messagePresentationData = item.presentationData.theme.theme.chat.message - let incomingBubble = if presentationData.theme.wallpaper.hasWallpaper { - messagePresentationData.incoming.bubble.withWallpaper - } else { - messagePresentationData.incoming.bubble.withoutWallpaper - } - let bannerPresentationData = AttChatBannerPresentationData( - incomingBubble: .init( - backgroundColor: incomingBubble.fill.first ?? .black, - primaryTextColor: messagePresentationData.incoming.primaryTextColor - ), - messageFont: presentationData.messageFont, - messageBoldFont: presentationData.messageBoldFont - ) - - let layoutConstants = chatMessageItemLayoutConstants(layoutConstants, params: params, presentationData: presentationData) - let maximumWidthFill = layoutConstants.bubble.maximumWidthFill.widthFor(params.width) - let layoutParams = AttChatBannerLayoutParams( - insets: layoutConstants.bubble.contentInsets - .sum(.vertical(layoutConstants.bubble.defaultSpacing)) - .sum(.horizontal(layoutConstants.bubble.edgeInset)) - .sum(.left(params.leftInset).right(params.rightInset)), - maximumWidthFill: maximumWidthFill - ) - - bannerView.set( - ad: item.ad, - layoutParams: layoutParams, - presentationData: bannerPresentationData - ) - bannerView.layoutIfNeeded() - let bannerSize = bannerView.systemLayoutSizeFitting( - UIView.layoutFittingExpandedSize - ) - let size = CGSize( - width: params.width, - height: bannerSize.height - ) - - let layout = ListViewItemNodeLayout( - contentSize: size, - insets: .zero - ) - - let apply: (ListViewItemUpdateAnimation) -> Void = { [weak self] _ in - guard let self else { return } - bannerNode.frame = CGRect(origin: .zero, size: size) - } - - return (layout, apply) - } - } - - override public func animateInsertion(_ currentTimestamp: Double, duration: Double, options: ListViewItemAnimationOptions) { - super.animateInsertion(currentTimestamp, duration: duration, options: options) - - self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) - } - - override public func animateRemoved(_ currentTimestamp: Double, duration: Double) { - super.animateRemoved(currentTimestamp, duration: duration) - - self.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false) - } - - override public func animateAdded(_ currentTimestamp: Double, duration: Double) { - super.animateAdded(currentTimestamp, duration: duration) - - self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) - } -} - -private extension UIEdgeInsets { - func sum(_ other: UIEdgeInsets) -> UIEdgeInsets { - UIEdgeInsets( - top: self.top + other.top, - left: self.left + other.left, - bottom: self.bottom + other.bottom, - right: self.right + other.right - ) - } -} diff --git a/submodules/TelegramUI/Sources/AppDelegate.swift b/submodules/TelegramUI/Sources/AppDelegate.swift index 658c0090a09..41d19a0a7a9 100644 --- a/submodules/TelegramUI/Sources/AppDelegate.swift +++ b/submodules/TelegramUI/Sources/AppDelegate.swift @@ -412,7 +412,6 @@ private class UserInterfaceStyleObserverWindow: UIWindow { env: Env( apiBaseUrl: URL(string: NGENV.ng_api_url)!, apiKey: NGENV.ng_api_key, - enableLogging: ngEnableLogging, isAppStoreBuild: buildConfig.isAppStoreBuild, premiumProductId: NGENV.premium_bundle, privacyUrl: URL(string: NGENV.privacy_url)!, diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 8bdc16d40dd..0e270f95a0f 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -54,7 +54,6 @@ import TooltipUI import StatisticsUI import NGWebUtils // MARK: Nicegram Imports -import FeatTgUtils import NGAppCache import NGStrings import NGUI @@ -618,11 +617,6 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var powerSavingMonitoringDisposable: Disposable? - // MARK: Nicegram - private var nicegramCloseCallback: (() -> Void)? - private var nicegramCloseCallbackDisposable: Disposable? - // - var avatarNode: ChatAvatarNavigationNode? var storyStats: PeerStoryStats? @@ -7059,11 +7053,6 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return state.updatedInterfaceState({ $0.withUpdatedSelectedMessages(messageIds) }) }) } - - // MARK: Nicegram - self.nicegramCloseCallback = TgChatCloseCallback.callback - TgChatCloseCallback.callback = nil - // } required public init(coder aDecoder: NSCoder) { @@ -7167,9 +7156,6 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G self.recorderDataDisposable.dispose() self.displaySendWhenOnlineTipDisposable.dispose() self.networkSpeedEventsDisposable?.dispose() - // MARK: Nicegram - self.nicegramCloseCallbackDisposable?.dispose() - // } deallocate() } @@ -7696,19 +7682,6 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } self.hasBrowserOrAppInFront.set(hasBrowserOrWebAppInFront) } - - // MARK: Nicegram - self.nicegramCloseCallbackDisposable = self.effectiveNavigationController?.viewControllersSignal.start( - next: { [weak self] controllers in - guard let self else { return } - - if !controllers.contains(where: { $0 === self }) { - self.nicegramCloseCallback?() - self.nicegramCloseCallback = nil - } - } - ) - // } var returnInputViewFocus = false diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index a0ca9508c9b..8bf0f750faf 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -1,7 +1,3 @@ -// MARK: Nicegram ATT -import ChatMessageNicegramAdNode -import FeatAttentionEconomy -// // MARK: Nicegram AiChat import NGAiChatUI // @@ -280,14 +276,6 @@ private func mappedInsertEntries(context: AccountContext, chatLocation: ChatLoca return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListSearchItem(theme: theme, placeholder: strings.Common_Search, activate: { controllerInteraction.openSearch() }), directionHint: entry.directionHint) - // MARK: Nicegram ATT - case let .NicegramAdEntry(_, ad, presentationData): - if #available(iOS 15.0, *) { - return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatMessageNicegramAdItem(ad: ad, context: context, controllerInteraction: controllerInteraction, presentationData: presentationData), directionHint: entry.directionHint) - } else { - fatalError() - } - // } } } @@ -340,14 +328,6 @@ private func mappedUpdateEntries(context: AccountContext, chatLocation: ChatLoca return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListSearchItem(theme: theme, placeholder: strings.Common_Search, activate: { controllerInteraction.openSearch() }), directionHint: entry.directionHint) - // MARK: Nicegram ATT - case let .NicegramAdEntry(_, ad, presentationData): - if #available(iOS 15.0, *) { - return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatMessageNicegramAdItem(ad: ad, context: context, controllerInteraction: controllerInteraction, presentationData: presentationData), directionHint: entry.directionHint) - } else { - fatalError() - } - // } } } @@ -1672,27 +1652,6 @@ public final class ChatHistoryListNodeImpl: ListView, ChatHistoryNode, ChatHisto return files } - // MARK: Nicegram ATT - let getPlacementAdsUseCase = AttCoreModule.shared.getPlacementAdsUseCase() - let getSettingsUseCase = AttCoreModule.shared.getSettingsUseCase() - let nicegramAd = getPlacementAdsUseCase - .publisher(placementId: .chat) - .combineLatestThreadSafe( - getSettingsUseCase.publisher() - ) - .map { ad, settings in - let enableAds = settings.enableAds - let enablePlacement = settings.settings(for: .chat)?.enabled ?? false - let forceRemove = !enableAds || !enablePlacement - return NicegramAdInChat( - ad: ad, - forceRemove: forceRemove - ) - } - .toSignal() - .skipError() - // - let messageViewQueue = Queue.mainQueue() let historyViewTransitionDisposable = combineLatest(queue: messageViewQueue, historyViewUpdate, @@ -1720,10 +1679,8 @@ public final class ChatHistoryListNodeImpl: ListView, ChatHistoryNode, ChatHisto chatThemes, deviceContactsNumbers, contentSettings, - starGifts, - // MARK: Nicegram ATT - nicegramAd - ).startStrict(next: { [weak self] update, chatPresentationData, selectedMessages, updatingMedia, networkType, preferredStoryHighQuality, animatedEmojiStickers, additionalAnimatedEmojiStickers, customChannelDiscussionReadState, customThreadOutgoingReadState, availableReactions, availableMessageEffects, savedMessageTags, defaultReaction, accountPeer, suggestAudioTranscription, promises, topicAuthorId, translationState, maxReadStoryId, recommendedChannels, audioTranscriptionTrial, chatThemes, deviceContactsNumbers, contentSettings, starGifts, nicegramAd in + starGifts + ).startStrict(next: { [weak self] update, chatPresentationData, selectedMessages, updatingMedia, networkType, preferredStoryHighQuality, animatedEmojiStickers, additionalAnimatedEmojiStickers, customChannelDiscussionReadState, customThreadOutgoingReadState, availableReactions, availableMessageEffects, savedMessageTags, defaultReaction, accountPeer, suggestAudioTranscription, promises, topicAuthorId, translationState, maxReadStoryId, recommendedChannels, audioTranscriptionTrial, chatThemes, deviceContactsNumbers, contentSettings, starGifts in let (historyAppearsCleared, pendingUnpinnedAllMessages, pendingRemovedMessages, currentlyPlayingMessageIdAndType, scrollToMessageId, chatHasBots, allAdMessages) = promises func applyHole() { @@ -1952,8 +1909,7 @@ public final class ChatHistoryListNodeImpl: ListView, ChatHistoryNode, ChatHisto let previousChatHistoryEntriesForViewState = chatHistoryEntriesForViewState.with({ $0 }) - // MARK: Nicegram ATT, changed 'let' to 'var' - var (filteredEntries, updatedChatHistoryEntriesForViewState) = chatHistoryEntriesForView( + let (filteredEntries, updatedChatHistoryEntriesForViewState) = chatHistoryEntriesForView( currentState: previousChatHistoryEntriesForViewState, context: context, location: chatLocation, @@ -1980,26 +1936,6 @@ public final class ChatHistoryListNodeImpl: ListView, ChatHistoryNode, ChatHisto adMessage: allAdMessages.fixed, dynamicAdMessages: allAdMessages.opportunistic ) - // MARK: Nicegram ATT - if let self { - var cachedPeerData: CachedPeerData? - for entry in view.additionalData { - if case let .cachedPeerData(_, maybeCachedPeerData) = entry, let maybeCachedPeerData { - cachedPeerData = maybeCachedPeerData - } - } - - filteredEntries = nicegramMapChatHistoryEntries( - oldEntries: previousView.with { $0?.0.filteredEntries } ?? [], - newEntries: filteredEntries, - nicegramAd: nicegramAd, - visibleItemRange: self.displayedItemRange.visibleRange, - chatPresentationData: chatPresentationData, - cachedPeerData: cachedPeerData - ) - } - // - let lastHeaderId = filteredEntries.last.flatMap { listMessageDateHeaderId(timestamp: $0.index.timestamp) } ?? 0 let processedView = ChatHistoryView(originalView: view, filteredEntries: filteredEntries, associatedData: associatedData, lastHeaderId: lastHeaderId, id: id, locationInput: update.2, ignoreMessagesInTimestampRange: update.3, ignoreMessageIds: update.4) let previousValueAndVersion = previousView.swap((processedView, update.1, selectedMessages, allAdMessages.version)) diff --git a/submodules/TelegramUI/Sources/Nicegram/NGDeeplinkHandler.swift b/submodules/TelegramUI/Sources/Nicegram/NGDeeplinkHandler.swift index 50027f6d42b..7b92293466b 100644 --- a/submodules/TelegramUI/Sources/Nicegram/NGDeeplinkHandler.swift +++ b/submodules/TelegramUI/Sources/Nicegram/NGDeeplinkHandler.swift @@ -1,5 +1,4 @@ import FeatAssistant -import FeatAttentionEconomy import Foundation import AccountContext import Display @@ -22,7 +21,6 @@ import NGUI import TelegramPresentationData import UIKit -@MainActor class NGDeeplinkHandler { // MARK: - Dependencies @@ -62,14 +60,12 @@ class NGDeeplinkHandler { return handleAssistant(url: url) case "assistant-auth": return handleLoginToAssistant(url: url) - case "attention-economy": - if #available(iOS 15.0, *) { - AttPresenter().present() - } - return true case "avatarGenerator": if #available(iOS 15.0, *) { - if let topController = UIApplication.topViewController { + Task { @MainActor in + guard let topController = UIApplication.topViewController else { + return + } AvatarGeneratorUIHelper().navigateToGenerationFlow( from: topController ) @@ -78,7 +74,9 @@ class NGDeeplinkHandler { return true case "avatarMyGenerations": if #available(iOS 15.0, *) { - AvatarGeneratorUIHelper().navigateToGenerator() + Task { @MainActor in + AvatarGeneratorUIHelper().navigateToGenerator() + } } return true case "generateImage": @@ -89,16 +87,26 @@ class NGDeeplinkHandler { return handleOnboarding(url: url) case "profit": if #available(iOS 15.0, *) { - RewardsUITgHelper.showRewards() + Task { @MainActor in + RewardsUITgHelper.showRewards() + } } return true case "specialOffer": - return handleSpecialOffer(url: url) + if #available(iOS 13.0, *) { + return handleSpecialOffer(url: url) + } else { + return false + } case "refferaldraw": if #available(iOS 15.0, *) { - AssistantTgHelper.showReferralDrawFromDeeplink() + Task { @MainActor in + AssistantTgHelper.showReferralDrawFromDeeplink() + } + return true + } else { + return false } - return true case "task": if #available(iOS 15.0, *) { let taskDeeplinkHandler = TasksContainer.shared.taskDeeplinkHandler() @@ -107,7 +115,9 @@ class NGDeeplinkHandler { return true case "tgAuthSuccess": if #available(iOS 15.0, *) { - TgAuthSuccessPresenter().presentIfNeeded() + Task { @MainActor in + TgAuthSuccessPresenter().presentIfNeeded() + } } return true default: @@ -121,23 +131,37 @@ class NGDeeplinkHandler { private extension NGDeeplinkHandler { func handleAiAuth(url: URL) -> Bool { - AiChatUITgHelper.routeToAiOnboarding() - return true + if #available(iOS 13.0, *) { + Task { @MainActor in + AiChatUITgHelper.routeToAiOnboarding() + } + return true + } + return false } func handleAi(url: URL) -> Bool { - AiChatUITgHelper.tryRouteToAiChatBotFromDeeplink() - return true + if #available(iOS 13.0, *) { + Task { @MainActor in + AiChatUITgHelper.tryRouteToAiChatBotFromDeeplink() + } + return true + } + return false } func handleGenerateImage(url: URL) -> Bool { if #available(iOS 15.0, *) { - ImagesHubUITgHelper.showFeed( - source: .deeplink, - forceGeneration: true - ) + Task { @MainActor in + ImagesHubUITgHelper.showFeed( + source: .deeplink, + forceGeneration: true + ) + } + return true + } else { + return false } - return true } func handleNicegramPremium(url: URL) -> Bool { @@ -149,11 +173,15 @@ private extension NGDeeplinkHandler { func handleAssistant(url: URL) -> Bool { if #available(iOS 15.0, *) { - AssistantTgHelper.routeToAssistant( - source: .deeplink - ) + Task { @MainActor in + AssistantTgHelper.routeToAssistant( + source: .deeplink + ) + } + return true + } else { + return false } - return true } func handleOnboarding(url: URL) -> Bool { @@ -182,16 +210,21 @@ private extension NGDeeplinkHandler { return false } - LoginViewPresenter().present( - feature: LoginFeature() - ) + Task { @MainActor in + LoginViewPresenter().present( + feature: LoginFeature() + ) + } return true } + @available(iOS 13.0, *) func handleSpecialOffer(url: URL) -> Bool { - SpecialOfferTgHelper.showSpecialOfferFromDeeplink( - id: url.queryItems["id"] - ) + Task { @MainActor in + SpecialOfferTgHelper.showSpecialOfferFromDeeplink( + id: url.queryItems["id"] + ) + } return true } } diff --git a/submodules/TelegramUI/Sources/Nicegram/NicegramMapChatHistoryEntries.swift b/submodules/TelegramUI/Sources/Nicegram/NicegramMapChatHistoryEntries.swift deleted file mode 100644 index bd40d9ce1eb..00000000000 --- a/submodules/TelegramUI/Sources/Nicegram/NicegramMapChatHistoryEntries.swift +++ /dev/null @@ -1,218 +0,0 @@ -import FeatAttentionEconomy -import Foundation -import NGUtils - -import ChatHistoryEntry -import Display -import Postbox -import TelegramPresentationData - -private let TOP_OFFSET_FROM_VISIBLE_RANGE = 10 -private let BOTTOM_OFFSET_FROM_VISIBLE_RANGE = 10 -private let THRESHOLD_MEMBERS = 1000 - -struct NicegramAdInChat { - let ad: AttAd? - let forceRemove: Bool -} - -func nicegramMapChatHistoryEntries( - oldEntries: [ChatHistoryEntry], - newEntries: [ChatHistoryEntry], - nicegramAd: NicegramAdInChat, - visibleItemRange: ListViewVisibleItemRange?, - chatPresentationData: ChatPresentationData, - cachedPeerData: CachedPeerData? -) -> [ChatHistoryEntry] { - var result = newEntries - - guard !nicegramAd.forceRemove else { - return result - } - let nicegramAd = nicegramAd.ad - - guard areAdsAllowed( - cachedPeerData: cachedPeerData - ) else { - return result - } - - guard let visibleRange = parseVisibleRange( - oldEntries: oldEntries, - visibleItemRange: visibleItemRange - ) else { - return result - } - - result = insertOldAdEntries( - oldEntries: oldEntries, - result: result, - nicegramAd: nicegramAd, - visibleRange: visibleRange - ) - result = updateOldAdEntries( - result: result, - nicegramAd: nicegramAd - ) - result = insertNewAdEntries( - result: result, - nicegramAd: nicegramAd, - visibleRange: visibleRange, - chatPresentationData: chatPresentationData - ) - - return result -} - -private func areAdsAllowed( - cachedPeerData: CachedPeerData? -) -> Bool { - guard #available(iOS 15.0, *) else { - return false - } - - let membersCount = getMembersCount(cachedPeerData: cachedPeerData) - if let membersCount, membersCount > THRESHOLD_MEMBERS { - return true - } else { - return false - } -} - -private func parseVisibleRange( - oldEntries: [ChatHistoryEntry], - visibleItemRange: ListViewVisibleItemRange? -) -> Range? { - guard let visibleItemRange else { - return nil - } - let leftIndex = oldEntries.count - 1 - visibleItemRange.lastIndex - let rightIndex = oldEntries.count - 1 - visibleItemRange.firstIndex - guard leftIndex <= rightIndex else { - return nil - } - return leftIndex.. -) -> [ChatHistoryEntry] { - struct OldEntry { - let entry: ChatHistoryEntry - let index: Int - } - - var result = result - - let filteredOldEntries = oldEntries.enumerated() - .filter { _, entry in - if case .NicegramAdEntry = entry { - true - } else { - result.contains { entry.stableId == $0.stableId } - } - } - .map { OldEntry(entry: $1, index: $0) } - - filteredOldEntries.forEachWithNeighbors { left, mid, right in - let entry = mid.entry - let index = mid.index - - guard case let .NicegramAdEntry(_, ad, _) = entry else { - return - } - - let isCurrentAd = (nicegramAd?.adId == ad.adId) - let isVisible = visibleRange.contains(index) - - if isCurrentAd || isVisible { - let targetIndex: Int - if let left, let index = result.firstIndex(where: { $0.stableId == left.entry.stableId }) { - targetIndex = index + 1 - } else if let right, let index = result.firstIndex(where: { $0.stableId == right.entry.stableId }) { - targetIndex = index - } else { - targetIndex = 0 - } - - result.insert(entry, at: targetIndex) - } - } - - return result -} - -private func updateOldAdEntries( - result: [ChatHistoryEntry], - nicegramAd: AttAd? -) -> [ChatHistoryEntry] { - guard let nicegramAd else { - return result - } - - return result.map { entry in - if case let .NicegramAdEntry(id, ad, presentationData) = entry, - ad.adId == nicegramAd.adId { - .NicegramAdEntry(id, nicegramAd, presentationData) - } else { - entry - } - } -} - -private func insertNewAdEntries( - result: [ChatHistoryEntry], - nicegramAd: AttAd?, - visibleRange: Range, - chatPresentationData: ChatPresentationData -) -> [ChatHistoryEntry] { - var result = result - - guard let nicegramAd else { - return result - } - - let alreadyContainsAd = result.contains { - if case let .NicegramAdEntry(_, ad, _) = $0, - ad.adId == nicegramAd.adId { - true - } else { - false - } - } - if !alreadyContainsAd { - let indicesToInsert = [ - visibleRange.lowerBound - TOP_OFFSET_FROM_VISIBLE_RANGE, - visibleRange.upperBound + BOTTOM_OFFSET_FROM_VISIBLE_RANGE - ] - indicesToInsert.forEach { index in - let index = index.clamped(to: result.startIndex...result.endIndex) - - if index != result.endIndex { - result.insert( - .NicegramAdEntry( - UUID().uuidString, - nicegramAd, - chatPresentationData - ), - at: index - ) - } - } - } - - return result -} - -private extension Array { - func forEachWithNeighbors(_ body: (Element?, Element, Element?) -> Void) { - for i in 0.. 0 ? self[i - 1] : nil - let right = i < self.count - 1 ? self[i + 1] : nil - body(left, self[i], right) - } - } -} diff --git a/submodules/TgVoipWebrtc/tgcalls b/submodules/TgVoipWebrtc/tgcalls index 29ab3249d1b..c8182281264 160000 --- a/submodules/TgVoipWebrtc/tgcalls +++ b/submodules/TgVoipWebrtc/tgcalls @@ -1 +1 @@ -Subproject commit 29ab3249d1b8916f960442ba3d56ad31778c8084 +Subproject commit c818228126433530740ec798ba2e89127a1f785a