mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-05 19:28:46 +02:00
Wave 11: ActionSheetPeerItem de-Postboxed. Revisits wave-1 abandonment. `postbox: Postbox, network: Network` init params collapse to `stateManager: AccountStateManager`; avatar setPeer call routes via `item.stateManager.postbox` / `.network`. Module never names Postbox. Sole caller (ShareController.swift:1146) migrated in place. Wave 12: HorizontalPeerItem de-Postboxed (same pattern). Ripples the collapse up into ChatListSearchRecentPeersNode's public init (`postbox:/network:` -> `stateManager:`). That module still imports Postbox for PostboxViewKey/UnreadMessageCountsView internals but its public surface simplifies. 3 external caller sites migrated. Wave 13: AttachmentTextInputPanelNode minor cleanup. Module was already Postbox-free at source level (wave 6) but carried a dead BUILD dep and had 2 raw `peerId?.namespace == Namespaces.Peer.SecretChat` checks. Both now use existing `PeerId.isSecretChat` extension in TelegramCore. Wave 14: BUILD-dep sweep mirroring wave 6's source sweep. 98 modules had `//submodules/Postbox:Postbox` (or `//submodules/Postbox`) BUILD deps despite no source file importing Postbox since wave 6. Single iteration, zero restores -- Bazel Swift requires source-level `import` for symbol resolution, so redundant BUILD deps are pure metadata. Net: 110 files, +116/-149. Build verified green (debug_sim_arm64). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
186 lines
8.4 KiB
Swift
186 lines
8.4 KiB
Swift
import Foundation
|
|
import UIKit
|
|
import AsyncDisplayKit
|
|
import Display
|
|
import SwiftSignalKit
|
|
import TelegramCore
|
|
import TelegramPresentationData
|
|
import ChatListSearchRecentPeersNode
|
|
import ContextUI
|
|
import AccountContext
|
|
|
|
class ChatListRecentPeersListItem: ListViewItem {
|
|
let theme: PresentationTheme
|
|
let strings: PresentationStrings
|
|
let context: AccountContext
|
|
let peers: [EnginePeer]
|
|
let peerSelected: (EnginePeer) -> Void
|
|
let peerContextAction: (EnginePeer, ASDisplayNode, ContextGesture?, CGPoint?) -> Void
|
|
|
|
let header: ListViewItemHeader?
|
|
|
|
init(theme: PresentationTheme, strings: PresentationStrings, context: AccountContext, peers: [EnginePeer], peerSelected: @escaping (EnginePeer) -> Void, peerContextAction: @escaping (EnginePeer, ASDisplayNode, ContextGesture?, CGPoint?) -> Void) {
|
|
self.theme = theme
|
|
self.strings = strings
|
|
self.context = context
|
|
self.peers = peers
|
|
self.peerSelected = peerSelected
|
|
self.peerContextAction = peerContextAction
|
|
self.header = nil
|
|
}
|
|
|
|
func nodeConfiguredForParams(async: @escaping (@escaping () -> Void) -> Void, params: ListViewItemLayoutParams, synchronousLoads: Bool, previousItem: ListViewItem?, nextItem: ListViewItem?, completion: @escaping (ListViewItemNode, @escaping () -> (Signal<Void, NoError>?, (ListViewItemApply) -> Void)) -> Void) {
|
|
async {
|
|
let node = ChatListRecentPeersListItemNode()
|
|
let makeLayout = node.asyncLayout()
|
|
let (nodeLayout, nodeApply) = makeLayout(self, params, nextItem != nil)
|
|
node.contentSize = nodeLayout.contentSize
|
|
node.insets = nodeLayout.insets
|
|
|
|
completion(node, {
|
|
return (nil, { _ in nodeApply(synchronousLoads) })
|
|
})
|
|
}
|
|
}
|
|
|
|
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? ChatListRecentPeersListItemNode {
|
|
let layout = nodeValue.asyncLayout()
|
|
async {
|
|
let (nodeLayout, apply) = layout(self, params, nextItem != nil)
|
|
Queue.mainQueue().async {
|
|
completion(nodeLayout, { _ in
|
|
apply(false)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class ChatListRecentPeersListItemNode: ListViewItemNode {
|
|
private let backgroundNode: ASDisplayNode
|
|
private let separatorNode: ASDisplayNode
|
|
private var peersNode: ChatListSearchRecentPeersNode?
|
|
|
|
private var item: ChatListRecentPeersListItem?
|
|
|
|
private let ready = Promise<Bool>()
|
|
public var isReady: Signal<Bool, NoError> {
|
|
return self.ready.get()
|
|
}
|
|
|
|
required init() {
|
|
self.backgroundNode = ASDisplayNode()
|
|
self.backgroundNode.isLayerBacked = true
|
|
|
|
self.separatorNode = ASDisplayNode()
|
|
self.separatorNode.isLayerBacked = true
|
|
|
|
super.init(layerBacked: false)
|
|
|
|
self.addSubnode(self.backgroundNode)
|
|
self.addSubnode(self.separatorNode)
|
|
}
|
|
|
|
override func layoutForParams(_ params: ListViewItemLayoutParams, item: ListViewItem, previousItem: ListViewItem?, nextItem: ListViewItem?) {
|
|
if let item = self.item {
|
|
let makeLayout = self.asyncLayout()
|
|
let (nodeLayout, nodeApply) = makeLayout(item, params, nextItem == nil)
|
|
self.contentSize = nodeLayout.contentSize
|
|
self.insets = nodeLayout.insets
|
|
let _ = nodeApply(false)
|
|
}
|
|
}
|
|
|
|
func asyncLayout() -> (_ item: ChatListRecentPeersListItem, _ params: ListViewItemLayoutParams, _ last: Bool) -> (ListViewItemNodeLayout, (Bool) -> Void) {
|
|
let currentItem = self.item
|
|
|
|
return { [weak self] item, params, last in
|
|
let nodeLayout = ListViewItemNodeLayout(contentSize: CGSize(width: params.width, height: 96.0), insets: UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0))
|
|
|
|
var updatedTheme: PresentationTheme?
|
|
if currentItem?.theme !== item.theme {
|
|
updatedTheme = item.theme
|
|
}
|
|
|
|
return (nodeLayout, { [weak self] synchronousLoads in
|
|
if let strongSelf = self {
|
|
strongSelf.item = item
|
|
|
|
if let _ = updatedTheme {
|
|
strongSelf.separatorNode.backgroundColor = item.theme.list.itemPlainSeparatorColor
|
|
strongSelf.backgroundNode.backgroundColor = item.theme.list.plainBackgroundColor
|
|
}
|
|
|
|
let peersNode: ChatListSearchRecentPeersNode
|
|
if let currentPeersNode = strongSelf.peersNode {
|
|
peersNode = currentPeersNode
|
|
peersNode.updateThemeAndStrings(theme: item.theme, strings: item.strings)
|
|
} else {
|
|
peersNode = ChatListSearchRecentPeersNode(
|
|
accountPeerId: item.context.account.peerId,
|
|
stateManager: item.context.account.stateManager,
|
|
energyUsageSettings: item.context.sharedContext.energyUsageSettings,
|
|
contentSettings: item.context.currentContentSettings.with { $0 },
|
|
animationCache: item.context.animationCache,
|
|
animationRenderer: item.context.animationRenderer,
|
|
resolveInlineStickers: item.context.engine.stickers.resolveInlineStickers,
|
|
theme: item.theme,
|
|
mode: .list(compact: false),
|
|
strings: item.strings,
|
|
peerSelected: { peer in
|
|
self?.item?.peerSelected(peer)
|
|
},
|
|
peerContextAction: { peer, node, gesture, location in
|
|
self?.item?.peerContextAction(peer, node, gesture, location)
|
|
},
|
|
isPeerSelected: { _ in
|
|
return false
|
|
}
|
|
)
|
|
strongSelf.ready.set(peersNode.isReady)
|
|
strongSelf.peersNode = peersNode
|
|
strongSelf.addSubnode(peersNode)
|
|
}
|
|
|
|
peersNode.frame = CGRect(origin: CGPoint(), size: nodeLayout.contentSize)
|
|
peersNode.updateLayout(size: nodeLayout.contentSize, leftInset: params.leftInset, rightInset: params.rightInset)
|
|
|
|
let separatorHeight = UIScreenPixel
|
|
strongSelf.backgroundNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: nodeLayout.contentSize.width, height: nodeLayout.contentSize.height))
|
|
strongSelf.separatorNode.frame = CGRect(origin: CGPoint(x: 0.0, y: nodeLayout.contentSize.height - separatorHeight), size: CGSize(width: nodeLayout.size.width, height: separatorHeight))
|
|
strongSelf.separatorNode.isHidden = true
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
override func animateInsertion(_ currentTimestamp: Double, duration: Double, options: ListViewItemAnimationOptions) {
|
|
self.layer.animateAlpha(from: 0.0, to: 1.0, duration: duration * 0.5)
|
|
}
|
|
|
|
override func animateRemoved(_ currentTimestamp: Double, duration: Double) {
|
|
self.layer.animateAlpha(from: 1.0, to: 0.0, duration: duration * 0.5, removeOnCompletion: false)
|
|
}
|
|
|
|
override public func headers() -> [ListViewItemHeader]? {
|
|
if let item = self.item {
|
|
return item.header.flatMap { [$0] }
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func viewAndPeerAtPoint(_ point: CGPoint) -> (UIView, EnginePeer.Id)? {
|
|
if let peersNode = self.peersNode {
|
|
let adjustedLocation = self.convert(point, to: peersNode)
|
|
if let result = peersNode.viewAndPeerAtPoint(adjustedLocation) {
|
|
return result
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|