From 1640a8c76f745ab30ae5994ff1fcdf70746410ab Mon Sep 17 00:00:00 2001 From: Ali <> Date: Thu, 20 Apr 2023 19:22:25 +0400 Subject: [PATCH] Refactoring [skip ci] --- .../Sources/LegacyLiveUploadInterface.swift | 16 +++---- .../Sources/SecureIdAuthControllerNode.swift | 2 +- .../Sources/SecureIdAuthFormContentNode.swift | 7 ++- .../Sources/SecureIdAuthHeaderNode.swift | 1 - .../Sources/ChannelBlacklistController.swift | 48 ++++++++++--------- .../ProxyListSettingsController.swift | 4 +- .../ProxyServerSettingsController.swift | 5 +- .../ProxySettingsServerItem.swift | 1 - .../Sources/VoiceChatController.swift | 2 +- .../Sources/VoiceChatParticipantItem.swift | 19 ++++---- .../State/MessageMediaPreuploadManager.swift | 13 +++-- .../Data/OrderedListsData.swift | 42 ++++++++++++++++ .../Resources/TelegramEngineResources.swift | 2 +- .../PresentationThemeEssentialGraphics.swift | 1 - .../Sources/EmojiStatusPreviewScreen.swift | 1 - .../EmojiStatusSelectionComponent.swift | 28 +++++------ .../Sources/EmojiSuggestionsComponent.swift | 9 ++-- 17 files changed, 121 insertions(+), 80 deletions(-) diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyLiveUploadInterface.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyLiveUploadInterface.swift index 3c9dae033a..ce818b9685 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyLiveUploadInterface.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyLiveUploadInterface.swift @@ -1,6 +1,5 @@ import Foundation import UIKit -import Postbox import TelegramCore import LegacyComponents import SwiftSignalKit @@ -49,8 +48,8 @@ public final class LegacyLiveUploadInterface: VideoConversionWatcher, TGLiveUplo private var path: String? private var size: Int? - private let data = Promise() - private let dataValue = Atomic(value: nil) + private let data = Promise() + private let dataValue = Atomic(value: nil) public init(context: AccountContext) { self.context = context @@ -70,14 +69,13 @@ public final class LegacyLiveUploadInterface: VideoConversionWatcher, TGLiveUplo strongSelf.size = size let result = strongSelf.dataValue.modify { dataValue in - if let dataValue = dataValue, dataValue.complete { - return MediaResourceData(path: path, offset: 0, size: Int64(size), complete: true) + if let dataValue = dataValue, dataValue.isComplete { + return EngineMediaResource.ResourceData(path: path, availableSize: Int64(size), isComplete: true) } else { - return MediaResourceData(path: path, offset: 0, size: Int64(size), complete: false) + return EngineMediaResource.ResourceData(path: path, availableSize: Int64(size), isComplete: false) } } if let result = result { - print("**set1 \(result) \(result.complete)") strongSelf.data.set(.single(result)) } } @@ -89,17 +87,15 @@ public final class LegacyLiveUploadInterface: VideoConversionWatcher, TGLiveUplo override public func fileUpdated(_ completed: Bool) -> Any! { let _ = super.fileUpdated(completed) - print("**fileUpdated \(completed)") if completed { let result = self.dataValue.modify { dataValue in if let dataValue = dataValue { - return MediaResourceData(path: dataValue.path, offset: dataValue.offset, size: dataValue.size, complete: true) + return EngineMediaResource.ResourceData(path: dataValue.path, availableSize: dataValue.availableSize, isComplete: true) } else { return nil } } if let result = result { - print("**set2 \(result) \(completed)") self.data.set(.single(result)) return LegacyLiveUploadInterfaceResult(id: self.id) } else { diff --git a/submodules/PassportUI/Sources/SecureIdAuthControllerNode.swift b/submodules/PassportUI/Sources/SecureIdAuthControllerNode.swift index 3f14922c1f..a4e0ff2753 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthControllerNode.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthControllerNode.swift @@ -303,7 +303,7 @@ final class SecureIdAuthControllerNode: ViewControllerTracingNode { current.updateValues(formData.values) contentNode = current } else { - let current = SecureIdAuthFormContentNode(theme: self.presentationData.theme, strings: self.presentationData.strings, nameDisplayOrder: self.presentationData.nameDisplayOrder, peer: encryptedFormData.servicePeer, privacyPolicyUrl: encryptedFormData.form.termsUrl, form: formData, primaryLanguageByCountry: encryptedFormData.primaryLanguageByCountry, openField: { [weak self] field in + let current = SecureIdAuthFormContentNode(theme: self.presentationData.theme, strings: self.presentationData.strings, nameDisplayOrder: self.presentationData.nameDisplayOrder, peer: EnginePeer(encryptedFormData.servicePeer), privacyPolicyUrl: encryptedFormData.form.termsUrl, form: formData, primaryLanguageByCountry: encryptedFormData.primaryLanguageByCountry, openField: { [weak self] field in if let strongSelf = self { switch field { case .identity, .address: diff --git a/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift b/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift index 3b1f79e9fd..55ccbd1e97 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import AsyncDisplayKit import Display -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -24,7 +23,7 @@ final class SecureIdAuthFormContentNode: ASDisplayNode, SecureIdAuthContentNode, private let requestLayout: () -> Void private var validLayout: CGFloat? - init(theme: PresentationTheme, strings: PresentationStrings, nameDisplayOrder: PresentationPersonNameOrder, peer: Peer, privacyPolicyUrl: String?, form: SecureIdForm, primaryLanguageByCountry: [String: String], openField: @escaping (SecureIdParsedRequestedFormField) -> Void, openURL: @escaping (String) -> Void, openMention: @escaping (TelegramPeerMention) -> Void, requestLayout: @escaping () -> Void) { + init(theme: PresentationTheme, strings: PresentationStrings, nameDisplayOrder: PresentationPersonNameOrder, peer: EnginePeer, privacyPolicyUrl: String?, form: SecureIdForm, primaryLanguageByCountry: [String: String], openField: @escaping (SecureIdParsedRequestedFormField) -> Void, openURL: @escaping (String) -> Void, openMention: @escaping (TelegramPeerMention) -> Void, requestLayout: @escaping () -> Void) { self.requestLayout = requestLayout self.primaryLanguageByCountry = primaryLanguageByCountry @@ -57,13 +56,13 @@ final class SecureIdAuthFormContentNode: ASDisplayNode, SecureIdAuthContentNode, let privacyPolicyAttributes = MarkdownAttributeSet(font: infoFont, textColor: theme.list.freeTextColor) let privacyPolicyLinkAttributes = MarkdownAttributeSet(font: infoFont, textColor: theme.list.itemAccentColor, additionalAttributes: [NSAttributedString.Key.underlineStyle.rawValue: NSUnderlineStyle.single.rawValue as NSNumber, TelegramTextAttributes.URL: privacyPolicyUrl]) - text = parseMarkdownIntoAttributedString(strings.Passport_PrivacyPolicy(EnginePeer(peer).displayTitle(strings: strings, displayOrder: nameDisplayOrder), (EnginePeer(peer).addressName ?? "")).string.replacingOccurrences(of: "]", with: "]()"), attributes: MarkdownAttributes(body: privacyPolicyAttributes, bold: privacyPolicyAttributes, link: privacyPolicyLinkAttributes, linkAttribute: { _ in + text = parseMarkdownIntoAttributedString(strings.Passport_PrivacyPolicy(peer.displayTitle(strings: strings, displayOrder: nameDisplayOrder), (peer.addressName ?? "")).string.replacingOccurrences(of: "]", with: "]()"), attributes: MarkdownAttributes(body: privacyPolicyAttributes, bold: privacyPolicyAttributes, link: privacyPolicyLinkAttributes, linkAttribute: { _ in return nil }), textAlignment: .center) } else { - text = NSAttributedString(string: strings.Passport_AcceptHelp(EnginePeer(peer).displayTitle(strings: strings, displayOrder: nameDisplayOrder), (peer.addressName ?? "")).string, font: infoFont, textColor: theme.list.freeTextColor, paragraphAlignment: .left) + text = NSAttributedString(string: strings.Passport_AcceptHelp(peer.displayTitle(strings: strings, displayOrder: nameDisplayOrder), (peer.addressName ?? "")).string, font: infoFont, textColor: theme.list.freeTextColor, paragraphAlignment: .left) } self.textNode.attributedText = text diff --git a/submodules/PassportUI/Sources/SecureIdAuthHeaderNode.swift b/submodules/PassportUI/Sources/SecureIdAuthHeaderNode.swift index 0312848ef9..732cfa73af 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthHeaderNode.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthHeaderNode.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import AsyncDisplayKit import Display -import Postbox import TelegramCore import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift b/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift index 3412d5a1d4..b028a7f806 100644 --- a/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -17,12 +16,12 @@ import ItemListPeerItem private final class ChannelBlacklistControllerArguments { let context: AccountContext - let setPeerIdWithRevealedOptions: (PeerId?, PeerId?) -> Void + let setPeerIdWithRevealedOptions: (EnginePeer.Id?, EnginePeer.Id?) -> Void let addPeer: () -> Void - let removePeer: (PeerId) -> Void + let removePeer: (EnginePeer.Id) -> Void let openPeer: (RenderedChannelParticipant) -> Void - init(context: AccountContext, setPeerIdWithRevealedOptions: @escaping (PeerId?, PeerId?) -> Void, addPeer: @escaping () -> Void, removePeer: @escaping (PeerId) -> Void, openPeer: @escaping (RenderedChannelParticipant) -> Void) { + init(context: AccountContext, setPeerIdWithRevealedOptions: @escaping (EnginePeer.Id?, EnginePeer.Id?) -> Void, addPeer: @escaping () -> Void, removePeer: @escaping (EnginePeer.Id) -> Void, openPeer: @escaping (RenderedChannelParticipant) -> Void) { self.context = context self.addPeer = addPeer self.setPeerIdWithRevealedOptions = setPeerIdWithRevealedOptions @@ -38,7 +37,7 @@ private enum ChannelBlacklistSection: Int32 { private enum ChannelBlacklistEntryStableId: Hashable { case index(Int) - case peer(PeerId) + case peer(EnginePeer.Id) } private enum ChannelBlacklistEntry: ItemListNodeEntry { @@ -182,8 +181,8 @@ private enum ChannelBlacklistEntry: ItemListNodeEntry { private struct ChannelBlacklistControllerState: Equatable { let referenceTimestamp: Int32 let editing: Bool - let peerIdWithRevealedOptions: PeerId? - let removingPeerId: PeerId? + let peerIdWithRevealedOptions: EnginePeer.Id? + let removingPeerId: EnginePeer.Id? let searchingMembers: Bool init(referenceTimestamp: Int32) { @@ -194,7 +193,7 @@ private struct ChannelBlacklistControllerState: Equatable { self.searchingMembers = false } - init(referenceTimestamp: Int32, editing: Bool, peerIdWithRevealedOptions: PeerId?, removingPeerId: PeerId?, searchingMembers: Bool) { + init(referenceTimestamp: Int32, editing: Bool, peerIdWithRevealedOptions: EnginePeer.Id?, removingPeerId: EnginePeer.Id?, searchingMembers: Bool) { self.referenceTimestamp = referenceTimestamp self.editing = editing self.peerIdWithRevealedOptions = peerIdWithRevealedOptions @@ -231,19 +230,19 @@ private struct ChannelBlacklistControllerState: Equatable { } - func withUpdatedPeerIdWithRevealedOptions(_ peerIdWithRevealedOptions: PeerId?) -> ChannelBlacklistControllerState { + func withUpdatedPeerIdWithRevealedOptions(_ peerIdWithRevealedOptions: EnginePeer.Id?) -> ChannelBlacklistControllerState { return ChannelBlacklistControllerState(referenceTimestamp: self.referenceTimestamp, editing: self.editing, peerIdWithRevealedOptions: peerIdWithRevealedOptions, removingPeerId: self.removingPeerId, searchingMembers: self.searchingMembers) } - func withUpdatedRemovingPeerId(_ removingPeerId: PeerId?) -> ChannelBlacklistControllerState { + func withUpdatedRemovingPeerId(_ removingPeerId: EnginePeer.Id?) -> ChannelBlacklistControllerState { return ChannelBlacklistControllerState(referenceTimestamp: self.referenceTimestamp, editing: self.editing, peerIdWithRevealedOptions: self.peerIdWithRevealedOptions, removingPeerId: removingPeerId, searchingMembers: self.searchingMembers) } } -private func channelBlacklistControllerEntries(presentationData: PresentationData, view: PeerView, state: ChannelBlacklistControllerState, participants: [RenderedChannelParticipant]?) -> [ChannelBlacklistEntry] { +private func channelBlacklistControllerEntries(presentationData: PresentationData, peer: EnginePeer?, state: ChannelBlacklistControllerState, participants: [RenderedChannelParticipant]?) -> [ChannelBlacklistEntry] { var entries: [ChannelBlacklistEntry] = [] - if let channel = view.peers[view.peerId] as? TelegramChannel, let participants = participants { + if case let .channel(channel) = peer, let participants = participants { entries.append(.add(presentationData.theme, presentationData.strings.GroupRemoved_Remove)) let isGroup: Bool @@ -267,7 +266,7 @@ private func channelBlacklistControllerEntries(presentationData: PresentationDat return entries } -public func channelBlacklistController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId) -> ViewController { +public func channelBlacklistController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: EnginePeer.Id) -> ViewController { let statePromise = ValuePromise(ChannelBlacklistControllerState(referenceTimestamp: Int32(Date().timeIntervalSince1970)), ignoreRepeated: true) let stateValue = Atomic(value: ChannelBlacklistControllerState(referenceTimestamp: Int32(Date().timeIntervalSince1970))) let updateState: ((ChannelBlacklistControllerState) -> ChannelBlacklistControllerState) -> Void = { f in @@ -287,8 +286,8 @@ public func channelBlacklistController(context: AccountContext, updatedPresentat let removePeerDisposable = MetaDisposable() actionsDisposable.add(removePeerDisposable) - let peerView = Promise() - peerView.set(context.account.viewTracker.peerView(peerId)) + actionsDisposable.add(context.engine.peers.keepPeerUpdated(id: peerId, forceUpdate: false).start()) + let blacklistPromise = Promise<[RenderedChannelParticipant]?>(nil) let arguments = ChannelBlacklistControllerArguments(context: context, setPeerIdWithRevealedOptions: { peerId, fromPeerId in @@ -347,10 +346,11 @@ public func channelBlacklistController(context: AccountContext, updatedPresentat } })) }, openPeer: { participant in - let _ = (peerView.get() - |> take(1) - |> deliverOnMainQueue).start(next: { peerView in - guard let channel = peerView.peers[peerId] as? TelegramChannel else { + let _ = (context.engine.data.get( + TelegramEngine.EngineData.Item.Peer.Peer(id: peerId) + ) + |> deliverOnMainQueue).start(next: { peer in + guard case let .channel(channel) = peer else { return } let presentationData = context.sharedContext.currentPresentationData.with { $0 } @@ -435,10 +435,14 @@ public func channelBlacklistController(context: AccountContext, updatedPresentat let previousParticipantsValue = Atomic<[RenderedChannelParticipant]?>(value: nil) + let peer = context.engine.data.get( + TelegramEngine.EngineData.Item.Peer.Peer(id: peerId) + ) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData - let signal = combineLatest(queue: .mainQueue(), presentationData, statePromise.get(), peerView.get(), blacklistPromise.get()) + let signal = combineLatest(queue: .mainQueue(), presentationData, statePromise.get(), peer, blacklistPromise.get()) |> deliverOnMainQueue - |> map { presentationData, state, view, participants -> (ItemListControllerState, (ItemListNodeState, Any)) in + |> map { presentationData, state, peer, participants -> (ItemListControllerState, (ItemListNodeState, Any)) in var rightNavigationButton: ItemListNavigationButton? var secondaryRightNavigationButton: ItemListNavigationButton? if let participants = participants, !participants.isEmpty { @@ -498,7 +502,7 @@ public func channelBlacklistController(context: AccountContext, updatedPresentat } let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.GroupRemoved_Title), leftNavigationButton: nil, rightNavigationButton: rightNavigationButton, secondaryRightNavigationButton: secondaryRightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: true) - let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: channelBlacklistControllerEntries(presentationData: presentationData, view: view, state: state, participants: participants), style: .blocks, emptyStateItem: emptyStateItem, searchItem: searchItem, animateChanges: previous != nil && participants != nil && previous!.count >= participants!.count) + let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: channelBlacklistControllerEntries(presentationData: presentationData, peer: peer, state: state, participants: participants), style: .blocks, emptyStateItem: emptyStateItem, searchItem: searchItem, animateChanges: previous != nil && participants != nil && previous!.count >= participants!.count) return (controllerState, (listState, arguments)) } diff --git a/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift index 6dac2550dd..56fa4ceb78 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift @@ -341,7 +341,7 @@ public func proxySettingsController(accountManager: AccountManager ViewController { let presentationData = context.sharedContext.currentPresentationData.with { $0 } - return proxyServerSettingsController(context: context, presentationData: presentationData, updatedPresentationData: context.sharedContext.presentationData, accountManager: context.sharedContext.accountManager, postbox: context.account.postbox, network: context.account.network, currentSettings: currentSettings) + return proxyServerSettingsController(context: context, presentationData: presentationData, updatedPresentationData: context.sharedContext.presentationData, accountManager: context.sharedContext.accountManager, network: context.account.network, currentSettings: currentSettings) } -func proxyServerSettingsController(context: AccountContext? = nil, presentationData: PresentationData, updatedPresentationData: Signal, accountManager: AccountManager, postbox: Postbox, network: Network, currentSettings: ProxyServerSettings?) -> ViewController { +func proxyServerSettingsController(context: AccountContext? = nil, presentationData: PresentationData, updatedPresentationData: Signal, accountManager: AccountManager, network: Network, currentSettings: ProxyServerSettings?) -> ViewController { var currentMode: ProxyServerSettingsControllerMode = .socks5 var currentUsername: String? var currentPassword: String? diff --git a/submodules/SettingsUI/Sources/Data and Storage/ProxySettingsServerItem.swift b/submodules/SettingsUI/Sources/Data and Storage/ProxySettingsServerItem.swift index b39dd1856d..c062830a95 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/ProxySettingsServerItem.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/ProxySettingsServerItem.swift @@ -3,7 +3,6 @@ import UIKit import Display import AsyncDisplayKit import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import ItemListUI diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index c4e26a38ce..6b72bdd7c3 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -717,7 +717,7 @@ public final class VoiceChatControllerImpl: ViewController, VoiceChatController expandedText = .text(about, textIcon, .generic) } - return VoiceChatParticipantItem(presentationData: ItemListPresentationData(presentationData), dateTimeFormat: presentationData.dateTimeFormat, nameDisplayOrder: presentationData.nameDisplayOrder, context: context, peer: peer, text: text, expandedText: expandedText, icon: icon, getAudioLevel: { return interaction.getAudioLevel(peer.id) }, action: { node in + return VoiceChatParticipantItem(presentationData: ItemListPresentationData(presentationData), dateTimeFormat: presentationData.dateTimeFormat, nameDisplayOrder: presentationData.nameDisplayOrder, context: context, peer: EnginePeer(peer), text: text, expandedText: expandedText, icon: icon, getAudioLevel: { return interaction.getAudioLevel(peer.id) }, action: { node in if let node = node { interaction.peerContextAction(peerEntry, node, nil, false) } diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatParticipantItem.swift b/submodules/TelegramCallsUI/Sources/VoiceChatParticipantItem.swift index 8af9954d51..1ed491fde8 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatParticipantItem.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatParticipantItem.swift @@ -3,7 +3,6 @@ import UIKit import Display import AsyncDisplayKit import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -59,7 +58,7 @@ final class VoiceChatParticipantItem: ListViewItem { let dateTimeFormat: PresentationDateTimeFormat let nameDisplayOrder: PresentationPersonNameOrder let context: AccountContext - let peer: Peer + let peer: EnginePeer let text: ParticipantText let expandedText: ParticipantText? let icon: Icon @@ -71,7 +70,7 @@ final class VoiceChatParticipantItem: ListViewItem { public let selectable: Bool = true - public init(presentationData: ItemListPresentationData, dateTimeFormat: PresentationDateTimeFormat, nameDisplayOrder: PresentationPersonNameOrder, context: AccountContext, peer: Peer, text: ParticipantText, expandedText: ParticipantText?, icon: Icon, getAudioLevel: (() -> Signal)?, action: ((ASDisplayNode?) -> Void)?, contextAction: ((ASDisplayNode, ContextGesture?) -> Void)? = nil, getIsExpanded: @escaping () -> Bool, getUpdatingAvatar: @escaping () -> Signal<(TelegramMediaImageRepresentation, Float)?, NoError>) { + public init(presentationData: ItemListPresentationData, dateTimeFormat: PresentationDateTimeFormat, nameDisplayOrder: PresentationPersonNameOrder, context: AccountContext, peer: EnginePeer, text: ParticipantText, expandedText: ParticipantText?, icon: Icon, getAudioLevel: (() -> Signal)?, action: ((ASDisplayNode?) -> Void)?, contextAction: ((ASDisplayNode, ContextGesture?) -> Void)? = nil, getIsExpanded: @escaping () -> Bool, getUpdatingAvatar: @escaping () -> Signal<(TelegramMediaImageRepresentation, Float)?, NoError>) { self.presentationData = presentationData self.dateTimeFormat = dateTimeFormat self.nameDisplayOrder = nameDisplayOrder @@ -512,7 +511,7 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode { let avatarListNode = PeerInfoAvatarListContainerNode(context: item.context) avatarListWrapperNode.contentNode.clipsToBounds = true avatarListNode.backgroundColor = .clear - avatarListNode.peer = EnginePeer(item.peer) + avatarListNode.peer = item.peer avatarListNode.firstFullSizeOnly = true avatarListNode.offsetLocation = true avatarListNode.customCenterTapAction = { [weak self] in @@ -528,7 +527,7 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode { avatarListContainerNode.addSubnode(avatarListNode.controlsClippingOffsetNode) avatarListWrapperNode.contentNode.addSubnode(avatarListContainerNode) - avatarListNode.update(size: targetRect.size, peer: EnginePeer(item.peer), customNode: nil, additionalEntry: item.getUpdatingAvatar(), isExpanded: true, transition: .immediate) + avatarListNode.update(size: targetRect.size, peer: item.peer, customNode: nil, additionalEntry: item.getUpdatingAvatar(), isExpanded: true, transition: .immediate) strongSelf.offsetContainerNode.supernode?.addSubnode(avatarListWrapperNode) strongSelf.audioLevelView?.alpha = 0.0 @@ -785,7 +784,7 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode { let rightInset: CGFloat = params.rightInset var updatedTitle = false - if let user = item.peer as? TelegramUser { + if case let .user(user) = item.peer { if let firstName = user.firstName, let lastName = user.lastName, !firstName.isEmpty, !lastName.isEmpty { let string = NSMutableAttributedString() switch item.nameDisplayOrder { @@ -806,9 +805,9 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode { } else { titleAttributedString = NSAttributedString(string: item.presentationData.strings.User_DeletedAccount, font: titleFont, textColor: titleColor) } - } else if let group = item.peer as? TelegramGroup { + } else if case let .legacyGroup(group) = item.peer { titleAttributedString = NSAttributedString(string: group.title, font: titleFont, textColor: titleColor) - } else if let channel = item.peer as? TelegramChannel { + } else if case let .channel(channel) = item.peer { titleAttributedString = NSAttributedString(string: channel.title, font: titleFont, textColor: titleColor) } if let currentTitle = currentTitle, currentTitle != titleAttributedString?.string { @@ -840,7 +839,7 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode { credibilityIcon = .text(color: item.presentationData.theme.chat.message.incoming.scamColor, string: item.presentationData.strings.Message_ScamAccount.uppercased()) } else if item.peer.isFake { credibilityIcon = .text(color: item.presentationData.theme.chat.message.incoming.scamColor, string: item.presentationData.strings.Message_FakeAccount.uppercased()) - } else if let user = item.peer as? TelegramUser, let emojiStatus = user.emojiStatus, !premiumConfiguration.isPremiumDisabled { + } else if case let .user(user) = item.peer, let emojiStatus = user.emojiStatus, !premiumConfiguration.isPremiumDisabled { credibilityIcon = .animation(content: .customEmoji(fileId: emojiStatus.fileId), size: CGSize(width: 20.0, height: 20.0), placeholderColor: item.presentationData.theme.list.mediaPlaceholderColor, themeColor: item.presentationData.theme.list.itemAccentColor, loopMode: .count(2)) } else if item.peer.isVerified { credibilityIcon = .verified(fillColor: item.presentationData.theme.list.itemCheckColors.fillColor, foregroundColor: item.presentationData.theme.list.itemCheckColors.foregroundColor, sizeType: .compact) @@ -1133,7 +1132,7 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode { if item.peer.isDeleted { overrideImage = .deletedIcon } - strongSelf.avatarNode.setPeer(context: item.context, theme: item.presentationData.theme, peer: EnginePeer(item.peer), overrideImage: overrideImage, emptyColor: item.presentationData.theme.list.mediaPlaceholderColor, synchronousLoad: synchronousLoad, storeUnrounded: true) + strongSelf.avatarNode.setPeer(context: item.context, theme: item.presentationData.theme, peer: item.peer, overrideImage: overrideImage, emptyColor: item.presentationData.theme.list.mediaPlaceholderColor, synchronousLoad: synchronousLoad, storeUnrounded: true) strongSelf.highlightContainerNode.frame = CGRect(origin: CGPoint(x: params.leftInset, y: -UIScreenPixel), size: CGSize(width: params.width - params.leftInset - params.rightInset, height: layout.contentSize.height + UIScreenPixel + UIScreenPixel + 11.0)) diff --git a/submodules/TelegramCore/Sources/State/MessageMediaPreuploadManager.swift b/submodules/TelegramCore/Sources/State/MessageMediaPreuploadManager.swift index f5226403b6..21b60c4c44 100644 --- a/submodules/TelegramCore/Sources/State/MessageMediaPreuploadManager.swift +++ b/submodules/TelegramCore/Sources/State/MessageMediaPreuploadManager.swift @@ -32,11 +32,18 @@ private final class MessageMediaPreuploadManagerContext { assert(self.queue.isCurrent()) } - func add(network: Network, postbox: Postbox, id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal, onComplete: (()->Void)? = nil) { + func add(network: Network, postbox: Postbox, id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal, onComplete: (()->Void)? = nil) { let context = MessageMediaPreuploadManagerUploadContext() self.uploadContexts[id] = context let queue = self.queue - context.disposable.set(multipartUpload(network: network, postbox: postbox, source: .custom(source), encrypt: encrypt, tag: tag, hintFileSize: nil, hintFileIsLarge: false, forceNoBigParts: false).start(next: { [weak self] next in + context.disposable.set(multipartUpload(network: network, postbox: postbox, source: .custom(source |> map { data in + return MediaResourceData( + path: data.path, + offset: 0, + size: data.availableSize, + complete: data.isComplete + ) + }), encrypt: encrypt, tag: tag, hintFileSize: nil, hintFileIsLarge: false, forceNoBigParts: false).start(next: { [weak self] next in queue.async { if let strongSelf = self, let context = strongSelf.uploadContexts[id] { switch next { @@ -112,7 +119,7 @@ final class MessageMediaPreuploadManager { }) } - func add(network: Network, postbox: Postbox, id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal, onComplete:(()->Void)? = nil) { + func add(network: Network, postbox: Postbox, id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal, onComplete:(()->Void)? = nil) { self.impl.with { context in context.add(network: network, postbox: postbox, id: id, encrypt: encrypt, tag: tag, source: source, onComplete: onComplete) } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Data/OrderedListsData.swift b/submodules/TelegramCore/Sources/TelegramEngine/Data/OrderedListsData.swift index 6701b555dd..84ee94709c 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Data/OrderedListsData.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Data/OrderedListsData.swift @@ -2,6 +2,48 @@ import SwiftSignalKit import Postbox public extension TelegramEngine.EngineData.Item { + enum Collections { + public struct FeaturedStickerPacks: TelegramEngineDataItem, PostboxViewDataItem { + public typealias Result = [FeaturedStickerPackItem] + + public init() { + } + + var key: PostboxViewKey { + return .orderedItemList(id: Namespaces.OrderedItemList.CloudFeaturedStickerPacks) + } + + func extract(view: PostboxView) -> Result { + guard let view = view as? OrderedItemListView else { + preconditionFailure() + } + return view.items.compactMap { item in + return item.contents.get(FeaturedStickerPackItem.self) + } + } + } + + public struct FeaturedEmojiPacks: TelegramEngineDataItem, PostboxViewDataItem { + public typealias Result = [FeaturedStickerPackItem] + + public init() { + } + + var key: PostboxViewKey { + return .orderedItemList(id: Namespaces.OrderedItemList.CloudFeaturedEmojiPacks) + } + + func extract(view: PostboxView) -> Result { + guard let view = view as? OrderedItemListView else { + preconditionFailure() + } + return view.items.compactMap { item in + return item.contents.get(FeaturedStickerPackItem.self) + } + } + } + } + enum OrderedLists { public struct ListItems: TelegramEngineDataItem, PostboxViewDataItem { public typealias Result = [OrderedItemListEntry] diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Resources/TelegramEngineResources.swift b/submodules/TelegramCore/Sources/TelegramEngine/Resources/TelegramEngineResources.swift index 853acdacf7..b47f405aa9 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Resources/TelegramEngineResources.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Resources/TelegramEngineResources.swift @@ -231,7 +231,7 @@ public extension TelegramEngine { self.account = account } - public func preUpload(id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal, onComplete: (()->Void)? = nil) { + public func preUpload(id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal, onComplete: (()->Void)? = nil) { return self.account.messageMediaPreuploadManager.add(network: self.account.network, postbox: self.account.postbox, id: id, encrypt: encrypt, tag: tag, source: source, onComplete: onComplete) } diff --git a/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift b/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift index d9178200be..048308dd71 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift @@ -1,7 +1,6 @@ import Foundation import UIKit import Display -import Postbox import TelegramCore import TelegramUIPreferences import AppBundle diff --git a/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusPreviewScreen.swift b/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusPreviewScreen.swift index b8505beb86..c9d0fcd28f 100644 --- a/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusPreviewScreen.swift +++ b/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusPreviewScreen.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import ComponentFlow import TelegramPresentationData diff --git a/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift b/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift index 68f6e7504c..94f96cd074 100644 --- a/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift +++ b/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift @@ -11,7 +11,6 @@ import ComponentDisplayAdapters import TelegramPresentationData import AccountContext import PagerComponent -import Postbox import TelegramCore import Lottie import EmojiTextAttachmentView @@ -19,6 +18,7 @@ import TextFormat import AppBundle import GZip import EmojiStatusComponent +import Postbox private func randomGenericReactionEffect(context: AccountContext) -> Signal { return context.engine.stickers.loadedStickerPack(reference: .emojiGenericAnimations, forceActualized: false) @@ -344,16 +344,16 @@ public final class EmojiStatusSelectionController: ViewController { self.layer.addSublayer(self.cloudLayer0) self.layer.addSublayer(self.cloudLayer1) - let viewKey = PostboxViewKey.orderedItemList(id: Namespaces.OrderedItemList.CloudFeaturedEmojiPacks) - self.stableEmptyResultEmojiDisposable.set((self.context.account.postbox.combinedView(keys: [viewKey]) - |> take(1) - |> deliverOnMainQueue).start(next: { [weak self] views in - guard let strongSelf = self, let view = views.views[viewKey] as? OrderedItemListView else { + self.stableEmptyResultEmojiDisposable.set((self.context.engine.data.get( + TelegramEngine.EngineData.Item.Collections.FeaturedEmojiPacks() + ) + |> deliverOnMainQueue).start(next: { [weak self] featuredEmojiPacks in + guard let strongSelf = self else { return } var filteredFiles: [TelegramMediaFile] = [] let filterList: [String] = ["😖", "😫", "🫠", "😨", "❓"] - for featuredEmojiPack in view.items.lazy.map({ $0.contents.get(FeaturedStickerPackItem.self)! }) { + for featuredEmojiPack in featuredEmojiPacks { for item in featuredEmojiPack.topItems { for attribute in item.file.attributes { switch attribute { @@ -423,14 +423,14 @@ public final class EmojiStatusSelectionController: ViewController { return } - let viewKey = PostboxViewKey.orderedItemList(id: Namespaces.OrderedItemList.CloudFeaturedEmojiPacks) - let _ = (strongSelf.context.account.postbox.combinedView(keys: [viewKey]) - |> take(1) - |> deliverOnMainQueue).start(next: { views in - guard let strongSelf = self, let view = views.views[viewKey] as? OrderedItemListView else { + let _ = (strongSelf.context.engine.data.get( + TelegramEngine.EngineData.Item.Collections.FeaturedEmojiPacks() + ) + |> deliverOnMainQueue).start(next: { featuredEmojiPacks in + guard let strongSelf = self else { return } - for featuredEmojiPack in view.items.lazy.map({ $0.contents.get(FeaturedStickerPackItem.self)! }) { + for featuredEmojiPack in featuredEmojiPacks { if featuredEmojiPack.info.id == collectionId { if let strongSelf = self { strongSelf.scheduledEmojiContentAnimationHint = EmojiPagerContentComponent.ContentAnimation(type: .groupInstalled(id: collectionId, scrollToGroup: true)) @@ -592,7 +592,7 @@ public final class EmojiStatusSelectionController: ViewController { |> mapToSignal { files, isFinalResult -> Signal<(items: [EmojiPagerContentComponent.ItemGroup], isFinalResult: Bool), NoError> in var items: [EmojiPagerContentComponent.Item] = [] - var existingIds = Set() + var existingIds = Set() for itemFile in files { if existingIds.contains(itemFile.fileId) { continue diff --git a/submodules/TelegramUI/Components/EmojiSuggestionsComponent/Sources/EmojiSuggestionsComponent.swift b/submodules/TelegramUI/Components/EmojiSuggestionsComponent/Sources/EmojiSuggestionsComponent.swift index 4d00e0b9d7..535b79b95d 100644 --- a/submodules/TelegramUI/Components/EmojiSuggestionsComponent/Sources/EmojiSuggestionsComponent.swift +++ b/submodules/TelegramUI/Components/EmojiSuggestionsComponent/Sources/EmojiSuggestionsComponent.swift @@ -7,7 +7,6 @@ import MultiAnimationRenderer import ComponentFlow import AccountContext import TelegramCore -import Postbox import TelegramPresentationData import EmojiTextAttachmentView import TextFormat @@ -52,7 +51,7 @@ public final class EmojiSuggestionsComponent: Component { let normalizedQuery = query.basicEmoji.0 - var existingIds = Set() + var existingIds = Set() for entry in view.entries { guard let item = entry.item as? StickerPackItem else { continue @@ -179,7 +178,7 @@ public final class EmojiSuggestionsComponent: Component { private var itemLayout: ItemLayout? private var ignoreScrolling: Bool = false - private var visibleLayers: [MediaId: InlineStickerItemLayer] = [:] + private var visibleLayers: [EngineMedia.Id: InlineStickerItemLayer] = [:] override init(frame: CGRect) { self.blurView = BlurredBackgroundView(color: .clear, enableBlur: true) @@ -296,7 +295,7 @@ public final class EmojiSuggestionsComponent: Component { let visibleBounds = self.scrollView.bounds - var visibleIds = Set() + var visibleIds = Set() for i in 0 ..< component.files.count { let itemFrame = itemLayout.frame(at: i) if visibleBounds.intersects(itemFrame) { @@ -330,7 +329,7 @@ public final class EmojiSuggestionsComponent: Component { } } - var removedIds: [MediaId] = [] + var removedIds: [EngineMedia.Id] = [] for (id, itemLayer) in self.visibleLayers { if !visibleIds.contains(id) { itemLayer.removeFromSuperlayer()