diff --git a/submodules/ChatListUI/Sources/ChatContextMenus.swift b/submodules/ChatListUI/Sources/ChatContextMenus.swift index 5af6a04022..6459d60996 100644 --- a/submodules/ChatListUI/Sources/ChatContextMenus.swift +++ b/submodules/ChatListUI/Sources/ChatContextMenus.swift @@ -733,7 +733,7 @@ func chatForumTopicMenuItems(context: AccountContext, peerId: PeerId, threadId: let canRemove = false - let exceptionController = notificationPeerExceptionController(context: context, updatedPresentationData: nil, peer: channel, threadId: threadId, canRemove: canRemove, defaultSound: defaultSound, edit: true, updatePeerSound: { peerId, sound in + let exceptionController = notificationPeerExceptionController(context: context, updatedPresentationData: nil, peer: .channel(channel), threadId: threadId, canRemove: canRemove, defaultSound: defaultSound, edit: true, updatePeerSound: { peerId, sound in let _ = (updatePeerSound(peerId, sound) |> deliverOnMainQueue).start(next: { _ in }) diff --git a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift index 05fe16fdbb..4a9ea3b17d 100644 --- a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift @@ -909,7 +909,7 @@ public func channelAdminController(context: AccountContext, updatedPresentationD } transferOwnershipDisposable.set((context.engine.peers.checkOwnershipTranfserAvailability(memberId: adminId) |> deliverOnMainQueue).start(error: { error in - let controller = channelOwnershipTransferController(context: context, updatedPresentationData: updatedPresentationData, peer: peer._asPeer(), member: member, initialError: error, present: { c, a in + let controller = channelOwnershipTransferController(context: context, updatedPresentationData: updatedPresentationData, peer: peer, member: member, initialError: error, present: { c, a in presentControllerImpl?(c, a) }, completion: { upgradedPeerId in if let upgradedPeerId = upgradedPeerId { diff --git a/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift b/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift index 066a127e4c..50dc14e4e8 100644 --- a/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -20,13 +19,13 @@ private final class ChannelAdminsControllerArguments { let context: AccountContext let openRecentActions: () -> Void - let setPeerIdWithRevealedOptions: (PeerId?, PeerId?) -> Void - let removeAdmin: (PeerId) -> Void + let setPeerIdWithRevealedOptions: (EnginePeer.Id?, EnginePeer.Id?) -> Void + let removeAdmin: (EnginePeer.Id) -> Void let addAdmin: () -> Void let openAdmin: (ChannelParticipant) -> Void let updateAntiSpamEnabled: (Bool) -> Void - init(context: AccountContext, openRecentActions: @escaping () -> Void, setPeerIdWithRevealedOptions: @escaping (PeerId?, PeerId?) -> Void, removeAdmin: @escaping (PeerId) -> Void, addAdmin: @escaping () -> Void, openAdmin: @escaping (ChannelParticipant) -> Void, updateAntiSpamEnabled: @escaping (Bool) -> Void) { + init(context: AccountContext, openRecentActions: @escaping () -> Void, setPeerIdWithRevealedOptions: @escaping (EnginePeer.Id?, EnginePeer.Id?) -> Void, removeAdmin: @escaping (EnginePeer.Id) -> Void, addAdmin: @escaping () -> Void, openAdmin: @escaping (ChannelParticipant) -> Void, updateAntiSpamEnabled: @escaping (Bool) -> Void) { self.context = context self.openRecentActions = openRecentActions self.setPeerIdWithRevealedOptions = setPeerIdWithRevealedOptions @@ -44,7 +43,7 @@ private enum ChannelAdminsSection: Int32 { private enum ChannelAdminsEntryStableId: Hashable { case index(Int32) - case peer(PeerId) + case peer(EnginePeer.Id) } private enum ChannelAdminsEntry: ItemListNodeEntry { @@ -266,9 +265,9 @@ private enum ChannelAdminsEntry: ItemListNodeEntry { private struct ChannelAdminsControllerState: Equatable { let editing: Bool - let peerIdWithRevealedOptions: PeerId? - let removingPeerId: PeerId? - let removedPeerIds: Set + let peerIdWithRevealedOptions: EnginePeer.Id? + let removingPeerId: EnginePeer.Id? + let removedPeerIds: Set let temporaryAdmins: [RenderedChannelParticipant] let searchingMembers: Bool @@ -281,7 +280,7 @@ private struct ChannelAdminsControllerState: Equatable { self.searchingMembers = false } - init(editing: Bool, peerIdWithRevealedOptions: PeerId?, removingPeerId: PeerId?, removedPeerIds: Set, temporaryAdmins: [RenderedChannelParticipant], searchingMembers: Bool) { + init(editing: Bool, peerIdWithRevealedOptions: EnginePeer.Id?, removingPeerId: EnginePeer.Id?, removedPeerIds: Set, temporaryAdmins: [RenderedChannelParticipant], searchingMembers: Bool) { self.editing = editing self.peerIdWithRevealedOptions = peerIdWithRevealedOptions self.removingPeerId = removingPeerId @@ -321,15 +320,15 @@ private struct ChannelAdminsControllerState: Equatable { return ChannelAdminsControllerState(editing: editing, peerIdWithRevealedOptions: self.peerIdWithRevealedOptions, removingPeerId: self.removingPeerId, removedPeerIds: self.removedPeerIds, temporaryAdmins: self.temporaryAdmins, searchingMembers: self.searchingMembers) } - func withUpdatedPeerIdWithRevealedOptions(_ peerIdWithRevealedOptions: PeerId?) -> ChannelAdminsControllerState { + func withUpdatedPeerIdWithRevealedOptions(_ peerIdWithRevealedOptions: EnginePeer.Id?) -> ChannelAdminsControllerState { return ChannelAdminsControllerState(editing: self.editing, peerIdWithRevealedOptions: peerIdWithRevealedOptions, removingPeerId: self.removingPeerId, removedPeerIds: self.removedPeerIds, temporaryAdmins: self.temporaryAdmins, searchingMembers: self.searchingMembers) } - func withUpdatedRemovingPeerId(_ removingPeerId: PeerId?) -> ChannelAdminsControllerState { + func withUpdatedRemovingPeerId(_ removingPeerId: EnginePeer.Id?) -> ChannelAdminsControllerState { return ChannelAdminsControllerState(editing: self.editing, peerIdWithRevealedOptions: self.peerIdWithRevealedOptions, removingPeerId: removingPeerId, removedPeerIds: self.removedPeerIds, temporaryAdmins: self.temporaryAdmins, searchingMembers: self.searchingMembers) } - func withUpdatedRemovedPeerIds(_ removedPeerIds: Set) -> ChannelAdminsControllerState { + func withUpdatedRemovedPeerIds(_ removedPeerIds: Set) -> ChannelAdminsControllerState { return ChannelAdminsControllerState(editing: self.editing, peerIdWithRevealedOptions: self.peerIdWithRevealedOptions, removingPeerId: self.removingPeerId, removedPeerIds: removedPeerIds, temporaryAdmins: self.temporaryAdmins, searchingMembers: self.searchingMembers) } @@ -338,13 +337,13 @@ private struct ChannelAdminsControllerState: Equatable { } } -private func channelAdminsControllerEntries(presentationData: PresentationData, accountPeerId: PeerId, view: PeerView, state: ChannelAdminsControllerState, participants: [RenderedChannelParticipant]?, antiSpamAvailable: Bool, antiSpamEnabled: Bool) -> [ChannelAdminsEntry] { +private func channelAdminsControllerEntries(presentationData: PresentationData, accountPeerId: EnginePeer.Id, peer: EnginePeer?, state: ChannelAdminsControllerState, participants: [RenderedChannelParticipant]?, antiSpamAvailable: Bool, antiSpamEnabled: Bool) -> [ChannelAdminsEntry] { if participants == nil || participants?.count == nil { return [] } var entries: [ChannelAdminsEntry] = [] - if let peer = view.peers[view.peerId] as? TelegramChannel { + if case let .channel(peer) = peer { var isGroup = false if case .group = peer.info { isGroup = true @@ -364,7 +363,7 @@ private func channelAdminsControllerEntries(presentationData: PresentationData, } var combinedParticipants: [RenderedChannelParticipant] = participants - var existingParticipantIds = Set() + var existingParticipantIds = Set() for participant in participants { existingParticipantIds.insert(participant.peer.id) } @@ -431,7 +430,7 @@ private func channelAdminsControllerEntries(presentationData: PresentationData, entries.append(.adminsInfo(presentationData.theme, info)) } } - } else if let peer = view.peers[view.peerId] as? TelegramGroup { + } else if case let .legacyGroup(peer) = peer { let isGroup = true //entries.append(.recentActions(presentationData.theme, presentationData.strings.Group_Info_AdminLog)) @@ -443,7 +442,7 @@ private func channelAdminsControllerEntries(presentationData: PresentationData, } var combinedParticipants: [RenderedChannelParticipant] = participants - var existingParticipantIds = Set() + var existingParticipantIds = Set() for participant in participants { existingParticipantIds.insert(participant.peer.id) } @@ -512,7 +511,7 @@ private func channelAdminsControllerEntries(presentationData: PresentationData, return entries } -public func channelAdminsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId initialPeerId: PeerId, loadCompleted: @escaping () -> Void = {}) -> ViewController { +public func channelAdminsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId initialPeerId: EnginePeer.Id, loadCompleted: @escaping () -> Void = {}) -> ViewController { let statePromise = ValuePromise(ChannelAdminsControllerState(), ignoreRepeated: true) let stateValue = Atomic(value: ChannelAdminsControllerState()) let updateState: ((ChannelAdminsControllerState) -> ChannelAdminsControllerState) -> Void = { f in @@ -559,16 +558,16 @@ public func channelAdminsController(context: AccountContext, updatedPresentation ) } - var upgradedToSupergroupImpl: ((PeerId, @escaping () -> Void) -> Void)? + var upgradedToSupergroupImpl: ((EnginePeer.Id, @escaping () -> Void) -> Void)? - let currentPeerId = ValuePromise(initialPeerId) + let currentPeerId = ValuePromise(initialPeerId) - let upgradedToSupergroup: (PeerId, @escaping () -> Void) -> Void = { upgradedPeerId, f in + let upgradedToSupergroup: (EnginePeer.Id, @escaping () -> Void) -> Void = { upgradedPeerId, f in currentPeerId.set(upgradedPeerId) upgradedToSupergroupImpl?(upgradedPeerId, f) } - let transferedOwnership: (PeerId) -> Void = { memberId in + let transferedOwnership: (EnginePeer.Id) -> Void = { memberId in let presentationData = context.sharedContext.currentPresentationData.with { $0 } let _ = (currentPeerId.get() |> take(1) @@ -586,21 +585,57 @@ public func channelAdminsController(context: AccountContext, updatedPresentation }) } - let peerView = Promise() + actionsDisposable.add((currentPeerId.get() + |> mapToSignal { peerId in + return context.engine.peers.keepPeerUpdated(id: peerId, forceUpdate: false) + }).start()) + + struct PeerData: Equatable { + var peerId: EnginePeer.Id + var peer: EnginePeer? + var participantCount: Int? + + init( + peerId: EnginePeer.Id, + peer: EnginePeer?, + participantCount: Int? + ) { + self.peerId = peerId + self.peer = peer + self.participantCount = participantCount + } + } + + let peerView = Promise() peerView.set(currentPeerId.get() |> mapToSignal { peerId in - return context.account.viewTracker.peerView(peerId) + return context.engine.data.subscribe( + TelegramEngine.EngineData.Item.Peer.Peer(id: peerId), + TelegramEngine.EngineData.Item.Peer.ParticipantCount(id: peerId) + ) + |> map { peer, participantCount -> PeerData in + return PeerData( + peerId: peerId, + peer: peer, + participantCount: participantCount + ) + } }) let arguments = ChannelAdminsControllerArguments(context: context, openRecentActions: { let _ = (currentPeerId.get() |> take(1) |> deliverOnMainQueue).start(next: { peerId in - let _ = (context.account.postbox.loadedPeerWithId(peerId) + let _ = (context.engine.data.get( + TelegramEngine.EngineData.Item.Peer.Peer(id: peerId) + ) |> deliverOnMainQueue).start(next: { peer in - if peer is TelegramGroup { + guard let peer else { + return + } + if case .legacyGroup = peer { } else { - pushControllerImpl?(context.sharedContext.makeChatRecentActionsController(context: context, peer: peer, adminPeerId: nil)) + pushControllerImpl?(context.sharedContext.makeChatRecentActionsController(context: context, peer: peer._asPeer(), adminPeerId: nil)) } }) }) @@ -660,7 +695,7 @@ public func channelAdminsController(context: AccountContext, updatedPresentation if banInfo.restrictedBy != context.account.peerId { canUnban = true } - if let channel = peerView.peers[peerId] as? TelegramChannel { + if case let .channel(channel) = peerView.peer { if channel.hasPermission(.banMembers) { canUnban = true } @@ -723,42 +758,68 @@ public func channelAdminsController(context: AccountContext, updatedPresentation membersDisposableValue.set(membersAndLoadMoreControl.0) } else { loadCompleted() - let membersDisposable = (peerView.get() - |> map { peerView -> [RenderedChannelParticipant]? in - guard let cachedData = peerView.cachedData as? CachedGroupData, let participants = cachedData.participants else { - return nil + let membersDisposable = (currentPeerId.get() + |> mapToSignal { peerId -> Signal<[RenderedChannelParticipant]?, NoError> in + return context.engine.data.subscribe( + TelegramEngine.EngineData.Item.Peer.LegacyGroupParticipants(id: peerId) + ) + |> mapToSignal { participants -> Signal<[(EngineLegacyGroupParticipant, EnginePeer?)]?, NoError> in + guard case let .known(participants) = participants else { + return .single(nil) + } + + return context.engine.data.subscribe( + EngineDataMap(participants.map { TelegramEngine.EngineData.Item.Peer.Peer(id: $0.peerId) }) + ) + |> map { peers -> [(EngineLegacyGroupParticipant, EnginePeer?)]? in + var result: [(EngineLegacyGroupParticipant, EnginePeer?)] = [] + for participant in participants { + var peer: EnginePeer? + if let peerValue = peers[participant.peerId] { + peer = peerValue + } + result.append((participant, peer)) + } + return result + } } - var result: [RenderedChannelParticipant] = [] - var creatorPeer: Peer? - for participant in participants.participants { - if let peer = peerView.peers[participant.peerId] { - switch participant { + |> map { participants -> [RenderedChannelParticipant]? in + guard let participants else { + return nil + } + + var result: [RenderedChannelParticipant] = [] + var creatorPeer: EnginePeer? + for (participant, peer) in participants { + if let peer { + switch participant { case .creator: creatorPeer = peer default: break + } } } - } - guard let creator = creatorPeer else { - return nil - } - for participant in participants.participants { - if let peer = peerView.peers[participant.peerId] { - switch participant { + guard let creator = creatorPeer else { + return nil + } + for (participant, peer) in participants { + if let peer { + switch participant { case .creator: - result.append(RenderedChannelParticipant(participant: .creator(id: peer.id, adminInfo: nil, rank: nil), peer: peer)) + result.append(RenderedChannelParticipant(participant: .creator(id: peer.id, adminInfo: nil, rank: nil), peer: peer._asPeer())) case .admin: - var peers: [PeerId: Peer] = [:] + var peers: [EnginePeer.Id: EnginePeer] = [:] peers[creator.id] = creator peers[peer.id] = peer - result.append(RenderedChannelParticipant(participant: .member(id: peer.id, invitedAt: 0, adminInfo: ChannelParticipantAdminInfo(rights: TelegramChatAdminRights(rights: .internal_groupSpecific), promotedBy: creator.id, canBeEditedByAccountPeer: creator.id == context.account.peerId), banInfo: nil, rank: nil), peer: peer, peers: peers)) + result.append(RenderedChannelParticipant(participant: .member(id: peer.id, invitedAt: 0, adminInfo: ChannelParticipantAdminInfo(rights: TelegramChatAdminRights(rights: .internal_groupSpecific), promotedBy: creator.id, canBeEditedByAccountPeer: creator.id == context.account.peerId), banInfo: nil, rank: nil), peer: peer._asPeer(), peers: peers.mapValues({ $0._asPeer() }))) case .member: break + } } } + return result } - return result }).start(next: { members in adminsPromise.set(.single(members)) }) @@ -787,7 +848,7 @@ public func channelAdminsController(context: AccountContext, updatedPresentation let peerId = view.peerId var antiSpamAvailable = false - if let cachedData = view.cachedData as? CachedChannelData, let memberCount = cachedData.participantsSummary.memberCount, memberCount >= antiSpamConfiguration.minimumGroupParticipants { + if case .channel = view.peer, let participantCount = view.participantCount, participantCount >= antiSpamConfiguration.minimumGroupParticipants { antiSpamAvailable = true } @@ -800,7 +861,7 @@ public func channelAdminsController(context: AccountContext, updatedPresentation return state.withUpdatedEditing(false) } }) - } else if let peer = view.peers[peerId] as? TelegramChannel, peer.flags.contains(.isCreator) { + } else if case let .channel(peer) = view.peer, peer.flags.contains(.isCreator) { rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Edit), style: .regular, enabled: true, action: { updateState { state in return state.withUpdatedEditing(true) @@ -829,9 +890,9 @@ public func channelAdminsController(context: AccountContext, updatedPresentation previousPeers = admins var isGroup = true - if let peer = view.peers[peerId] as? TelegramChannel, case .broadcast = peer.info { + if case let .channel(peer) = view.peer, case .broadcast = peer.info { isGroup = false - } else if let _ = view.peers[peerId] as? TelegramGroup { + } else if case .legacyGroup = view.peer { isGroup = true } @@ -862,7 +923,7 @@ public func channelAdminsController(context: AccountContext, updatedPresentation } let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(isGroup ? presentationData.strings.ChatAdmins_Title : presentationData.strings.Channel_Management_Title), leftNavigationButton: nil, rightNavigationButton: rightNavigationButton, secondaryRightNavigationButton: secondaryRightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: true) - let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: channelAdminsControllerEntries(presentationData: presentationData, accountPeerId: context.account.peerId, view: view, state: state, participants: admins, antiSpamAvailable: antiSpamAvailable, antiSpamEnabled: antiSpamEnabled), style: .blocks, emptyStateItem: emptyStateItem, searchItem: searchItem, animateChanges: previous != nil && admins != nil && previous!.count >= admins!.count) + let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: channelAdminsControllerEntries(presentationData: presentationData, accountPeerId: context.account.peerId, peer: view.peer, state: state, participants: admins, antiSpamAvailable: antiSpamAvailable, antiSpamEnabled: antiSpamEnabled), style: .blocks, emptyStateItem: emptyStateItem, searchItem: searchItem, animateChanges: previous != nil && admins != nil && previous!.count >= admins!.count) return (controllerState, (listState, arguments)) } |> afterDisposed { diff --git a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSearchContainerNode.swift b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSearchContainerNode.swift index ff3bb6b05f..52ff8fb04f 100644 --- a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSearchContainerNode.swift +++ b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSearchContainerNode.swift @@ -3,7 +3,6 @@ import UIKit import AsyncDisplayKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -14,20 +13,20 @@ import ContactsPeerItem import ItemListUI private enum ChannelDiscussionGroupSearchContent: Equatable { - case peer(Peer) + case peer(EnginePeer) static func ==(lhs: ChannelDiscussionGroupSearchContent, rhs: ChannelDiscussionGroupSearchContent) -> Bool { switch lhs { case let .peer(lhsPeer): if case let .peer(rhsPeer) = rhs { - return lhsPeer.isEqual(rhsPeer) + return lhsPeer == rhsPeer } else { return false } } } - var peerId: PeerId { + var peerId: EnginePeer.Id { switch self { case let .peer(peer): return peer.id @@ -36,15 +35,15 @@ private enum ChannelDiscussionGroupSearchContent: Equatable { } private final class ChannelDiscussionGroupSearchInteraction { - let peerSelected: (Peer) -> Void + let peerSelected: (EnginePeer) -> Void - init(peerSelected: @escaping (Peer) -> Void) { + init(peerSelected: @escaping (EnginePeer) -> Void) { self.peerSelected = peerSelected } } private struct ChannelDiscussionGroupSearchEntryId: Hashable { - let peerId: PeerId + let peerId: EnginePeer.Id } private final class ChannelDiscussionGroupSearchEntry: Comparable, Identifiable { @@ -71,7 +70,7 @@ private final class ChannelDiscussionGroupSearchEntry: Comparable, Identifiable func item(context: AccountContext, presentationData: PresentationData, interaction: ChannelDiscussionGroupSearchInteraction) -> ListViewItem { switch self.content { case let .peer(peer): - return ContactsPeerItem(presentationData: ItemListPresentationData(presentationData), sortOrder: .firstLast, displayOrder: .firstLast, context: context, peerMode: .peer, peer: .peer(peer: EnginePeer(peer), chatPeer: EnginePeer(peer)), status: .none, enabled: true, selection: .none, editing: ContactsPeerItemEditing(editable: false, editing: false, revealed: false), index: nil, header: nil, action: { _ in + return ContactsPeerItem(presentationData: ItemListPresentationData(presentationData), sortOrder: .firstLast, displayOrder: .firstLast, context: context, peerMode: .peer, peer: .peer(peer: peer, chatPeer: peer), status: .none, enabled: true, selection: .none, editing: ContactsPeerItemEditing(editable: false, editing: false, revealed: false), index: nil, header: nil, action: { _ in interaction.peerSelected(peer) }) } @@ -100,7 +99,7 @@ private struct ChannelDiscussionGroupSearchContainerState: Equatable { final class ChannelDiscussionGroupSearchContainerNode: SearchDisplayControllerContentNode { private let context: AccountContext - private let openPeer: (Peer) -> Void + private let openPeer: (EnginePeer) -> Void private let dimNode: ASDisplayNode private let listNode: ListView @@ -120,7 +119,7 @@ final class ChannelDiscussionGroupSearchContainerNode: SearchDisplayControllerCo return true } - init(context: AccountContext, peers: [Peer], openPeer: @escaping (Peer) -> Void) { + init(context: AccountContext, peers: [EnginePeer], openPeer: @escaping (EnginePeer) -> Void) { self.context = context self.openPeer = openPeer @@ -153,9 +152,9 @@ final class ChannelDiscussionGroupSearchContainerNode: SearchDisplayControllerCo openPeer(peer) }) - var searchIndex: [ValueBoxKey: [Peer]] = [:] + var searchIndex: [EngineDataBuffer: [EnginePeer]] = [:] for peer in peers { - for token in peer.indexName.indexTokens { + for token in peer._asPeer().indexName.indexTokens { if searchIndex[token] == nil { searchIndex[token] = [] } @@ -170,9 +169,9 @@ final class ChannelDiscussionGroupSearchContainerNode: SearchDisplayControllerCo } var entries: [ChannelDiscussionGroupSearchEntry] = [] - let searchQueryTokens = stringIndexTokens(query.lowercased(), transliteration: .none) - var filteredPeers: [Peer] = [] - var existingPeers = Set() + let searchQueryTokens = context.engine.peers.tokenizeSearchString(string: query.lowercased(), transliteration: .none) + var filteredPeers: [EnginePeer] = [] + var existingPeers = Set() for (key, values) in searchIndex { inner: for token in searchQueryTokens { if token.isPrefix(to: key) { diff --git a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift index 53aca6894c..0efb5f7960 100644 --- a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -20,10 +19,10 @@ import UndoUI private final class ChannelDiscussionGroupSetupControllerArguments { let context: AccountContext let createGroup: () -> Void - let selectGroup: (PeerId) -> Void + let selectGroup: (EnginePeer.Id) -> Void let unlinkGroup: () -> Void - init(context: AccountContext, createGroup: @escaping () -> Void, selectGroup: @escaping (PeerId) -> Void, unlinkGroup: @escaping () -> Void) { + init(context: AccountContext, createGroup: @escaping () -> Void, selectGroup: @escaping (EnginePeer.Id) -> Void, unlinkGroup: @escaping () -> Void) { self.context = context self.createGroup = createGroup self.selectGroup = selectGroup @@ -39,13 +38,13 @@ private enum ChannelDiscussionGroupSetupControllerSection: Int32 { private enum ChannelDiscussionGroupSetupControllerEntryStableId: Hashable { case id(Int) - case peer(PeerId) + case peer(EnginePeer.Id) } private enum ChannelDiscussionGroupSetupControllerEntry: ItemListNodeEntry { case header(PresentationTheme, PresentationStrings, String?, Bool, String) case create(PresentationTheme, String) - case group(Int, PresentationTheme, PresentationStrings, Peer, PresentationPersonNameOrder) + case group(Int, PresentationTheme, PresentationStrings, EnginePeer, PresentationPersonNameOrder) case groupsInfo(PresentationTheme, String) case unlink(PresentationTheme, String) @@ -90,7 +89,7 @@ private enum ChannelDiscussionGroupSetupControllerEntry: ItemListNodeEntry { return false } case let .group(lhsIndex, lhsTheme, lhsStrings, lhsPeer, lhsNameOrder): - if case let .group(rhsIndex, rhsTheme, rhsStrings, rhsPeer, rhsNameOrder) = rhs, lhsIndex == rhsIndex, lhsTheme === rhsTheme, lhsStrings == rhsStrings, lhsPeer.isEqual(rhsPeer), lhsNameOrder == rhsNameOrder { + if case let .group(rhsIndex, rhsTheme, rhsStrings, rhsPeer, rhsNameOrder) = rhs, lhsIndex == rhsIndex, lhsTheme === rhsTheme, lhsStrings == rhsStrings, lhsPeer == rhsPeer, lhsNameOrder == rhsNameOrder { return true } else { return false @@ -150,14 +149,14 @@ private enum ChannelDiscussionGroupSetupControllerEntry: ItemListNodeEntry { }) case let .group(_, _, strings, peer, nameOrder): let text: String - if let peer = peer as? TelegramChannel, let addressName = peer.addressName, !addressName.isEmpty { + if case let .channel(peer) = peer, let addressName = peer.addressName, !addressName.isEmpty { text = "@\(addressName)" - } else if let peer = peer as? TelegramChannel, case .broadcast = peer.info { + } else if case let .channel(peer) = peer, case .broadcast = peer.info { text = strings.Channel_DiscussionGroup_PrivateChannel } else { text = strings.Channel_DiscussionGroup_PrivateGroup } - return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: PresentationDateTimeFormat(), nameDisplayOrder: nameOrder, context: arguments.context, peer: EnginePeer(peer), aliasHandling: .standard, nameStyle: .plain, presence: nil, text: .text(text, .secondary), label: .none, editing: ItemListPeerItemEditing(editable: false, editing: false, revealed: false), revealOptions: nil, switchValue: nil, enabled: true, selectable: true, sectionId: self.section, action: { + return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: PresentationDateTimeFormat(), nameDisplayOrder: nameOrder, context: arguments.context, peer: peer, aliasHandling: .standard, nameStyle: .plain, presence: nil, text: .text(text, .secondary), label: .none, editing: ItemListPeerItemEditing(editable: false, editing: false, revealed: false), revealOptions: nil, switchValue: nil, enabled: true, selectable: true, sectionId: self.section, action: { arguments.selectGroup(peer.id) }, setPeerIdWithRevealedOptions: { _, _ in }, removePeer: { _ in }) case let .groupsInfo(_, title): @@ -170,8 +169,8 @@ private enum ChannelDiscussionGroupSetupControllerEntry: ItemListNodeEntry { } } -private func channelDiscussionGroupSetupControllerEntries(presentationData: PresentationData, view: PeerView, groups: [Peer]?) -> [ChannelDiscussionGroupSetupControllerEntry] { - guard let peer = view.peers[view.peerId] as? TelegramChannel, let cachedData = view.cachedData as? CachedChannelData else { +private func channelDiscussionGroupSetupControllerEntries(presentationData: PresentationData, peer: EnginePeer?, linkedDiscussionPeer: EnginePeer?, groups: [EnginePeer]?) -> [ChannelDiscussionGroupSetupControllerEntry] { + guard case let .channel(peer) = peer else { return [] } @@ -179,25 +178,23 @@ private func channelDiscussionGroupSetupControllerEntries(presentationData: Pres var entries: [ChannelDiscussionGroupSetupControllerEntry] = [] - if case let .known(maybeLinkedDiscussionPeerId) = cachedData.linkedDiscussionPeerId, let linkedDiscussionPeerId = maybeLinkedDiscussionPeerId { - if let group = view.peers[linkedDiscussionPeerId] { + if let group = linkedDiscussionPeer { + if case .group = peer.info { + entries.append(.header(presentationData.theme, presentationData.strings, group.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), true, presentationData.strings.Channel_DiscussionGroup_HeaderLabel)) + } else { + entries.append(.header(presentationData.theme, presentationData.strings, group.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), false, presentationData.strings.Channel_DiscussionGroup_HeaderLabel)) + } + + entries.append(.group(0, presentationData.theme, presentationData.strings, group, presentationData.nameDisplayOrder)) + entries.append(.groupsInfo(presentationData.theme, presentationData.strings.Channel_DiscussionGroup_Info)) + if canEditChannel { + let unlinkText: String if case .group = peer.info { - entries.append(.header(presentationData.theme, presentationData.strings, EnginePeer(group).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), true, presentationData.strings.Channel_DiscussionGroup_HeaderLabel)) + unlinkText = presentationData.strings.Channel_DiscussionGroup_UnlinkChannel } else { - entries.append(.header(presentationData.theme, presentationData.strings, EnginePeer(group).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), false, presentationData.strings.Channel_DiscussionGroup_HeaderLabel)) - } - - entries.append(.group(0, presentationData.theme, presentationData.strings, group, presentationData.nameDisplayOrder)) - entries.append(.groupsInfo(presentationData.theme, presentationData.strings.Channel_DiscussionGroup_Info)) - if canEditChannel { - let unlinkText: String - if case .group = peer.info { - unlinkText = presentationData.strings.Channel_DiscussionGroup_UnlinkChannel - } else { - unlinkText = presentationData.strings.Channel_DiscussionGroup_UnlinkGroup - } - entries.append(.unlink(presentationData.theme, unlinkText)) + unlinkText = presentationData.strings.Channel_DiscussionGroup_UnlinkGroup } + entries.append(.unlink(presentationData.theme, unlinkText)) } } else if case .broadcast = peer.info, canEditChannel { if let groups = groups { @@ -220,30 +217,63 @@ private struct ChannelDiscussionGroupSetupControllerState: Equatable { var searching: Bool = false } -public func channelDiscussionGroupSetupController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId) -> ViewController { +public func channelDiscussionGroupSetupController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: EnginePeer.Id) -> ViewController { let statePromise = ValuePromise(ChannelDiscussionGroupSetupControllerState(), ignoreRepeated: true) let stateValue = Atomic(value: ChannelDiscussionGroupSetupControllerState()) let updateState: ((ChannelDiscussionGroupSetupControllerState) -> ChannelDiscussionGroupSetupControllerState) -> Void = { f in statePromise.set(stateValue.modify { f($0) }) } - let groupPeers = Promise<[Peer]?>() + let groupPeers = Promise<[EnginePeer]?>() groupPeers.set(.single(nil) |> then( context.engine.peers.availableGroupsForChannelDiscussion() |> map(Optional.init) - |> `catch` { _ -> Signal<[Peer]?, NoError> in + |> `catch` { _ -> Signal<[EnginePeer]?, NoError> in return .single(nil) } )) - let peerView = context.account.viewTracker.peerView(peerId) + struct PeerData { + var peer: EnginePeer? + var linkedDiscussionPeer: EnginePeer? + var hasLinkedDiscussionPeerValue: Bool + } + let peerView: Signal = context.engine.data.subscribe( + TelegramEngine.EngineData.Item.Peer.Peer(id: peerId), + TelegramEngine.EngineData.Item.Peer.LinkedDiscussionPeerId(id: peerId) + ) + |> mapToSignal { peer, linkedDiscussionPeerId -> Signal in + var linkedDiscussionPeer: Signal + var hasLinkedDiscussionPeerValue: Bool = false + if case let .known(linkedDiscussionPeerId) = linkedDiscussionPeerId { + hasLinkedDiscussionPeerValue = true + if let linkedDiscussionPeerIdValue = linkedDiscussionPeerId { + linkedDiscussionPeer = context.engine.data.subscribe( + TelegramEngine.EngineData.Item.Peer.Peer(id: linkedDiscussionPeerIdValue) + ) + } else { + linkedDiscussionPeer = .single(nil) + } + } else { + linkedDiscussionPeer = .single(nil) + } + + return linkedDiscussionPeer + |> map { linkedDiscussionPeer -> PeerData in + return PeerData( + peer: peer, + linkedDiscussionPeer: linkedDiscussionPeer, + hasLinkedDiscussionPeerValue: hasLinkedDiscussionPeerValue + ) + } + } var dismissImpl: (() -> Void)? var dismissInputImpl: (() -> Void)? var pushControllerImpl: ((ViewController) -> Void)? var presentControllerImpl: ((ViewController, Any?) -> Void)? - var navigateToGroupImpl: ((PeerId) -> Void)? + var navigateToGroupImpl: ((EnginePeer.Id) -> Void)? let actionsDisposable = DisposableSet() @@ -329,7 +359,7 @@ public func channelDiscussionGroupSetupController(context: AccountContext, updat actionSheet?.dismissAnimated() var applySignal: Signal - var updatedPeerId: PeerId? = nil + var updatedPeerId: EnginePeer.Id? = nil if case let .legacyGroup(legacyGroup) = groupPeer { applySignal = context.engine.peers.convertGroupToSupergroup(peerId: legacyGroup.id) |> mapError { error -> ChannelDiscussionGroupError in @@ -356,7 +386,7 @@ public func channelDiscussionGroupSetupController(context: AccountContext, updat } for i in 0 ..< groups.count { if groups[i].id == groupId { - groups[i] = groupPeer._asPeer() + groups[i] = groupPeer break } } @@ -495,7 +525,7 @@ public func channelDiscussionGroupSetupController(context: AccountContext, updat return } - let applyPeerId: PeerId + let applyPeerId: EnginePeer.Id if case .broadcast = peer.info { applyPeerId = peerId } else if case let .known(maybeLinkedDiscussionPeerId) = linkedDiscussionPeerId, let linkedDiscussionPeerId = maybeLinkedDiscussionPeerId { @@ -555,7 +585,7 @@ public func channelDiscussionGroupSetupController(context: AccountContext, updat |> deliverOnMainQueue |> map { presentationData, state, view, groups -> (ItemListControllerState, (ItemListNodeState, Any)) in let title: String - if let peer = view.peers[view.peerId] as? TelegramChannel, case .broadcast = peer.info { + if case let .channel(peer) = view.peer, case .broadcast = peer.info { title = presentationData.strings.Channel_DiscussionGroup } else { title = presentationData.strings.Group_LinkedChannel @@ -564,15 +594,11 @@ public func channelDiscussionGroupSetupController(context: AccountContext, updat var crossfade = false var isEmptyState = false var displayGroupList = false - if let cachedData = view.cachedData as? CachedChannelData { - var isEmpty = true - switch cachedData.linkedDiscussionPeerId { - case .unknown: - isEmpty = true - case let .known(value): - isEmpty = value == nil - } - if let peer = view.peers[view.peerId] as? TelegramChannel, case .broadcast = peer.info { + if view.hasLinkedDiscussionPeerValue { + let isEmpty: Bool + isEmpty = view.linkedDiscussionPeer == nil + + if case let .channel(peer) = view.peer, case .broadcast = peer.info { if isEmpty { if groups == nil { isEmptyState = true @@ -621,7 +647,7 @@ public func channelDiscussionGroupSetupController(context: AccountContext, updat } let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(title), leftNavigationButton: nil, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: false) - let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: channelDiscussionGroupSetupControllerEntries(presentationData: presentationData, view: view, groups: groups), style: .blocks, emptyStateItem: emptyStateItem, searchItem: searchItem, crossfadeState: crossfade, animateChanges: false) + let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: channelDiscussionGroupSetupControllerEntries(presentationData: presentationData, peer: view.peer, linkedDiscussionPeer: view.linkedDiscussionPeer, groups: groups), style: .blocks, emptyStateItem: emptyStateItem, searchItem: searchItem, crossfadeState: crossfade, animateChanges: false) return (controllerState, (listState, arguments)) } diff --git a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupSearchItem.swift b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupSearchItem.swift index 637245089b..e631a36ed9 100644 --- a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupSearchItem.swift +++ b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupSearchItem.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import AsyncDisplayKit -import Postbox import TelegramCore import SwiftSignalKit import TelegramPresentationData @@ -13,12 +12,12 @@ import SearchBarNode final class ChannelDiscussionGroupSetupSearchItem: ItemListControllerSearch { let context: AccountContext - let peers: [Peer] + let peers: [EnginePeer] let cancel: () -> Void let dismissInput: () -> Void - let openPeer: (Peer) -> Void + let openPeer: (EnginePeer) -> Void - init(context: AccountContext, peers: [Peer], cancel: @escaping () -> Void, dismissInput: @escaping () -> Void, openPeer: @escaping (Peer) -> Void) { + init(context: AccountContext, peers: [EnginePeer], cancel: @escaping () -> Void, dismissInput: @escaping () -> Void, openPeer: @escaping (EnginePeer) -> Void) { self.context = context self.peers = peers self.cancel = cancel @@ -60,7 +59,7 @@ final class ChannelDiscussionGroupSetupSearchItem: ItemListControllerSearch { private final class ChannelDiscussionGroupSetupSearchItemNode: ItemListControllerSearchNode { private let containerNode: ChannelDiscussionGroupSearchContainerNode - init(context: AccountContext, peers: [Peer], openPeer: @escaping (Peer) -> Void, cancel: @escaping () -> Void, updateActivity: @escaping (Bool) -> Void, dismissInput: @escaping () -> Void) { + init(context: AccountContext, peers: [EnginePeer], openPeer: @escaping (EnginePeer) -> Void, cancel: @escaping () -> Void, updateActivity: @escaping (Bool) -> Void, dismissInput: @escaping () -> Void) { self.containerNode = ChannelDiscussionGroupSearchContainerNode(context: context, peers: peers, openPeer: { peer in openPeer(peer) }) diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersController.swift b/submodules/PeerInfoUI/Sources/ChannelMembersController.swift index 0b947e0716..993025828a 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -16,19 +15,20 @@ import ItemListPeerActionItem import InviteLinksUI import UndoUI import SendInviteLinkScreen +import Postbox private final class ChannelMembersControllerArguments { let context: AccountContext let addMember: () -> Void - let setPeerIdWithRevealedOptions: (PeerId?, PeerId?) -> Void - let removePeer: (PeerId) -> Void - let openPeer: (Peer) -> Void + let setPeerIdWithRevealedOptions: (EnginePeer.Id?, EnginePeer.Id?) -> Void + let removePeer: (EnginePeer.Id) -> Void + let openPeer: (EnginePeer) -> Void let inviteViaLink: () -> Void let updateHideMembers: (Bool) -> Void let displayHideMembersTip: (HideMembersDisabledReason) -> Void - init(context: AccountContext, addMember: @escaping () -> Void, setPeerIdWithRevealedOptions: @escaping (PeerId?, PeerId?) -> Void, removePeer: @escaping (PeerId) -> Void, openPeer: @escaping (Peer) -> Void, inviteViaLink: @escaping () -> Void, updateHideMembers: @escaping (Bool) -> Void, displayHideMembersTip: @escaping (HideMembersDisabledReason) -> Void) { + init(context: AccountContext, addMember: @escaping () -> Void, setPeerIdWithRevealedOptions: @escaping (EnginePeer.Id?, EnginePeer.Id?) -> Void, removePeer: @escaping (EnginePeer.Id) -> Void, openPeer: @escaping (EnginePeer) -> Void, inviteViaLink: @escaping () -> Void, updateHideMembers: @escaping (Bool) -> Void, displayHideMembersTip: @escaping (HideMembersDisabledReason) -> Void) { self.context = context self.addMember = addMember self.setPeerIdWithRevealedOptions = setPeerIdWithRevealedOptions @@ -49,7 +49,7 @@ private enum ChannelMembersSection: Int32 { private enum ChannelMembersEntryStableId: Hashable { case index(Int32) - case peer(PeerId) + case peer(EnginePeer.Id) } private enum HideMembersDisabledReason: Equatable { @@ -287,7 +287,7 @@ private enum ChannelMembersEntry: ItemListNodeEntry { text = .presence } return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, context: arguments.context, peer: EnginePeer(participant.peer), presence: participant.presences[participant.peer.id].flatMap(EnginePeer.Presence.init), text: text, label: .none, editing: editing, switchValue: nil, enabled: enabled, selectable: participant.peer.id != arguments.context.account.peerId, sectionId: self.section, action: { - arguments.openPeer(participant.peer) + arguments.openPeer(EnginePeer(participant.peer)) }, setPeerIdWithRevealedOptions: { previousId, id in arguments.setPeerIdWithRevealedOptions(previousId, id) }, removePeer: { peerId in @@ -299,8 +299,8 @@ private enum ChannelMembersEntry: ItemListNodeEntry { private struct ChannelMembersControllerState: Equatable { let editing: Bool - let peerIdWithRevealedOptions: PeerId? - let removingPeerId: PeerId? + let peerIdWithRevealedOptions: EnginePeer.Id? + let removingPeerId: EnginePeer.Id? let searchingMembers: Bool init() { @@ -310,7 +310,7 @@ private struct ChannelMembersControllerState: Equatable { self.searchingMembers = false } - init(editing: Bool, peerIdWithRevealedOptions: PeerId?, removingPeerId: PeerId?, searchingMembers: Bool) { + init(editing: Bool, peerIdWithRevealedOptions: EnginePeer.Id?, removingPeerId: EnginePeer.Id?, searchingMembers: Bool) { self.editing = editing self.peerIdWithRevealedOptions = peerIdWithRevealedOptions self.removingPeerId = removingPeerId @@ -341,11 +341,11 @@ private struct ChannelMembersControllerState: Equatable { return ChannelMembersControllerState(editing: editing, peerIdWithRevealedOptions: self.peerIdWithRevealedOptions, removingPeerId: self.removingPeerId, searchingMembers: self.searchingMembers) } - func withUpdatedPeerIdWithRevealedOptions(_ peerIdWithRevealedOptions: PeerId?) -> ChannelMembersControllerState { + func withUpdatedPeerIdWithRevealedOptions(_ peerIdWithRevealedOptions: EnginePeer.Id?) -> ChannelMembersControllerState { return ChannelMembersControllerState(editing: self.editing, peerIdWithRevealedOptions: peerIdWithRevealedOptions, removingPeerId: self.removingPeerId, searchingMembers: self.searchingMembers) } - func withUpdatedRemovingPeerId(_ removingPeerId: PeerId?) -> ChannelMembersControllerState { + func withUpdatedRemovingPeerId(_ removingPeerId: EnginePeer.Id?) -> ChannelMembersControllerState { return ChannelMembersControllerState(editing: self.editing, peerIdWithRevealedOptions: self.peerIdWithRevealedOptions, removingPeerId: removingPeerId, searchingMembers: self.searchingMembers) } } @@ -428,7 +428,7 @@ private func channelMembersControllerEntries(context: AccountContext, presentati var index: Int32 = 0 - var existingPeerIds = Set() + var existingPeerIds = Set() var addedContactsHeader = false if !contacts.isEmpty { @@ -484,7 +484,7 @@ private func channelMembersControllerEntries(context: AccountContext, presentati return entries } -public func channelMembersController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId) -> ViewController { +public func channelMembersController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: EnginePeer.Id) -> ViewController { let statePromise = ValuePromise(ChannelMembersControllerState(), ignoreRepeated: true) let stateValue = Atomic(value: ChannelMembersControllerState()) let updateState: ((ChannelMembersControllerState) -> ChannelMembersControllerState) -> Void = { f in @@ -523,7 +523,7 @@ public func channelMembersController(context: AccountContext, updatedPresentatio addMembersDisposable.set(( contactsController.result |> deliverOnMainQueue - |> mapToSignal { [weak contactsController] result -> Signal<[(PeerId, AddChannelMemberError)], NoError> in + |> mapToSignal { [weak contactsController] result -> Signal<[(EnginePeer.Id, AddChannelMemberError)], NoError> in contactsController?.displayProgress = true var contacts: [ContactListPeerId] = [] @@ -531,7 +531,7 @@ public func channelMembersController(context: AccountContext, updatedPresentatio contacts = peerIdsValue } - let signal = context.peerChannelMemberCategoriesContextsManager.addMembersAllowPartial(engine: context.engine, peerId: peerId, memberIds: contacts.compactMap({ contact -> PeerId? in + let signal = context.peerChannelMemberCategoriesContextsManager.addMembersAllowPartial(engine: context.engine, peerId: peerId, memberIds: contacts.compactMap({ contact -> EnginePeer.Id? in switch contact { case let .peer(contactId): return contactId @@ -649,7 +649,7 @@ public func channelMembersController(context: AccountContext, updatedPresentatio } })) }, openPeer: { peer in - if let controller = context.sharedContext.makePeerInfoController(context: context, updatedPresentationData: nil, peer: peer, mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) { + if let controller = context.sharedContext.makePeerInfoController(context: context, updatedPresentationData: nil, peer: peer._asPeer(), mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) { pushControllerImpl?(controller) } }, inviteViaLink: { @@ -726,7 +726,7 @@ public func channelMembersController(context: AccountContext, updatedPresentatio return state.withUpdatedSearchingMembers(false) } }, openPeer: { peer, _ in - if let infoController = context.sharedContext.makePeerInfoController(context: context, updatedPresentationData: nil, peer: peer, mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) { + if let infoController = context.sharedContext.makePeerInfoController(context: context, updatedPresentationData: nil, peer: peer._asPeer(), mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) { pushControllerImpl?(infoController) } }, pushController: { c in diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift b/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift index 0850513f01..aa97ed2b2f 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift @@ -3,7 +3,6 @@ import UIKit import AsyncDisplayKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -67,14 +66,14 @@ private enum ChannelMembersSearchSection { } private enum ChannelMembersSearchContent: Equatable { - case peer(Peer) + case peer(EnginePeer) case participant(participant: RenderedChannelParticipant, label: String?, revealActions: [ParticipantRevealAction], revealed: Bool, enabled: Bool) static func ==(lhs: ChannelMembersSearchContent, rhs: ChannelMembersSearchContent) -> Bool { switch lhs { case let .peer(lhsPeer): if case let .peer(rhsPeer) = rhs { - return lhsPeer.isEqual(rhsPeer) + return lhsPeer == rhsPeer } else { return false } @@ -87,7 +86,7 @@ private enum ChannelMembersSearchContent: Equatable { } } - var peerId: PeerId { + var peerId: EnginePeer.Id { switch self { case let .peer(peer): return peer.id @@ -98,18 +97,18 @@ private enum ChannelMembersSearchContent: Equatable { } private struct RevealedPeerId: Equatable { - let peerId: PeerId + let peerId: EnginePeer.Id let section: ChannelMembersSearchSection } private final class ChannelMembersSearchContainerInteraction { - let peerSelected: (Peer, RenderedChannelParticipant?) -> Void + let peerSelected: (EnginePeer, RenderedChannelParticipant?) -> Void let setPeerIdWithRevealedOptions: (RevealedPeerId?, RevealedPeerId?) -> Void let promotePeer: (RenderedChannelParticipant) -> Void let restrictPeer: (RenderedChannelParticipant) -> Void - let removePeer: (PeerId) -> Void + let removePeer: (EnginePeer.Id) -> Void - init(peerSelected: @escaping (Peer, RenderedChannelParticipant?) -> Void, setPeerIdWithRevealedOptions: @escaping (RevealedPeerId?, RevealedPeerId?) -> Void, promotePeer: @escaping (RenderedChannelParticipant) -> Void, restrictPeer: @escaping (RenderedChannelParticipant) -> Void, removePeer: @escaping (PeerId) -> Void) { + init(peerSelected: @escaping (EnginePeer, RenderedChannelParticipant?) -> Void, setPeerIdWithRevealedOptions: @escaping (RevealedPeerId?, RevealedPeerId?) -> Void, promotePeer: @escaping (RenderedChannelParticipant) -> Void, restrictPeer: @escaping (RenderedChannelParticipant) -> Void, removePeer: @escaping (EnginePeer.Id) -> Void) { self.peerSelected = peerSelected self.setPeerIdWithRevealedOptions = setPeerIdWithRevealedOptions self.promotePeer = promotePeer @@ -119,7 +118,7 @@ private final class ChannelMembersSearchContainerInteraction { } private struct ChannelMembersSearchEntryId: Hashable { - let peerId: PeerId + let peerId: EnginePeer.Id let section: ChannelMembersSearchSection } @@ -153,7 +152,7 @@ private final class ChannelMembersSearchEntry: Comparable, Identifiable { func item(context: AccountContext, presentationData: PresentationData, nameSortOrder: PresentationPersonNameOrder, nameDisplayOrder: PresentationPersonNameOrder, interaction: ChannelMembersSearchContainerInteraction) -> ListViewItem { switch self.content { case let .peer(peer): - return ContactsPeerItem(presentationData: ItemListPresentationData(presentationData), sortOrder: nameSortOrder, displayOrder: nameDisplayOrder, context: context, peerMode: .peer, peer: .peer(peer: EnginePeer(peer), chatPeer: EnginePeer(peer)), status: .none, enabled: true, selection: .none, editing: ContactsPeerItemEditing(editable: false, editing: false, revealed: false), index: nil, header: self.section.chatListHeaderType.flatMap({ ChatListSearchItemHeader(type: $0, theme: presentationData.theme, strings: presentationData.strings, actionTitle: nil, action: nil) }), action: { _ in + return ContactsPeerItem(presentationData: ItemListPresentationData(presentationData), sortOrder: nameSortOrder, displayOrder: nameDisplayOrder, context: context, peerMode: .peer, peer: .peer(peer: peer, chatPeer: peer), status: .none, enabled: true, selection: .none, editing: ContactsPeerItemEditing(editable: false, editing: false, revealed: false), index: nil, header: self.section.chatListHeaderType.flatMap({ ChatListSearchItemHeader(type: $0, theme: presentationData.theme, strings: presentationData.strings, actionTitle: nil, action: nil) }), action: { _ in interaction.peerSelected(peer, nil) }) case let .participant(participant, label, revealActions, revealed, enabled): @@ -188,7 +187,7 @@ private final class ChannelMembersSearchEntry: Comparable, Identifiable { } return ContactsPeerItem(presentationData: ItemListPresentationData(presentationData), sortOrder: nameSortOrder, displayOrder: nameDisplayOrder, context: context, peerMode: .peer, peer: .peer(peer: EnginePeer(participant.peer), chatPeer: EnginePeer(participant.peer)), status: status, enabled: enabled, selection: .none, editing: ContactsPeerItemEditing(editable: false, editing: false, revealed: revealed), options: options, actionIcon: actionIcon, index: nil, header: self.section.chatListHeaderType.flatMap({ ChatListSearchItemHeader(type: $0, theme: presentationData.theme, strings: presentationData.strings, actionTitle: nil, action: nil) }), action: { _ in - interaction.peerSelected(participant.peer, participant) + interaction.peerSelected(EnginePeer(participant.peer), participant) }, setPeerIdWithRevealedOptions: { peerId, fromPeerId in interaction.setPeerIdWithRevealedOptions(RevealedPeerId(peerId: participant.peer.id, section: self.section), fromPeerId.flatMap({ RevealedPeerId(peerId: $0, section: self.section) })) }) @@ -212,7 +211,7 @@ private enum GroupMemberCategory { case members } -private func categorySignal(context: AccountContext, peerId: PeerId, category: GroupMemberCategory) -> Signal<[RenderedChannelParticipant], NoError> { +private func categorySignal(context: AccountContext, peerId: EnginePeer.Id, category: GroupMemberCategory) -> Signal<[RenderedChannelParticipant], NoError> { return Signal<[RenderedChannelParticipant], NoError> { subscriber in let disposableAndLoadMoreControl: (Disposable, PeerChannelMemberCategoryControl?) func processListState(_ listState: ChannelMemberListState) { @@ -255,7 +254,7 @@ private struct GroupMembersSearchContextState { public final class GroupMembersSearchContext { fileprivate let state = Promise() - public init(context: AccountContext, peerId: PeerId) { + public init(context: AccountContext, peerId: EnginePeer.Id) { assert(Queue.mainQueue().isCurrent()) let combinedSignal = combineLatest(queue: .mainQueue(), categorySignal(context: context, peerId: peerId, category: .contacts), categorySignal(context: context, peerId: peerId, category: .bots), categorySignal(context: context, peerId: peerId, category: .admins), categorySignal(context: context, peerId: peerId, category: .members)) @@ -285,12 +284,12 @@ private func channelMembersSearchContainerPreparedRecentTransition(from fromEntr private struct ChannelMembersSearchContainerState: Equatable { var revealedPeerId: RevealedPeerId? - var removingParticipantIds = Set() + var removingParticipantIds = Set() } public final class ChannelMembersSearchContainerNode: SearchDisplayControllerContentNode { private let context: AccountContext - private let openPeer: (Peer, RenderedChannelParticipant?) -> Void + private let openPeer: (EnginePeer, RenderedChannelParticipant?) -> Void private let mode: ChannelMembersSearchMode private let emptyQueryListNode: ListView @@ -320,7 +319,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon return _hasDim } - public init(context: AccountContext, forceTheme: PresentationTheme?, peerId: PeerId, mode: ChannelMembersSearchMode, filters: [ChannelMembersSearchFilter], searchContext: GroupMembersSearchContext?, openPeer: @escaping (Peer, RenderedChannelParticipant?) -> Void, updateActivity: @escaping (Bool) -> Void, pushController: @escaping (ViewController) -> Void) { + public init(context: AccountContext, forceTheme: PresentationTheme?, peerId: EnginePeer.Id, mode: ChannelMembersSearchMode, filters: [ChannelMembersSearchFilter], searchContext: GroupMembersSearchContext?, openPeer: @escaping (EnginePeer, RenderedChannelParticipant?) -> Void, updateActivity: @escaping (Bool) -> Void, pushController: @escaping (ViewController) -> Void) { self.context = context self.openPeer = openPeer self.mode = mode @@ -666,7 +665,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon foundMembers = .single([]) } - let foundContacts: Signal<([Peer], [PeerId: PeerPresence]), NoError> + let foundContacts: Signal<([EnginePeer], [EnginePeer.Id: EnginePeer.Presence]), NoError> let foundRemotePeers: Signal<([FoundPeer], [FoundPeer]), NoError> switch mode { case .inviteActions, .banAndPromoteActions: @@ -680,7 +679,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon foundContacts = .single(([], [:])) foundRemotePeers = .single(([], [])) } else { - foundContacts = context.account.postbox.searchContacts(query: query.lowercased()) + foundContacts = context.engine.contacts.searchContacts(query: query.lowercased()) foundRemotePeers = .single(([], [])) |> then(context.engine.contacts.searchRemotePeers(query: query) |> delay(0.2, queue: Queue.concurrentDefaultQueue())) } @@ -693,7 +692,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon |> map { foundGroupMembers, foundMembers, foundContacts, foundRemotePeers, presentationData, state -> [ChannelMembersSearchEntry]? in var entries: [ChannelMembersSearchEntry] = [] - var existingPeerIds = Set() + var existingPeerIds = Set() var excludeBots = false for filter in filters { switch filter { @@ -894,7 +893,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon } for peer in foundContacts.0 { - if excludeBots, let user = peer as? TelegramUser, user.botInfo != nil { + if excludeBots, case let .user(user) = peer, user.botInfo != nil { continue } @@ -914,7 +913,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon if !existingPeerIds.contains(peer.id) && peer is TelegramUser { existingPeerIds.insert(peer.id) - entries.append(ChannelMembersSearchEntry(index: index, content: .peer(peer), section: .global, dateTimeFormat: presentationData.dateTimeFormat)) + entries.append(ChannelMembersSearchEntry(index: index, content: .peer(EnginePeer(peer)), section: .global, dateTimeFormat: presentationData.dateTimeFormat)) index += 1 } } @@ -927,7 +926,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon if !existingPeerIds.contains(peer.id) && peer is TelegramUser { existingPeerIds.insert(peer.id) - entries.append(ChannelMembersSearchEntry(index: index, content: .peer(peer), section: .global, dateTimeFormat: presentationData.dateTimeFormat)) + entries.append(ChannelMembersSearchEntry(index: index, content: .peer(EnginePeer(peer)), section: .global, dateTimeFormat: presentationData.dateTimeFormat)) index += 1 } } @@ -951,12 +950,12 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon if !peer.indexName.matchesByTokens(query.lowercased()) { continue } - var creatorPeer: Peer? + var creatorPeer: EnginePeer? for participant in participants.participants { if let peer = peerView.peers[participant.peerId] { switch participant { case .creator: - creatorPeer = peer + creatorPeer = EnginePeer(peer) default: break } @@ -968,16 +967,16 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon case .creator: renderedParticipant = RenderedChannelParticipant(participant: .creator(id: peer.id, adminInfo: nil, rank: nil), peer: peer) case .admin: - var peers: [PeerId: Peer] = [:] + var peers: [EnginePeer.Id: EnginePeer] = [:] if let creator = creatorPeer { peers[creator.id] = creator } - peers[peer.id] = peer - renderedParticipant = RenderedChannelParticipant(participant: .member(id: peer.id, invitedAt: 0, adminInfo: ChannelParticipantAdminInfo(rights: TelegramChatAdminRights(rights: TelegramChatAdminRightsFlags.peerSpecific(peer: .legacyGroup(group))), promotedBy: creatorPeer?.id ?? context.account.peerId, canBeEditedByAccountPeer: creatorPeer?.id == context.account.peerId), banInfo: nil, rank: nil), peer: peer, peers: peers) + peers[peer.id] = EnginePeer(peer) + renderedParticipant = RenderedChannelParticipant(participant: .member(id: peer.id, invitedAt: 0, adminInfo: ChannelParticipantAdminInfo(rights: TelegramChatAdminRights(rights: TelegramChatAdminRightsFlags.peerSpecific(peer: .legacyGroup(group))), promotedBy: creatorPeer?.id ?? context.account.peerId, canBeEditedByAccountPeer: creatorPeer?.id == context.account.peerId), banInfo: nil, rank: nil), peer: peer, peers: peers.mapValues({ $0._asPeer() })) case .member: - var peers: [PeerId: Peer] = [:] - peers[peer.id] = peer - renderedParticipant = RenderedChannelParticipant(participant: .member(id: peer.id, invitedAt: 0, adminInfo: nil, banInfo: nil, rank: nil), peer: peer, peers: peers) + var peers: [EnginePeer.Id: EnginePeer] = [:] + peers[peer.id] = EnginePeer(peer) + renderedParticipant = RenderedChannelParticipant(participant: .member(id: peer.id, invitedAt: 0, adminInfo: nil, banInfo: nil, rank: nil), peer: peer, peers: peers.mapValues({ $0._asPeer() })) } matchingMembers.append(renderedParticipant) } @@ -1009,7 +1008,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon |> map { foundGroupMembers, foundMembers, foundRemotePeers, presentationData, state -> [ChannelMembersSearchEntry]? in var entries: [ChannelMembersSearchEntry] = [] - var existingPeerIds = Set() + var existingPeerIds = Set() var excludeBots = false for filter in filters { switch filter { @@ -1166,7 +1165,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon if !existingPeerIds.contains(peer.id) && peer is TelegramUser { existingPeerIds.insert(peer.id) - entries.append(ChannelMembersSearchEntry(index: index, content: .peer(peer), section: .global, dateTimeFormat: presentationData.dateTimeFormat)) + entries.append(ChannelMembersSearchEntry(index: index, content: .peer(EnginePeer(peer)), section: .global, dateTimeFormat: presentationData.dateTimeFormat)) index += 1 } } @@ -1180,7 +1179,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon if !existingPeerIds.contains(peer.id) && peer is TelegramUser { existingPeerIds.insert(peer.id) - entries.append(ChannelMembersSearchEntry(index: index, content: .peer(peer), section: .global, dateTimeFormat: presentationData.dateTimeFormat)) + entries.append(ChannelMembersSearchEntry(index: index, content: .peer(EnginePeer(peer)), section: .global, dateTimeFormat: presentationData.dateTimeFormat)) index += 1 } } diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersSearchController.swift b/submodules/PeerInfoUI/Sources/ChannelMembersSearchController.swift index e00c4d8015..46e0fc4489 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersSearchController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersSearchController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import TelegramCore -import Postbox import SwiftSignalKit import TelegramPresentationData import AccountContext @@ -15,8 +14,8 @@ public enum ChannelMembersSearchControllerMode { } public enum ChannelMembersSearchFilter { - case exclude([PeerId]) - case disable([PeerId]) + case exclude([EnginePeer.Id]) + case disable([EnginePeer.Id]) case excludeNonMembers case excludeBots } @@ -25,10 +24,10 @@ public final class ChannelMembersSearchController: ViewController { private let queue = Queue() private let context: AccountContext - private let peerId: PeerId + private let peerId: EnginePeer.Id private let mode: ChannelMembersSearchControllerMode private let filters: [ChannelMembersSearchFilter] - private let openPeer: (Peer, RenderedChannelParticipant?) -> Void + private let openPeer: (EnginePeer, RenderedChannelParticipant?) -> Void public var copyInviteLink: (() -> Void)? @@ -44,7 +43,7 @@ public final class ChannelMembersSearchController: ViewController { private var searchContentNode: NavigationBarSearchContentNode? - public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId, forceTheme: PresentationTheme? = nil, mode: ChannelMembersSearchControllerMode, filters: [ChannelMembersSearchFilter] = [], openPeer: @escaping (Peer, RenderedChannelParticipant?) -> Void) { + public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: EnginePeer.Id, forceTheme: PresentationTheme? = nil, mode: ChannelMembersSearchControllerMode, filters: [ChannelMembersSearchFilter] = [], openPeer: @escaping (EnginePeer, RenderedChannelParticipant?) -> Void) { self.context = context self.peerId = peerId self.mode = mode @@ -120,7 +119,7 @@ public final class ChannelMembersSearchController: ViewController { self?.deactivateSearch(animated: true) } self.controllerNode.requestOpenPeerFromSearch = { [weak self] peer, participant in - self?.openPeer(peer._asPeer(), participant) + self?.openPeer(peer, participant) } self.controllerNode.requestCopyInviteLink = { [weak self] in self?.copyInviteLink?() diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersSearchControllerNode.swift b/submodules/PeerInfoUI/Sources/ChannelMembersSearchControllerNode.swift index b48c6fe0c2..5b399fe10a 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersSearchControllerNode.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersSearchControllerNode.swift @@ -676,7 +676,7 @@ class ChannelMembersSearchControllerNode: ASDisplayNode { } self.searchDisplayController = SearchDisplayController(presentationData: self.presentationData, contentNode: ChannelMembersSearchContainerNode(context: self.context, forceTheme: self.forceTheme, peerId: self.peerId, mode: .banAndPromoteActions, filters: self.filters, searchContext: nil, openPeer: { [weak self] peer, participant in - self?.requestOpenPeerFromSearch?(EnginePeer(peer), participant) + self?.requestOpenPeerFromSearch?(peer, participant) }, updateActivity: { value in }, pushController: { [weak self] c in diff --git a/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift b/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift index db0e459c4d..f227c32cda 100644 --- a/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift @@ -3,7 +3,6 @@ import UIKit import AsyncDisplayKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import ActivityIndicator @@ -425,7 +424,7 @@ public final class ChannelOwnershipTransferAlertContentNode: AlertContentNode { } } -private func commitChannelOwnershipTransferController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peer: Peer, member: TelegramUser, present: @escaping (ViewController, Any?) -> Void, completion: @escaping (PeerId?) -> Void) -> ViewController { +private func commitChannelOwnershipTransferController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peer: EnginePeer, member: TelegramUser, present: @escaping (ViewController, Any?) -> Void, completion: @escaping (EnginePeer.Id?) -> Void) -> ViewController { let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } var dismissImpl: (() -> Void)? @@ -464,13 +463,13 @@ private func commitChannelOwnershipTransferController(context: AccountContext, u } contentNode.updateIsChecking(true) - let signal: Signal - if let peer = peer as? TelegramChannel { + let signal: Signal + if case let .channel(peer) = peer { signal = context.peerChannelMemberCategoriesContextsManager.transferOwnership(engine: context.engine, peerId: peer.id, memberId: member.id, password: contentNode.password) |> mapToSignal { _ in return .complete() } |> then(.single(nil)) - } else if let peer = peer as? TelegramGroup { + } else if case let .legacyGroup(peer) = peer { signal = context.engine.peers.convertGroupToSupergroup(peerId: peer.id) |> map(Optional.init) |> mapError { error -> ChannelOwnershipTransferError in @@ -482,7 +481,7 @@ private func commitChannelOwnershipTransferController(context: AccountContext, u } } |> deliverOnMainQueue - |> mapToSignal { upgradedPeerId -> Signal in + |> mapToSignal { upgradedPeerId -> Signal in guard let upgradedPeerId = upgradedPeerId else { return .fail(.generic) } @@ -500,7 +499,7 @@ private func commitChannelOwnershipTransferController(context: AccountContext, u completion(upgradedPeerId) }, error: { [weak contentNode] error in var isGroup = true - if let channel = peer as? TelegramChannel, case .broadcast = channel.info { + if case let .channel(channel) = peer, case .broadcast = channel.info { isGroup = false } @@ -540,12 +539,12 @@ private func commitChannelOwnershipTransferController(context: AccountContext, u return controller } -private func confirmChannelOwnershipTransferController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peer: Peer, member: TelegramUser, present: @escaping (ViewController, Any?) -> Void, completion: @escaping (PeerId?) -> Void) -> ViewController { +private func confirmChannelOwnershipTransferController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peer: EnginePeer, member: TelegramUser, present: @escaping (ViewController, Any?) -> Void, completion: @escaping (EnginePeer.Id?) -> Void) -> ViewController { let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } let theme = AlertControllerTheme(presentationData: presentationData) var isGroup = true - if let channel = peer as? TelegramChannel, case .broadcast = channel.info { + if case let .channel(channel) = peer, case .broadcast = channel.info { isGroup = false } @@ -553,10 +552,10 @@ private func confirmChannelOwnershipTransferController(context: AccountContext, var text: String if isGroup { title = presentationData.strings.Group_OwnershipTransfer_Title - text = presentationData.strings.Group_OwnershipTransfer_DescriptionInfo(EnginePeer(peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), EnginePeer(member).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string + text = presentationData.strings.Group_OwnershipTransfer_DescriptionInfo(peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), EnginePeer.user(member).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string } else { title = presentationData.strings.Channel_OwnershipTransfer_Title - text = presentationData.strings.Channel_OwnershipTransfer_DescriptionInfo(EnginePeer(peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), EnginePeer(member).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string + text = presentationData.strings.Channel_OwnershipTransfer_DescriptionInfo(peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), EnginePeer.user(member).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string } let attributedTitle = NSAttributedString(string: title, font: Font.semibold(presentationData.listsFontSize.baseDisplaySize), textColor: theme.primaryColor, paragraphAlignment: .center) @@ -571,7 +570,7 @@ private func confirmChannelOwnershipTransferController(context: AccountContext, return controller } -func channelOwnershipTransferController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peer: Peer, member: TelegramUser, initialError: ChannelOwnershipTransferError, present: @escaping (ViewController, Any?) -> Void, completion: @escaping (PeerId?) -> Void) -> ViewController { +func channelOwnershipTransferController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peer: EnginePeer, member: TelegramUser, initialError: ChannelOwnershipTransferError, present: @escaping (ViewController, Any?) -> Void, completion: @escaping (EnginePeer.Id?) -> Void) -> ViewController { let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } let theme = AlertControllerTheme(presentationData: presentationData) @@ -581,7 +580,7 @@ func channelOwnershipTransferController(context: AccountContext, updatedPresenta let textFontSize = presentationData.listsFontSize.baseDisplaySize * 13.0 / 17.0 var isGroup = true - if let channel = peer as? TelegramChannel, case .broadcast = channel.info { + if case let .channel(channel) = peer, case .broadcast = channel.info { isGroup = false } diff --git a/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift b/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift index b79d5c3d47..3845e8f792 100644 --- a/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -18,16 +17,17 @@ import TelegramPermissionsUI import ItemListPeerActionItem import Markdown import UndoUI +import Postbox private final class ChannelPermissionsControllerArguments { let context: AccountContext let updatePermission: (TelegramChatBannedRightsFlags, Bool) -> Void - 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: (ChannelParticipant) -> Void - let openPeerInfo: (Peer) -> Void + let openPeerInfo: (EnginePeer) -> Void let openKicked: () -> Void let presentRestrictedPermissionAlert: (TelegramChatBannedRightsFlags) -> Void let presentConversionToBroadcastGroup: () -> Void @@ -35,7 +35,7 @@ private final class ChannelPermissionsControllerArguments { let updateSlowmode: (Int32) -> Void let toggleIsOptionExpanded: (TelegramChatBannedRightsFlags) -> Void - init(context: AccountContext, updatePermission: @escaping (TelegramChatBannedRightsFlags, Bool) -> Void, setPeerIdWithRevealedOptions: @escaping (PeerId?, PeerId?) -> Void, addPeer: @escaping () -> Void, removePeer: @escaping (PeerId) -> Void, openPeer: @escaping (ChannelParticipant) -> Void, openPeerInfo: @escaping (Peer) -> Void, openKicked: @escaping () -> Void, presentRestrictedPermissionAlert: @escaping (TelegramChatBannedRightsFlags) -> Void, presentConversionToBroadcastGroup: @escaping () -> Void, openChannelExample: @escaping () -> Void, updateSlowmode: @escaping (Int32) -> Void, toggleIsOptionExpanded: @escaping (TelegramChatBannedRightsFlags) -> Void) { + init(context: AccountContext, updatePermission: @escaping (TelegramChatBannedRightsFlags, Bool) -> Void, setPeerIdWithRevealedOptions: @escaping (EnginePeer.Id?, EnginePeer.Id?) -> Void, addPeer: @escaping () -> Void, removePeer: @escaping (EnginePeer.Id) -> Void, openPeer: @escaping (ChannelParticipant) -> Void, openPeerInfo: @escaping (EnginePeer) -> Void, openKicked: @escaping () -> Void, presentRestrictedPermissionAlert: @escaping (TelegramChatBannedRightsFlags) -> Void, presentConversionToBroadcastGroup: @escaping () -> Void, openChannelExample: @escaping () -> Void, updateSlowmode: @escaping (Int32) -> Void, toggleIsOptionExpanded: @escaping (TelegramChatBannedRightsFlags) -> Void) { self.context = context self.updatePermission = updatePermission self.addPeer = addPeer @@ -62,7 +62,7 @@ private enum ChannelPermissionsSection: Int32 { private enum ChannelPermissionsEntryStableId: Hashable { case index(Int) - case peer(PeerId) + case peer(EnginePeer.Id) } struct SubPermission: Equatable { @@ -363,7 +363,7 @@ private enum ChannelPermissionsEntry: ItemListNodeEntry { return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, context: arguments.context, peer: EnginePeer(participant.peer), presence: nil, text: text, label: .none, editing: editing, switchValue: nil, enabled: enabled, selectable: true, sectionId: self.section, action: canOpen ? { arguments.openPeer(participant.participant) } : { - arguments.openPeerInfo(participant.peer) + arguments.openPeerInfo(EnginePeer(participant.peer)) }, setPeerIdWithRevealedOptions: { previousId, id in arguments.setPeerIdWithRevealedOptions(previousId, id) }, removePeer: { peerId in @@ -374,8 +374,8 @@ private enum ChannelPermissionsEntry: ItemListNodeEntry { } private struct ChannelPermissionsControllerState: Equatable { - var peerIdWithRevealedOptions: PeerId? - var removingPeerId: PeerId? + var peerIdWithRevealedOptions: EnginePeer.Id? + var removingPeerId: EnginePeer.Id? var searchingMembers: Bool = false var modifiedRightsFlags: TelegramChatBannedRightsFlags? var modifiedSlowmodeTimeout: Int32? @@ -656,7 +656,7 @@ private func channelPermissionsControllerEntries(context: AccountContext, presen return entries } -public func channelPermissionsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId originalPeerId: PeerId, loadCompleted: @escaping () -> Void = {}) -> ViewController { +public func channelPermissionsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId originalPeerId: EnginePeer.Id, loadCompleted: @escaping () -> Void = {}) -> ViewController { let statePromise = ValuePromise(ChannelPermissionsControllerState(), ignoreRepeated: true) let stateValue = Atomic(value: ChannelPermissionsControllerState()) let updateState: ((ChannelPermissionsControllerState) -> ChannelPermissionsControllerState) -> Void = { f in @@ -665,7 +665,7 @@ public func channelPermissionsController(context: AccountContext, updatedPresent var presentControllerImpl: ((ViewController, Any?) -> Void)? var pushControllerImpl: ((ViewController) -> Void)? - var navigateToChatControllerImpl: ((PeerId) -> Void)? + var navigateToChatControllerImpl: ((EnginePeer.Id) -> Void)? var dismissInputImpl: (() -> Void)? var dismissToChatController: (() -> Void)? var resetSlowmodeVisualValueImpl: (() -> Void)? @@ -681,12 +681,12 @@ public func channelPermissionsController(context: AccountContext, updatedPresent let removePeerDisposable = MetaDisposable() actionsDisposable.add(removePeerDisposable) - let sourcePeerId = Promise<(PeerId, Bool)>((originalPeerId, false)) + let sourcePeerId = Promise<(EnginePeer.Id, Bool)>((originalPeerId, false)) let peersDisposable = MetaDisposable() let loadMoreControl = Atomic(value: nil) - let peersPromise = Promise<(PeerId, [RenderedChannelParticipant]?)>() + let peersPromise = Promise<(EnginePeer.Id, [RenderedChannelParticipant]?)>() actionsDisposable.add((sourcePeerId.get() |> deliverOnMainQueue).start(next: { peerId, updated in @@ -722,7 +722,7 @@ public func channelPermissionsController(context: AccountContext, updatedPresent peerView.set(sourcePeerId.get() |> mapToSignal(context.account.viewTracker.peerView)) - var upgradedToSupergroupImpl: ((PeerId, @escaping () -> Void) -> Void)? + var upgradedToSupergroupImpl: ((EnginePeer.Id, @escaping () -> Void) -> Void)? let arguments = ChannelPermissionsControllerArguments(context: context, updatePermission: { rights, value in let _ = (peerView.get() @@ -922,7 +922,7 @@ public func channelPermissionsController(context: AccountContext, updatedPresent }), ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) }) }, openPeerInfo: { peer in - if let controller = context.sharedContext.makePeerInfoController(context: context, updatedPresentationData: nil, peer: peer, mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) { + if let controller = context.sharedContext.makePeerInfoController(context: context, updatedPresentationData: nil, peer: peer._asPeer(), mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) { pushControllerImpl?(controller) } }, openKicked: { @@ -1042,9 +1042,9 @@ public func channelPermissionsController(context: AccountContext, updatedPresent return .generic } } - |> mapToSignal { upgradedPeerId -> Signal in + |> mapToSignal { upgradedPeerId -> Signal in return context.engine.peers.updateChannelSlowModeInteractively(peerId: upgradedPeerId, timeout: modifiedSlowmodeTimeout == 0 ? nil : value) - |> mapToSignal { _ -> Signal in + |> mapToSignal { _ -> Signal in return .complete() } |> then(.single(upgradedPeerId)) diff --git a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift index b0d86bc067..731e974567 100644 --- a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift @@ -3,7 +3,6 @@ import UIKit import Display import AsyncDisplayKit import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -24,14 +23,15 @@ import UndoUI import QrCodeUI import PremiumUI import TextFormat +import Postbox private final class ChannelVisibilityControllerArguments { let context: AccountContext let updateCurrentType: (CurrentChannelType) -> Void let updatePublicLinkText: (String?, String) -> Void let scrollToPublicLinkText: () -> Void - let setPeerIdWithRevealedOptions: (PeerId?, PeerId?) -> Void - let revokePeerId: (PeerId) -> Void + let setPeerIdWithRevealedOptions: (EnginePeer.Id?, EnginePeer.Id?) -> Void + let revokePeerId: (EnginePeer.Id) -> Void let copyLink: (ExportedInvitation) -> Void let shareLink: (ExportedInvitation) -> Void let linkContextAction: (ASDisplayNode, ContextGesture?) -> Void @@ -44,7 +44,7 @@ private final class ChannelVisibilityControllerArguments { let deactivateLink: (String) -> Void let openAuction: (String) -> Void - init(context: AccountContext, updateCurrentType: @escaping (CurrentChannelType) -> Void, updatePublicLinkText: @escaping (String?, String) -> Void, scrollToPublicLinkText: @escaping () -> Void, setPeerIdWithRevealedOptions: @escaping (PeerId?, PeerId?) -> Void, revokePeerId: @escaping (PeerId) -> Void, copyLink: @escaping (ExportedInvitation) -> Void, shareLink: @escaping (ExportedInvitation) -> Void, linkContextAction: @escaping (ASDisplayNode, ContextGesture?) -> Void, manageInviteLinks: @escaping () -> Void, openLink: @escaping (ExportedInvitation) -> Void, toggleForwarding: @escaping (Bool) -> Void, updateJoinToSend: @escaping (CurrentChannelJoinToSend) -> Void, toggleApproveMembers: @escaping (Bool) -> Void, activateLink: @escaping (String) -> Void, deactivateLink: @escaping (String) -> Void, openAuction: @escaping (String) -> Void) { + init(context: AccountContext, updateCurrentType: @escaping (CurrentChannelType) -> Void, updatePublicLinkText: @escaping (String?, String) -> Void, scrollToPublicLinkText: @escaping () -> Void, setPeerIdWithRevealedOptions: @escaping (EnginePeer.Id?, EnginePeer.Id?) -> Void, revokePeerId: @escaping (EnginePeer.Id) -> Void, copyLink: @escaping (ExportedInvitation) -> Void, shareLink: @escaping (ExportedInvitation) -> Void, linkContextAction: @escaping (ASDisplayNode, ContextGesture?) -> Void, manageInviteLinks: @escaping () -> Void, openLink: @escaping (ExportedInvitation) -> Void, toggleForwarding: @escaping (Bool) -> Void, updateJoinToSend: @escaping (CurrentChannelJoinToSend) -> Void, toggleApproveMembers: @escaping (Bool) -> Void, activateLink: @escaping (String) -> Void, deactivateLink: @escaping (String) -> Void, openAuction: @escaping (String) -> Void) { self.context = context self.updateCurrentType = updateCurrentType self.updatePublicLinkText = updatePublicLinkText @@ -114,7 +114,7 @@ private enum ChannelVisibilityEntry: ItemListNodeEntry { case publicLinkStatus(PresentationTheme, String, AddressNameValidationStatus, String) case existingLinksInfo(PresentationTheme, String) - case existingLinkPeerItem(Int32, PresentationTheme, PresentationStrings, PresentationDateTimeFormat, PresentationPersonNameOrder, Peer, ItemListPeerItemEditing, Bool) + case existingLinkPeerItem(Int32, PresentationTheme, PresentationStrings, PresentationDateTimeFormat, PresentationPersonNameOrder, EnginePeer, ItemListPeerItemEditing, Bool) case additionalLinkHeader(PresentationTheme, String) case additionalLink(PresentationTheme, TelegramPeerUsername, Int32) @@ -348,7 +348,7 @@ private enum ChannelVisibilityEntry: ItemListNodeEntry { if lhsNameOrder != rhsNameOrder { return false } - if !lhsPeer.isEqual(rhsPeer) { + if lhsPeer != rhsPeer { return false } if lhsEditing != rhsEditing { @@ -704,7 +704,7 @@ private enum ChannelVisibilityEntry: ItemListNodeEntry { if let addressName = peer.addressName { label = "t.me/" + addressName } - return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, context: arguments.context, peer: EnginePeer(peer), presence: nil, text: .text(label, .secondary), label: .none, editing: editing, switchValue: nil, enabled: enabled, selectable: true, sectionId: self.section, action: nil, setPeerIdWithRevealedOptions: { previousId, id in + return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, context: arguments.context, peer: peer, presence: nil, text: .text(label, .secondary), label: .none, editing: editing, switchValue: nil, enabled: enabled, selectable: true, sectionId: self.section, action: nil, setPeerIdWithRevealedOptions: { previousId, id in arguments.setPeerIdWithRevealedOptions(previousId, id) }, removePeer: { peerId in arguments.revokePeerId(peerId) @@ -772,8 +772,8 @@ private struct ChannelVisibilityControllerState: Equatable { let editingPublicLinkText: String? let addressNameValidationStatus: AddressNameValidationStatus? let updatingAddressName: Bool - let revealedRevokePeerId: PeerId? - let revokingPeerId: PeerId? + let revealedRevokePeerId: EnginePeer.Id? + let revokingPeerId: EnginePeer.Id? let revokingPrivateLink: Bool let forwardingEnabled: Bool? let joinToSend: CurrentChannelJoinToSend? @@ -855,11 +855,11 @@ private struct ChannelVisibilityControllerState: Equatable { return ChannelVisibilityControllerState(selectedType: self.selectedType, editingPublicLinkText: self.editingPublicLinkText, addressNameValidationStatus: self.addressNameValidationStatus, updatingAddressName: updatingAddressName, revealedRevokePeerId: self.revealedRevokePeerId, revokingPeerId: self.revokingPeerId, revokingPrivateLink: self.revokingPrivateLink, forwardingEnabled: self.forwardingEnabled, joinToSend: self.joinToSend, approveMembers: self.approveMembers) } - func withUpdatedRevealedRevokePeerId(_ revealedRevokePeerId: PeerId?) -> ChannelVisibilityControllerState { + func withUpdatedRevealedRevokePeerId(_ revealedRevokePeerId: EnginePeer.Id?) -> ChannelVisibilityControllerState { return ChannelVisibilityControllerState(selectedType: self.selectedType, editingPublicLinkText: self.editingPublicLinkText, addressNameValidationStatus: self.addressNameValidationStatus, updatingAddressName: updatingAddressName, revealedRevokePeerId: revealedRevokePeerId, revokingPeerId: self.revokingPeerId, revokingPrivateLink: self.revokingPrivateLink, forwardingEnabled: self.forwardingEnabled, joinToSend: self.joinToSend, approveMembers: self.approveMembers) } - func withUpdatedRevokingPeerId(_ revokingPeerId: PeerId?) -> ChannelVisibilityControllerState { + func withUpdatedRevokingPeerId(_ revokingPeerId: EnginePeer.Id?) -> ChannelVisibilityControllerState { return ChannelVisibilityControllerState(selectedType: self.selectedType, editingPublicLinkText: self.editingPublicLinkText, addressNameValidationStatus: self.addressNameValidationStatus, updatingAddressName: updatingAddressName, revealedRevokePeerId: self.revealedRevokePeerId, revokingPeerId: revokingPeerId, revokingPrivateLink: self.revokingPrivateLink, forwardingEnabled: self.forwardingEnabled, joinToSend: self.joinToSend, approveMembers: self.approveMembers) } @@ -880,7 +880,7 @@ private struct ChannelVisibilityControllerState: Equatable { } } -private func channelVisibilityControllerEntries(presentationData: PresentationData, mode: ChannelVisibilityControllerMode, view: PeerView, publicChannelsToRevoke: [Peer]?, importers: PeerInvitationImportersState?, state: ChannelVisibilityControllerState, limits: EngineConfiguration.UserLimits, premiumLimits: EngineConfiguration.UserLimits, isPremium: Bool, isPremiumDisabled: Bool, temporaryOrder: [String]?) -> [ChannelVisibilityEntry] { +private func channelVisibilityControllerEntries(presentationData: PresentationData, mode: ChannelVisibilityControllerMode, view: PeerView, publicChannelsToRevoke: [EnginePeer]?, importers: PeerInvitationImportersState?, state: ChannelVisibilityControllerState, limits: EngineConfiguration.UserLimits, premiumLimits: EngineConfiguration.UserLimits, isPremium: Bool, isPremiumDisabled: Bool, temporaryOrder: [String]?) -> [ChannelVisibilityEntry] { var entries: [ChannelVisibilityEntry] = [] let isInitialSetup: Bool @@ -1009,10 +1009,10 @@ private func channelVisibilityControllerEntries(presentationData: PresentationDa for peer in publicChannelsToRevoke.sorted(by: { lhs, rhs in var lhsDate: Int32 = 0 var rhsDate: Int32 = 0 - if let lhs = lhs as? TelegramChannel { + if case let .channel(lhs) = lhs { lhsDate = lhs.creationDate } - if let rhs = rhs as? TelegramChannel { + if case let .channel(rhs) = rhs { rhsDate = rhs.creationDate } return lhsDate > rhsDate @@ -1185,10 +1185,10 @@ private func channelVisibilityControllerEntries(presentationData: PresentationDa for peer in publicChannelsToRevoke.sorted(by: { lhs, rhs in var lhsDate: Int32 = 0 var rhsDate: Int32 = 0 - if let lhs = lhs as? TelegramChannel { + if case let .channel(lhs) = lhs { lhsDate = lhs.creationDate } - if let rhs = rhs as? TelegramChannel { + if case let .channel(rhs) = rhs { rhsDate = rhs.creationDate } return lhsDate > rhsDate @@ -1336,8 +1336,8 @@ private func effectiveChannelType(mode: ChannelVisibilityControllerMode, state: return selectedType } -private func updatedAddressName(mode: ChannelVisibilityControllerMode, state: ChannelVisibilityControllerState, peer: Peer, cachedData: CachedPeerData?) -> String? { - if let peer = peer as? TelegramChannel { +private func updatedAddressName(mode: ChannelVisibilityControllerMode, state: ChannelVisibilityControllerState, peer: EnginePeer, cachedData: CachedPeerData?) -> String? { + if case let .channel(peer) = peer { let selectedType = effectiveChannelType(mode: mode, state: state, peer: peer, cachedData: cachedData) let currentUsername: String @@ -1368,7 +1368,7 @@ private func updatedAddressName(mode: ChannelVisibilityControllerMode, state: Ch } else { return nil } - } else if let _ = peer as? TelegramGroup { + } else if case .legacyGroup = peer { let currentUsername = state.editingPublicLinkText ?? "" if !currentUsername.isEmpty { return currentUsername @@ -1384,17 +1384,17 @@ public enum ChannelVisibilityControllerMode { case initialSetup case generic case privateLink - case revokeNames([Peer]) + case revokeNames([EnginePeer]) } -public func channelVisibilityController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId, mode: ChannelVisibilityControllerMode, upgradedToSupergroup: @escaping (PeerId, @escaping () -> Void) -> Void, onDismissRemoveController: ViewController? = nil, revokedPeerAddressName: ((PeerId) -> Void)? = nil) -> ViewController { +public func channelVisibilityController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: EnginePeer.Id, mode: ChannelVisibilityControllerMode, upgradedToSupergroup: @escaping (EnginePeer.Id, @escaping () -> Void) -> Void, onDismissRemoveController: ViewController? = nil, revokedPeerAddressName: ((EnginePeer.Id) -> Void)? = nil) -> ViewController { let statePromise = ValuePromise(ChannelVisibilityControllerState(), ignoreRepeated: true) let stateValue = Atomic(value: ChannelVisibilityControllerState()) let updateState: ((ChannelVisibilityControllerState) -> ChannelVisibilityControllerState) -> Void = { f in statePromise.set(stateValue.modify { f($0) }) } - let adminedPublicChannels = Promise<[Peer]?>() + let adminedPublicChannels = Promise<[EnginePeer]?>() if case let .revokeNames(peers) = mode { adminedPublicChannels.set(.single(peers)) } else { @@ -1402,8 +1402,8 @@ public func channelVisibilityController(context: AccountContext, updatedPresenta |> map(Optional.init)) } - let peersDisablingAddressNameAssignment = Promise<[Peer]?>() - peersDisablingAddressNameAssignment.set(.single(nil) |> then(context.engine.peers.channelAddressNameAssignmentAvailability(peerId: peerId.namespace == Namespaces.Peer.CloudChannel ? peerId : nil) |> mapToSignal { result -> Signal<[Peer]?, NoError> in + let peersDisablingAddressNameAssignment = Promise<[EnginePeer]?>() + peersDisablingAddressNameAssignment.set(.single(nil) |> then(context.engine.peers.channelAddressNameAssignmentAvailability(peerId: peerId.namespace == Namespaces.Peer.CloudChannel ? peerId : nil) |> mapToSignal { result -> Signal<[EnginePeer]?, NoError> in if case .addressNameLimitReached = result { return context.engine.peers.adminedPublicChannels(scope: .all) |> map(Optional.init) @@ -1857,7 +1857,7 @@ public func channelVisibilityController(context: AccountContext, updatedPresenta rightNavigationButton = ItemListNavigationButton(content: .text(isInitialSetup ? presentationData.strings.Common_Next : presentationData.strings.Common_Done), style: state.updatingAddressName ? .activity : .bold, enabled: doneEnabled, action: { var updatedAddressNameValue: String? updateState { state in - updatedAddressNameValue = updatedAddressName(mode: mode, state: state, peer: peer, cachedData: view.cachedData) + updatedAddressNameValue = updatedAddressName(mode: mode, state: state, peer: .channel(peer), cachedData: view.cachedData) return state } @@ -1953,7 +1953,7 @@ public func channelVisibilityController(context: AccountContext, updatedPresenta rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Done), style: state.updatingAddressName ? .activity : .bold, enabled: doneEnabled, action: { var updatedAddressNameValue: String? updateState { state in - updatedAddressNameValue = updatedAddressName(mode: mode, state: state, peer: peer, cachedData: nil) + updatedAddressNameValue = updatedAddressName(mode: mode, state: state, peer: .legacyGroup(peer), cachedData: nil) return state } diff --git a/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift b/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift index fa2162d8ff..e5c9a37338 100644 --- a/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift +++ b/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import ItemListUI @@ -120,7 +119,7 @@ private func convertToSupergroupEntries(presentationData: PresentationData) -> [ return entries } -public func convertToSupergroupController(context: AccountContext, peerId: PeerId) -> ViewController { +public func convertToSupergroupController(context: AccountContext, peerId: EnginePeer.Id) -> ViewController { var replaceControllerImpl: ((ViewController) -> Void)? var presentControllerImpl: ((ViewController, Any?) -> Void)? diff --git a/submodules/PeerInfoUI/Sources/DeviceContactInfoController.swift b/submodules/PeerInfoUI/Sources/DeviceContactInfoController.swift index 69618abfd2..e310908f96 100644 --- a/submodules/PeerInfoUI/Sources/DeviceContactInfoController.swift +++ b/submodules/PeerInfoUI/Sources/DeviceContactInfoController.swift @@ -3,7 +3,6 @@ import UIKit import Display import AsyncDisplayKit import SwiftSignalKit -import Postbox import TelegramCore import MessageUI import TelegramPresentationData @@ -24,6 +23,7 @@ import PhoneNumberFormat import UndoUI import GalleryUI import PeerAvatarGalleryUI +import Postbox private enum DeviceContactInfoAction { case sendMessage @@ -48,9 +48,9 @@ private final class DeviceContactInfoControllerArguments { let openAddress: (DeviceContactAddressData) -> Void let displayCopyContextMenu: (DeviceContactInfoEntryTag, String) -> Void let updateShareViaException: (Bool) -> Void - let openAvatar: (Peer) -> Void + let openAvatar: (EnginePeer) -> Void - init(context: AccountContext, isPlain: Bool, updateEditingName: @escaping (ItemListAvatarAndNameInfoItemName) -> Void, updatePhone: @escaping (Int64, String) -> Void, updatePhoneLabel: @escaping (Int64, String) -> Void, deletePhone: @escaping (Int64) -> Void, setPhoneIdWithRevealedOptions: @escaping (Int64?, Int64?) -> Void, addPhoneNumber: @escaping () -> Void, performAction: @escaping (DeviceContactInfoAction) -> Void, toggleSelection: @escaping (DeviceContactInfoDataId) -> Void, callPhone: @escaping (String) -> Void, openUrl: @escaping (String) -> Void, openAddress: @escaping (DeviceContactAddressData) -> Void, displayCopyContextMenu: @escaping (DeviceContactInfoEntryTag, String) -> Void, updateShareViaException: @escaping (Bool) -> Void, openAvatar: @escaping (Peer) -> Void) { + init(context: AccountContext, isPlain: Bool, updateEditingName: @escaping (ItemListAvatarAndNameInfoItemName) -> Void, updatePhone: @escaping (Int64, String) -> Void, updatePhoneLabel: @escaping (Int64, String) -> Void, deletePhone: @escaping (Int64) -> Void, setPhoneIdWithRevealedOptions: @escaping (Int64?, Int64?) -> Void, addPhoneNumber: @escaping () -> Void, performAction: @escaping (DeviceContactInfoAction) -> Void, toggleSelection: @escaping (DeviceContactInfoDataId) -> Void, callPhone: @escaping (String) -> Void, openUrl: @escaping (String) -> Void, openAddress: @escaping (DeviceContactAddressData) -> Void, displayCopyContextMenu: @escaping (DeviceContactInfoEntryTag, String) -> Void, updateShareViaException: @escaping (Bool) -> Void, openAvatar: @escaping (EnginePeer) -> Void) { self.context = context self.isPlain = isPlain self.updateEditingName = updateEditingName @@ -127,7 +127,7 @@ private enum DeviceContactInfoEntryId: Hashable { } private enum DeviceContactInfoEntry: ItemListNodeEntry { - case info(Int, PresentationTheme, PresentationStrings, PresentationDateTimeFormat, peer: Peer, state: ItemListAvatarAndNameInfoItemState, job: String?, isPlain: Bool, hiddenAvatar: TelegramMediaImageRepresentation?) + case info(Int, PresentationTheme, PresentationStrings, PresentationDateTimeFormat, peer: EnginePeer, state: ItemListAvatarAndNameInfoItemState, job: String?, isPlain: Bool, hiddenAvatar: TelegramMediaImageRepresentation?) case invite(Int, PresentationTheme, String) case sendMessage(Int, PresentationTheme, String) @@ -223,7 +223,7 @@ private enum DeviceContactInfoEntry: ItemListNodeEntry { if lhsDateTimeFormat != rhsDateTimeFormat { return false } - if !arePeersEqual(lhsPeer, rhsPeer) { + if lhsPeer != rhsPeer { return false } if lhsState != rhsState { @@ -404,7 +404,7 @@ private enum DeviceContactInfoEntry: ItemListNodeEntry { let arguments = arguments as! DeviceContactInfoControllerArguments switch self { case let .info(_, _, _, dateTimeFormat, peer, state, jobSummary, _, hiddenAvatar): - return ItemListAvatarAndNameInfoItem(accountContext: arguments.context, presentationData: presentationData, dateTimeFormat: dateTimeFormat, mode: .contact, peer: EnginePeer(peer), presence: nil, label: jobSummary, memberCount: nil, state: state, sectionId: self.section, style: arguments.isPlain ? .plain : .blocks(withTopInset: false, withExtendedBottomInset: true), editingNameUpdated: { editingName in + return ItemListAvatarAndNameInfoItem(accountContext: arguments.context, presentationData: presentationData, dateTimeFormat: dateTimeFormat, mode: .contact, peer: peer, presence: nil, label: jobSummary, memberCount: nil, state: state, sectionId: self.section, style: arguments.isPlain ? .plain : .blocks(withTopInset: false, withExtendedBottomInset: true), editingNameUpdated: { editingName in arguments.updateEditingName(editingName) }, avatarTapped: { if peer.smallProfileImage != nil { @@ -625,7 +625,7 @@ private func filteredContactData(contactData: DeviceContactExtendedData, exclude return DeviceContactExtendedData(basicData: DeviceContactBasicData(firstName: contactData.basicData.firstName, lastName: contactData.basicData.lastName, phoneNumbers: phoneNumbers), middleName: contactData.middleName, prefix: contactData.prefix, suffix: contactData.suffix, organization: includeJob ? contactData.organization : "", jobTitle: includeJob ? contactData.jobTitle : "", department: includeJob ? contactData.department : "", emailAddresses: emailAddresses, urls: urls, addresses: addresses, birthdayDate: includeBirthday ? contactData.birthdayDate : nil, socialProfiles: socialProfiles, instantMessagingProfiles: instantMessagingProfiles, note: includeNote ? contactData.note : "") } -private func deviceContactInfoEntries(account: Account, engine: TelegramEngine, presentationData: PresentationData, peer: Peer?, isShare: Bool, shareViaException: Bool, contactData: DeviceContactExtendedData, isContact: Bool, state: DeviceContactInfoState, selecting: Bool, editingPhoneNumbers: Bool, hiddenAvatar: TelegramMediaImageRepresentation?) -> [DeviceContactInfoEntry] { +private func deviceContactInfoEntries(account: Account, engine: TelegramEngine, presentationData: PresentationData, peer: EnginePeer?, isShare: Bool, shareViaException: Bool, contactData: DeviceContactExtendedData, isContact: Bool, state: DeviceContactInfoState, selecting: Bool, editingPhoneNumbers: Bool, hiddenAvatar: TelegramMediaImageRepresentation?) -> [DeviceContactInfoEntry] { var entries: [DeviceContactInfoEntry] = [] var editingName: ItemListAvatarAndNameInfoItemName? @@ -663,7 +663,7 @@ private func deviceContactInfoEntries(account: Account, engine: TelegramEngine, firstName = presentationData.strings.Message_Contact } - entries.append(.info(entries.count, presentationData.theme, presentationData.strings, presentationData.dateTimeFormat, peer: peer ?? TelegramUser(id: PeerId(namespace: .max, id: PeerId.Id._internalFromInt64Value(0)), accessHash: nil, firstName: firstName, lastName: isOrganization ? nil : personName.1, username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: [], emojiStatus: nil, usernames: []), state: ItemListAvatarAndNameInfoItemState(editingName: editingName, updatingName: nil), job: isOrganization ? nil : jobSummary, isPlain: !isShare, hiddenAvatar: hiddenAvatar)) + entries.append(.info(entries.count, presentationData.theme, presentationData.strings, presentationData.dateTimeFormat, peer: peer ?? EnginePeer.user(TelegramUser(id: EnginePeer.Id(namespace: .max, id: EnginePeer.Id.Id._internalFromInt64Value(0)), accessHash: nil, firstName: firstName, lastName: isOrganization ? nil : personName.1, username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: [], emojiStatus: nil, usernames: [])), state: ItemListAvatarAndNameInfoItemState(editingName: editingName, updatingName: nil), job: isOrganization ? nil : jobSummary, isPlain: !isShare, hiddenAvatar: hiddenAvatar)) if !selecting { if let _ = peer { @@ -696,7 +696,7 @@ private func deviceContactInfoEntries(account: Account, engine: TelegramEngine, } else if !personName.1.isEmpty { personCompactName = personName.1 } else { - personCompactName = EnginePeer(peer).compactDisplayTitle + personCompactName = peer.compactDisplayTitle } if contactData.basicData.phoneNumbers.isEmpty { @@ -859,7 +859,7 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta } var addToExistingImpl: (() -> Void)? - var openChatImpl: ((PeerId) -> Void)? + var openChatImpl: ((EnginePeer.Id) -> Void)? var replaceControllerImpl: ((ViewController) -> Void)? var pushControllerImpl: ((ViewController) -> Void)? var presentControllerImpl: ((ViewController, Any?) -> Void)? @@ -867,7 +867,7 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta var openAddressImpl: ((DeviceContactAddressData) -> Void)? var inviteImpl: (([String]) -> Void)? var dismissImpl: ((Bool) -> Void)? - var openAvatarImpl: ((Peer) -> Void)? + var openAvatarImpl: ((EnginePeer) -> Void)? let actionsDisposable = DisposableSet() @@ -918,16 +918,16 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta }) } - let contactData: Signal<(Peer?, DeviceContactStableId?, DeviceContactExtendedData), NoError> + let contactData: Signal<(EnginePeer?, DeviceContactStableId?, DeviceContactExtendedData), NoError> var isShare = false var shareViaException = false switch subject { case let .vcard(peer, id, data): - contactData = .single((peer, id, data)) + contactData = .single((peer.flatMap(EnginePeer.init), id, data)) case let .filter(peer, id, data, _): - contactData = .single((peer, id, data)) + contactData = .single((peer.flatMap(EnginePeer.init), id, data)) case let .create(peer, data, share, shareViaExceptionValue, _): - contactData = .single((peer, nil, data)) + contactData = .single((peer.flatMap(EnginePeer.init), nil, data)) isShare = share shareViaException = shareViaExceptionValue } @@ -1084,7 +1084,7 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta } else if case let .filter(_, _, _, completion) = subject { let filteredData = filteredContactData(contactData: peerAndContactData.2, excludedComponents: state.excludedComponents) rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.ShareMenu_Send), style: .bold, enabled: !filteredData.basicData.phoneNumbers.isEmpty, action: { - completion(peerAndContactData.0, filteredData) + completion(peerAndContactData.0?._asPeer(), filteredData) dismissImpl?(true) }) } else if case let .create(createForPeer, _, _, _, completion) = subject { @@ -1113,6 +1113,7 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta } composedContactData = DeviceContactExtendedData(basicData: DeviceContactBasicData(firstName: firstName, lastName: lastName, phoneNumbers: filteredPhoneNumbers), middleName: filteredData.middleName, prefix: filteredData.prefix, suffix: filteredData.suffix, organization: filteredData.organization, jobTitle: filteredData.jobTitle, department: filteredData.department, emailAddresses: filteredData.emailAddresses, urls: urls, addresses: filteredData.addresses, birthdayDate: filteredData.birthdayDate, socialProfiles: filteredData.socialProfiles, instantMessagingProfiles: filteredData.instantMessagingProfiles, note: filteredData.note) } + rightNavigationButton = ItemListNavigationButton(content: .text(isShare ? presentationData.strings.Common_Done : presentationData.strings.Compose_Create), style: .bold, enabled: (isShare || !filteredPhoneNumbers.isEmpty) && composedContactData != nil, action: { if let composedContactData = composedContactData { var addToPrivacyExceptions = false @@ -1152,7 +1153,7 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta let _ = (contactDataManager.createContactWithData(composedContactData) |> castError(AddContactError.self) - |> mapToSignal { contactIdAndData -> Signal<(DeviceContactStableId, DeviceContactExtendedData, Peer?)?, AddContactError> in + |> mapToSignal { contactIdAndData -> Signal<(DeviceContactStableId, DeviceContactExtendedData, EnginePeer?)?, AddContactError> in guard let (id, data) = contactIdAndData else { return .single(nil) } @@ -1161,13 +1162,13 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta case let .create(peer, _, share, shareViaException, _): if share, let peer = peer { return context.engine.contacts.addContactInteractively(peerId: peer.id, firstName: composedContactData.basicData.firstName, lastName: composedContactData.basicData.lastName, phoneNumber: filteredPhoneNumbers.first?.value ?? "", addToPrivacyExceptions: shareViaException && addToPrivacyExceptions) - |> mapToSignal { _ -> Signal<(DeviceContactStableId, DeviceContactExtendedData, Peer?)?, AddContactError> in + |> mapToSignal { _ -> Signal<(DeviceContactStableId, DeviceContactExtendedData, EnginePeer?)?, AddContactError> in } |> then( context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peer.id)) |> castError(AddContactError.self) - |> map { result -> (DeviceContactStableId, DeviceContactExtendedData, Peer?)? in - return (id, data, result?._asPeer()) + |> map { result -> (DeviceContactStableId, DeviceContactExtendedData, EnginePeer?)? in + return (id, data, result) } ) } @@ -1177,12 +1178,12 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta return context.engine.contacts.importContact(firstName: composedContactData.basicData.firstName, lastName: composedContactData.basicData.lastName, phoneNumber: filteredPhoneNumbers[0].value) |> castError(AddContactError.self) - |> mapToSignal { peerId -> Signal<(DeviceContactStableId, DeviceContactExtendedData, Peer?)?, AddContactError> in + |> mapToSignal { peerId -> Signal<(DeviceContactStableId, DeviceContactExtendedData, EnginePeer?)?, AddContactError> in if let peerId = peerId { return context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) |> castError(AddContactError.self) - |> map { result -> (DeviceContactStableId, DeviceContactExtendedData, Peer?)? in - return (id, data, result?._asPeer()) + |> map { result -> (DeviceContactStableId, DeviceContactExtendedData, EnginePeer?)? in + return (id, data, result) } } else { return .single((id, data, nil)) @@ -1199,7 +1200,7 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta return state } if let contactIdAndData = contactIdAndData { - completion(contactIdAndData.2, contactIdAndData.0, contactIdAndData.1) + completion(contactIdAndData.2?._asPeer(), contactIdAndData.0, contactIdAndData.1) } completed?() dismissImpl?(true) @@ -1231,7 +1232,7 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta let editingPhoneIds = Set(state.phoneNumbers.map({ $0.id })) let previousPhoneIds = previousEditingPhoneIds.swap(editingPhoneIds) - let insertedPhoneIds = editingPhoneIds.subtracting(previousPhoneIds ?? Set()) + let insertedPhoneIds = editingPhoneIds.subtracting(previousPhoneIds ?? Set()) var insertedPhoneId: Int64? if insertedPhoneIds.count == 1, let id = insertedPhoneIds.first { for phoneNumber in state.phoneNumbers { @@ -1264,7 +1265,7 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta return } addContactToExisting(context: context, parentController: controller, contactData: subject.contactData, completion: { peer, contactId, contactData in - replaceControllerImpl?(deviceContactInfoController(context: context, subject: .vcard(peer, contactId, contactData), completed: nil, cancelled: nil)) + replaceControllerImpl?(deviceContactInfoController(context: context, subject: .vcard(peer?._asPeer(), contactId, contactData), completed: nil, cancelled: nil)) }) } openChatImpl = { [weak controller] peerId in @@ -1349,7 +1350,7 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta } } openAvatarImpl = { [weak controller] peer in - let avatarController = AvatarGalleryController(context: context, peer: EnginePeer(peer), replaceRootController: { _, _ in + let avatarController = AvatarGalleryController(context: context, peer: peer, replaceRootController: { _, _ in }) hiddenAvatarPromise.set( avatarController.hiddenMedia @@ -1378,14 +1379,14 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta return controller } -private func addContactToExisting(context: AccountContext, parentController: ViewController, contactData: DeviceContactExtendedData, completion: @escaping (Peer?, DeviceContactStableId, DeviceContactExtendedData) -> Void) { +private func addContactToExisting(context: AccountContext, parentController: ViewController, contactData: DeviceContactExtendedData, completion: @escaping (EnginePeer?, DeviceContactStableId, DeviceContactExtendedData) -> Void) { let contactsController = context.sharedContext.makeContactSelectionController(ContactSelectionControllerParams(context: context, title: { $0.Contacts_Title }, displayDeviceContacts: true)) contactsController.navigationPresentation = .modal (parentController.navigationController as? NavigationController)?.pushViewController(contactsController) let _ = (contactsController.result |> deliverOnMainQueue).start(next: { result in if let (peers, _, _, _, _) = result, let peer = peers.first { - let dataSignal: Signal<(Peer?, DeviceContactStableId?), NoError> + let dataSignal: Signal<(EnginePeer?, DeviceContactStableId?), NoError> switch peer { case let .peer(contact, _, _): guard let contact = contact as? TelegramUser, let phoneNumber = contact.phone else { @@ -1393,7 +1394,7 @@ private func addContactToExisting(context: AccountContext, parentController: Vie } dataSignal = (context.sharedContext.contactDataManager?.basicData() ?? .single([:])) |> take(1) - |> mapToSignal { basicData -> Signal<(Peer?, DeviceContactStableId?), NoError> in + |> mapToSignal { basicData -> Signal<(EnginePeer?, DeviceContactStableId?), NoError> in var stableId: String? let queryPhoneNumber = formatPhoneNumber(phoneNumber) outer: for (id, data) in basicData { @@ -1404,7 +1405,7 @@ private func addContactToExisting(context: AccountContext, parentController: Vie } } } - return .single((contact, stableId)) + return .single((EnginePeer.user(contact), stableId)) } case let .deviceContact(id, _): dataSignal = .single((nil, id)) @@ -1412,8 +1413,7 @@ private func addContactToExisting(context: AccountContext, parentController: Vie let _ = (dataSignal |> deliverOnMainQueue).start(next: { peer, stableId in guard let stableId = stableId else { - parentController.present(deviceContactInfoController(context: context, subject: .create(peer: peer, contactData: contactData, isSharing: false, shareViaException: false, completion: { peer, stableId, contactData in - + parentController.present(deviceContactInfoController(context: context, subject: .create(peer: peer?._asPeer(), contactData: contactData, isSharing: false, shareViaException: false, completion: { peer, stableId, contactData in }), completed: nil, cancelled: nil), in: .window(.root)) return } @@ -1440,7 +1440,7 @@ private func addContactToExisting(context: AccountContext, parentController: Vie } } } - completion(foundPeer?._asPeer(), stableId, contactData) + completion(foundPeer, stableId, contactData) }) }) } @@ -1449,7 +1449,7 @@ private func addContactToExisting(context: AccountContext, parentController: Vie }) } -func addContactOptionsController(context: AccountContext, peer: Peer?, contactData: DeviceContactExtendedData) -> ActionSheetController { +func addContactOptionsController(context: AccountContext, peer: EnginePeer?, contactData: DeviceContactExtendedData) -> ActionSheetController { let presentationData = context.sharedContext.currentPresentationData.with { $0 } let controller = ActionSheetController(presentationData: presentationData) let dismissAction: () -> Void = { [weak controller] in @@ -1459,7 +1459,7 @@ func addContactOptionsController(context: AccountContext, peer: Peer?, contactDa controller.setItemGroups([ ActionSheetItemGroup(items: [ ActionSheetButtonItem(title: presentationData.strings.Profile_CreateNewContact, action: { [weak controller] in - controller?.present(context.sharedContext.makeDeviceContactInfoController(context: context, subject: .create(peer: peer, contactData: contactData, isSharing: peer != nil, shareViaException: false, completion: { _, _, _ in + controller?.present(context.sharedContext.makeDeviceContactInfoController(context: context, subject: .create(peer: peer?._asPeer(), contactData: contactData, isSharing: peer != nil, shareViaException: false, completion: { _, _, _ in }), completed: nil, cancelled: nil), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) dismissAction() }), @@ -1468,7 +1468,6 @@ func addContactOptionsController(context: AccountContext, peer: Peer?, contactDa return } addContactToExisting(context: context, parentController: controller, contactData: contactData, completion: { peer, contactId, contactData in - }) dismissAction() }) diff --git a/submodules/PeerInfoUI/Sources/GroupInfoSearchItem.swift b/submodules/PeerInfoUI/Sources/GroupInfoSearchItem.swift index 66fcbf2133..020bb7bda2 100644 --- a/submodules/PeerInfoUI/Sources/GroupInfoSearchItem.swift +++ b/submodules/PeerInfoUI/Sources/GroupInfoSearchItem.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import AsyncDisplayKit -import Postbox import TelegramCore import SwiftSignalKit import ItemListUI @@ -11,10 +10,10 @@ import AccountContext final class ChannelMembersSearchItem: ItemListControllerSearch { let context: AccountContext - let peerId: PeerId + let peerId: EnginePeer.Id let searchContext: GroupMembersSearchContext? let cancel: () -> Void - let openPeer: (Peer, RenderedChannelParticipant?) -> Void + let openPeer: (EnginePeer, RenderedChannelParticipant?) -> Void let pushController: (ViewController) -> Void let dismissInput: () -> Void let searchMode: ChannelMembersSearchMode @@ -23,7 +22,7 @@ final class ChannelMembersSearchItem: ItemListControllerSearch { private var activity: ValuePromise = ValuePromise(ignoreRepeated: false) private let activityDisposable = MetaDisposable() - init(context: AccountContext, peerId: PeerId, searchContext: GroupMembersSearchContext?, searchMode: ChannelMembersSearchMode = .searchMembers, cancel: @escaping () -> Void, openPeer: @escaping (Peer, RenderedChannelParticipant?) -> Void, pushController: @escaping (ViewController) -> Void, dismissInput: @escaping () -> Void) { + init(context: AccountContext, peerId: EnginePeer.Id, searchContext: GroupMembersSearchContext?, searchMode: ChannelMembersSearchMode = .searchMembers, cancel: @escaping () -> Void, openPeer: @escaping (EnginePeer, RenderedChannelParticipant?) -> Void, pushController: @escaping (ViewController) -> Void, dismissInput: @escaping () -> Void) { self.context = context self.peerId = peerId self.searchContext = searchContext @@ -85,7 +84,7 @@ final class ChannelMembersSearchItem: ItemListControllerSearch { private final class ChannelMembersSearchItemNode: ItemListControllerSearchNode { private let containerNode: ChannelMembersSearchContainerNode - init(context: AccountContext, peerId: PeerId, searchMode: ChannelMembersSearchMode, searchContext: GroupMembersSearchContext?, openPeer: @escaping (Peer, RenderedChannelParticipant?) -> Void, cancel: @escaping () -> Void, updateActivity: @escaping(Bool) -> Void, pushController: @escaping (ViewController) -> Void, dismissInput: @escaping () -> Void) { + init(context: AccountContext, peerId: EnginePeer.Id, searchMode: ChannelMembersSearchMode, searchContext: GroupMembersSearchContext?, openPeer: @escaping (EnginePeer, RenderedChannelParticipant?) -> Void, cancel: @escaping () -> Void, updateActivity: @escaping(Bool) -> Void, pushController: @escaping (ViewController) -> Void, dismissInput: @escaping () -> Void) { self.containerNode = ChannelMembersSearchContainerNode(context: context, forceTheme: nil, peerId: peerId, mode: searchMode, filters: [], searchContext: searchContext, openPeer: { peer, participant in openPeer(peer, participant) }, updateActivity: updateActivity, pushController: pushController) diff --git a/submodules/PeerInfoUI/Sources/OldChannelsController.swift b/submodules/PeerInfoUI/Sources/OldChannelsController.swift index 1ed188000e..1dc627c391 100644 --- a/submodules/PeerInfoUI/Sources/OldChannelsController.swift +++ b/submodules/PeerInfoUI/Sources/OldChannelsController.swift @@ -3,7 +3,6 @@ import UIKit import Display import AsyncDisplayKit import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import ItemListUI @@ -61,11 +60,11 @@ func localizedOldChannelDate(peer: InactiveChannel, strings: PresentationStrings private final class OldChannelsItemArguments { let context: AccountContext - let togglePeer: (PeerId, Bool) -> Void + let togglePeer: (EnginePeer.Id, Bool) -> Void init( context: AccountContext, - togglePeer: @escaping (PeerId, Bool) -> Void + togglePeer: @escaping (EnginePeer.Id, Bool) -> Void ) { self.context = context self.togglePeer = togglePeer @@ -80,7 +79,7 @@ private enum OldChannelsSection: Int32 { private enum OldChannelsEntryId: Hashable { case info case peersHeader - case peer(PeerId) + case peer(EnginePeer.Id) } private enum OldChannelsEntry: ItemListNodeEntry { @@ -181,7 +180,7 @@ private enum OldChannelsEntry: ItemListNodeEntry { } private struct OldChannelsState: Equatable { - var selectedPeers: Set = Set() + var selectedPeers: Set = Set() var isSearching: Bool = false } @@ -255,7 +254,7 @@ public func oldChannelsController(context: AccountContext, updatedPresentationDa var pushImpl: ((ViewController) -> Void)? var setDisplayNavigationBarImpl: ((Bool) -> Void)? - var ensurePeerVisibleImpl: ((PeerId) -> Void)? + var ensurePeerVisibleImpl: ((EnginePeer.Id) -> Void)? var leaveActionImpl: (() -> Void)? diff --git a/submodules/PeerInfoUI/Sources/OldChannelsSearch.swift b/submodules/PeerInfoUI/Sources/OldChannelsSearch.swift index 903b05bc1a..cb679ae79e 100644 --- a/submodules/PeerInfoUI/Sources/OldChannelsSearch.swift +++ b/submodules/PeerInfoUI/Sources/OldChannelsSearch.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import AsyncDisplayKit -import Postbox import TelegramCore import SwiftSignalKit import TelegramPresentationData @@ -33,14 +32,14 @@ final class OldChannelsSearchItem: ItemListControllerSearch { let activated: Bool let updateActivated: (Bool) -> Void let peers: Signal<[InactiveChannel], NoError> - let selectedPeerIds: Signal, NoError> - let togglePeer: (PeerId) -> Void + let selectedPeerIds: Signal, NoError> + let togglePeer: (EnginePeer.Id) -> Void private var updateActivity: ((Bool) -> Void)? private var activity: ValuePromise = ValuePromise(ignoreRepeated: false) private let activityDisposable = MetaDisposable() - init(context: AccountContext, theme: PresentationTheme, placeholder: String, activated: Bool, updateActivated: @escaping (Bool) -> Void, peers: Signal<[InactiveChannel], NoError>, selectedPeerIds: Signal, NoError>, togglePeer: @escaping (PeerId) -> Void) { + init(context: AccountContext, theme: PresentationTheme, placeholder: String, activated: Bool, updateActivated: @escaping (Bool) -> Void, peers: Signal<[InactiveChannel], NoError>, selectedPeerIds: Signal, NoError>, togglePeer: @escaping (EnginePeer.Id) -> Void) { self.context = context self.theme = theme self.placeholder = placeholder @@ -101,9 +100,9 @@ final class OldChannelsSearchItem: ItemListControllerSearch { } private final class OldChannelsSearchInteraction { - let togglePeer: (PeerId) -> Void + let togglePeer: (EnginePeer.Id) -> Void - init(togglePeer: @escaping (PeerId) -> Void) { + init(togglePeer: @escaping (EnginePeer.Id) -> Void) { self.togglePeer = togglePeer } } @@ -111,7 +110,7 @@ private final class OldChannelsSearchInteraction { private enum OldChannelsSearchEntry: Comparable, Identifiable { case peer(Int, InactiveChannel, Bool) - var stableId: PeerId { + var stableId: EnginePeer.Id { switch self { case let .peer(_, peer, _): return peer.peer.id @@ -180,7 +179,7 @@ private final class OldChannelsSearchContainerNode: SearchDisplayControllerConte private var presentationDataDisposable: Disposable? private let presentationDataPromise: Promise - init(context: AccountContext, peers: Signal<[InactiveChannel], NoError>, selectedPeerIds: Signal, NoError>, togglePeer: @escaping (PeerId) -> Void) { + init(context: AccountContext, peers: Signal<[InactiveChannel], NoError>, selectedPeerIds: Signal, NoError>, togglePeer: @escaping (EnginePeer.Id) -> Void) { let presentationData = context.sharedContext.currentPresentationData.with { $0 } self.presentationData = presentationData self.presentationDataPromise = Promise(self.presentationData) @@ -352,10 +351,10 @@ private final class OldChannelsSearchItemNode: ItemListControllerSearchNode { var cancel: () -> Void private let peers: Signal<[InactiveChannel], NoError> - private let selectedPeerIds: Signal, NoError> - private let togglePeer: (PeerId) -> Void + private let selectedPeerIds: Signal, NoError> + private let togglePeer: (EnginePeer.Id) -> Void - init(context: AccountContext, cancel: @escaping () -> Void, peers: Signal<[InactiveChannel], NoError>, selectedPeerIds: Signal, NoError>, togglePeer: @escaping (PeerId) -> Void) { + init(context: AccountContext, cancel: @escaping () -> Void, peers: Signal<[InactiveChannel], NoError>, selectedPeerIds: Signal, NoError>, togglePeer: @escaping (EnginePeer.Id) -> Void) { self.context = context self.presentationData = context.sharedContext.currentPresentationData.with { $0 } self.cancel = cancel diff --git a/submodules/PeerInfoUI/Sources/PeerReportController.swift b/submodules/PeerInfoUI/Sources/PeerReportController.swift index d26b4c00d8..3e77918bc5 100644 --- a/submodules/PeerInfoUI/Sources/PeerReportController.swift +++ b/submodules/PeerInfoUI/Sources/PeerReportController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import ItemListUI @@ -17,9 +16,9 @@ import TelegramPermissionsUI import Markdown public enum PeerReportSubject { - case peer(PeerId) - case messages([MessageId]) - case profilePhoto(PeerId, Int64) + case peer(EnginePeer.Id) + case messages([EngineMessage.Id]) + case profilePhoto(EnginePeer.Id, Int64) } public enum PeerReportOption { diff --git a/submodules/PeerInfoUI/Sources/SecretChatKeyController.swift b/submodules/PeerInfoUI/Sources/SecretChatKeyController.swift index 120e211973..ebafd19083 100644 --- a/submodules/PeerInfoUI/Sources/SecretChatKeyController.swift +++ b/submodules/PeerInfoUI/Sources/SecretChatKeyController.swift @@ -3,7 +3,6 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore -import Postbox import TelegramPresentationData import AccountContext @@ -14,11 +13,11 @@ public final class SecretChatKeyController: ViewController { private let context: AccountContext private let fingerprint: SecretChatKeyFingerprint - private let peer: Peer + private let peer: EnginePeer private var presentationData: PresentationData - public init(context: AccountContext, fingerprint: SecretChatKeyFingerprint, peer: Peer) { + public init(context: AccountContext, fingerprint: SecretChatKeyFingerprint, peer: EnginePeer) { self.context = context self.fingerprint = fingerprint self.peer = peer diff --git a/submodules/PeerInfoUI/Sources/SecretChatKeyControllerNode.swift b/submodules/PeerInfoUI/Sources/SecretChatKeyControllerNode.swift index ac7cb5d653..985a4bf850 100644 --- a/submodules/PeerInfoUI/Sources/SecretChatKeyControllerNode.swift +++ b/submodules/PeerInfoUI/Sources/SecretChatKeyControllerNode.swift @@ -3,7 +3,6 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore -import Postbox import TelegramPresentationData import TextFormat import AccountContext @@ -30,7 +29,7 @@ final class SecretChatKeyControllerNode: ViewControllerTracingNode { private let context: AccountContext private var presentationData: PresentationData private let fingerprint: SecretChatKeyFingerprint - private let peer: Peer + private let peer: EnginePeer private let getNavigationController: () -> NavigationController? private let scrollNode: ASScrollNode @@ -40,7 +39,7 @@ final class SecretChatKeyControllerNode: ViewControllerTracingNode { private var validImageSize: CGSize? - init(context: AccountContext, presentationData: PresentationData, fingerprint: SecretChatKeyFingerprint, peer: Peer, getNavigationController: @escaping () -> NavigationController?) { + init(context: AccountContext, presentationData: PresentationData, fingerprint: SecretChatKeyFingerprint, peer: EnginePeer, getNavigationController: @escaping () -> NavigationController?) { self.context = context self.presentationData = presentationData self.fingerprint = fingerprint @@ -118,7 +117,7 @@ final class SecretChatKeyControllerNode: ViewControllerTracingNode { let (keyTextLayout, keyTextApply) = makeKeyTextLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: text, font: Font.semiboldMonospace(15.0), textColor: self.presentationData.theme.list.itemPrimaryTextColor), backgroundColor: nil, maximumNumberOfLines: 0, truncationType: .end, constrainedSize: CGSize(width: layout.size.width - sideInset * 2.0, height: CGFloat.greatestFiniteMagnitude), alignment: .left, lineSpacing: 0.0, cutout: nil, insets: UIEdgeInsets())) - let infoString = self.presentationData.strings.EncryptionKey_Description(EnginePeer(self.peer).compactDisplayTitle, EnginePeer(self.peer).compactDisplayTitle) + let infoString = self.presentationData.strings.EncryptionKey_Description(self.peer.compactDisplayTitle, self.peer.compactDisplayTitle) let infoText = NSMutableAttributedString(string: infoString.string, attributes: [.font: Font.regular(14.0), .foregroundColor: self.presentationData.theme.list.itemPrimaryTextColor]) for range in infoString.ranges { diff --git a/submodules/PeerInfoUI/Sources/UserInfoController.swift b/submodules/PeerInfoUI/Sources/UserInfoController.swift index 3ecf99828c..5204d23782 100644 --- a/submodules/PeerInfoUI/Sources/UserInfoController.swift +++ b/submodules/PeerInfoUI/Sources/UserInfoController.swift @@ -3,7 +3,6 @@ import UIKit import AsyncDisplayKit import Display import SwiftSignalKit -import Postbox import TelegramCore import LegacyComponents import TelegramPresentationData diff --git a/submodules/SettingsUI/Sources/CachedFaqInstantPage.swift b/submodules/SettingsUI/Sources/CachedFaqInstantPage.swift index 58f145fd42..6c80171197 100644 --- a/submodules/SettingsUI/Sources/CachedFaqInstantPage.swift +++ b/submodules/SettingsUI/Sources/CachedFaqInstantPage.swift @@ -1,6 +1,5 @@ import Foundation import SwiftSignalKit -import Postbox import TelegramCore import AccountContext import InstantPageUI diff --git a/submodules/SettingsUI/Sources/Data and Storage/ShareProxyServerActionSheetController.swift b/submodules/SettingsUI/Sources/Data and Storage/ShareProxyServerActionSheetController.swift index 322a22c1f6..56251e3eb4 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/ShareProxyServerActionSheetController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/ShareProxyServerActionSheetController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import TelegramCore -import Postbox import AsyncDisplayKit import UIKit import SwiftSignalKit diff --git a/submodules/SettingsUI/Sources/DeleteAccountDataController.swift b/submodules/SettingsUI/Sources/DeleteAccountDataController.swift index 7b2934724c..efa45cab1c 100644 --- a/submodules/SettingsUI/Sources/DeleteAccountDataController.swift +++ b/submodules/SettingsUI/Sources/DeleteAccountDataController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import LegacyComponents import TelegramPresentationData @@ -283,10 +282,7 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat return peers } - preloadedGroupPeers.set(context.engine.peers.adminedPublicChannels(scope: .all) - |> map { peers -> [EnginePeer] in - return peers.map { EnginePeer($0) } - }) + preloadedGroupPeers.set(context.engine.peers.adminedPublicChannels(scope: .all)) case let .groups(preloadedPeers): peers = .single(preloadedPeers.shuffled()) default: diff --git a/submodules/SettingsUI/Sources/DeleteAccountOptionsController.swift b/submodules/SettingsUI/Sources/DeleteAccountOptionsController.swift index 5422f7abe9..67f73ad248 100644 --- a/submodules/SettingsUI/Sources/DeleteAccountOptionsController.swift +++ b/submodules/SettingsUI/Sources/DeleteAccountOptionsController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import LegacyComponents import TelegramPresentationData @@ -322,7 +321,7 @@ public func deleteAccountOptionsController(context: AccountContext, navigationCo let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let supportPeer = Promise() + let supportPeer = Promise() supportPeer.set(context.engine.peers.supportPeerId()) var faqUrl = presentationData.strings.Settings_FAQ_URL diff --git a/submodules/SettingsUI/Sources/LogoutOptionsController.swift b/submodules/SettingsUI/Sources/LogoutOptionsController.swift index d6750a91a0..b217e08261 100644 --- a/submodules/SettingsUI/Sources/LogoutOptionsController.swift +++ b/submodules/SettingsUI/Sources/LogoutOptionsController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import LegacyComponents import TelegramPresentationData @@ -193,7 +192,7 @@ public func logoutOptionsController(context: AccountContext, navigationControlle pushControllerImpl?(introController) dismissImpl?() }, contactSupport: { [weak navigationController] in - let supportPeer = Promise() + let supportPeer = Promise() supportPeer.set(context.engine.peers.supportPeerId()) let presentationData = context.sharedContext.currentPresentationData.with { $0 } diff --git a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift index 6d109338d2..c474bb262f 100644 --- a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift +++ b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import AsyncDisplayKit -import Postbox import TelegramCore import SwiftSignalKit import TelegramPresentationData @@ -20,14 +19,15 @@ import ChatListUI import ItemListPeerActionItem import TelegramStringFormatting import NotificationPeerExceptionController +import Postbox private final class NotificationExceptionState : Equatable { let mode: NotificationExceptionMode let isSearchMode: Bool - let revealedPeerId: PeerId? + let revealedPeerId: EnginePeer.Id? let editing: Bool - init(mode: NotificationExceptionMode, isSearchMode: Bool = false, revealedPeerId: PeerId? = nil, editing: Bool = false) { + init(mode: NotificationExceptionMode, isSearchMode: Bool = false, revealedPeerId: EnginePeer.Id? = nil, editing: Bool = false) { self.mode = mode self.isSearchMode = isSearchMode self.revealedPeerId = revealedPeerId @@ -46,19 +46,19 @@ private final class NotificationExceptionState : Equatable { return NotificationExceptionState(mode: self.mode, isSearchMode: self.isSearchMode, revealedPeerId: self.revealedPeerId, editing: editing) } - func withUpdatedRevealedPeerId(_ revealedPeerId: PeerId?) -> NotificationExceptionState { + func withUpdatedRevealedPeerId(_ revealedPeerId: EnginePeer.Id?) -> NotificationExceptionState { return NotificationExceptionState(mode: self.mode, isSearchMode: self.isSearchMode, revealedPeerId: revealedPeerId, editing: self.editing) } - func withUpdatedPeerSound(_ peer: Peer, _ sound: PeerMessageSound) -> NotificationExceptionState { + func withUpdatedPeerSound(_ peer: EnginePeer, _ sound: PeerMessageSound) -> NotificationExceptionState { return NotificationExceptionState(mode: mode.withUpdatedPeerSound(peer, sound), isSearchMode: isSearchMode, revealedPeerId: self.revealedPeerId, editing: self.editing) } - func withUpdatedPeerMuteInterval(_ peer: Peer, _ muteInterval: Int32?) -> NotificationExceptionState { + func withUpdatedPeerMuteInterval(_ peer: EnginePeer, _ muteInterval: Int32?) -> NotificationExceptionState { return NotificationExceptionState(mode: mode.withUpdatedPeerMuteInterval(peer, muteInterval), isSearchMode: isSearchMode, revealedPeerId: self.revealedPeerId, editing: self.editing) } - func withUpdatedPeerDisplayPreviews(_ peer: Peer, _ displayPreviews: PeerNotificationDisplayPreviews) -> NotificationExceptionState { + func withUpdatedPeerDisplayPreviews(_ peer: EnginePeer, _ displayPreviews: PeerNotificationDisplayPreviews) -> NotificationExceptionState { return NotificationExceptionState(mode: mode.withUpdatedPeerDisplayPreviews(peer, displayPreviews), isSearchMode: isSearchMode, revealedPeerId: self.revealedPeerId, editing: self.editing) } @@ -67,25 +67,25 @@ private final class NotificationExceptionState : Equatable { } } -private func notificationsExceptionEntries(presentationData: PresentationData, notificationSoundList: NotificationSoundList?, state: NotificationExceptionState, query: String? = nil, foundPeers: [RenderedPeer] = []) -> [NotificationExceptionEntry] { +private func notificationsExceptionEntries(presentationData: PresentationData, notificationSoundList: NotificationSoundList?, state: NotificationExceptionState, query: String? = nil, foundPeers: [EngineRenderedPeer] = []) -> [NotificationExceptionEntry] { var entries: [NotificationExceptionEntry] = [] if !state.isSearchMode { entries.append(.addException(presentationData.theme, presentationData.strings, state.mode.mode, state.editing)) } - var existingPeerIds = Set() + var existingPeerIds = Set() var index: Int = 0 for (_, value) in state.mode.settings.filter({ (_, value) in if let query = query, !query.isEmpty { - return !EnginePeer(value.peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder).lowercased().components(separatedBy: " ").filter { $0.hasPrefix(query.lowercased())}.isEmpty + return !value.peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder).lowercased().components(separatedBy: " ").filter { $0.hasPrefix(query.lowercased())}.isEmpty } else { return true } }).sorted(by: { lhs, rhs in - let lhsName = EnginePeer(lhs.value.peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) - let rhsName = EnginePeer(rhs.value.peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) + let lhsName = lhs.value.peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) + let rhsName = rhs.value.peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) if let lhsDate = lhs.value.date, let rhsDate = rhs.value.date { return lhsDate > rhsDate @@ -95,7 +95,7 @@ private func notificationsExceptionEntries(presentationData: PresentationData, n return false } - if let lhsPeer = lhs.value.peer as? TelegramUser, let rhsPeer = rhs.value.peer as? TelegramUser { + if case let .user(lhsPeer) = lhs.value.peer, case let .user(rhsPeer) = rhs.value.peer { if lhsPeer.botInfo != nil && rhsPeer.botInfo == nil { return false } else if lhsPeer.botInfo == nil && rhsPeer.botInfo != nil { @@ -173,18 +173,18 @@ private func notificationsExceptionEntries(presentationData: PresentationData, n } switch state.mode { case .channels: - if let channel = peer as? TelegramChannel, case .broadcast = channel.info { + if case let .channel(channel) = peer, case .broadcast = channel.info { } else { continue } case .groups: - if let channel = peer as? TelegramChannel, case .broadcast = channel.info { - } else if peer is TelegramGroup { + if case let .channel(channel) = peer, case .broadcast = channel.info { + } else if case .legacyGroup = peer { } else { continue } case .users: - if peer is TelegramUser { + if case .user = peer { } else { continue } @@ -208,13 +208,13 @@ private func notificationsExceptionEntries(presentationData: PresentationData, n private final class NotificationExceptionArguments { let context: AccountContext let activateSearch:()->Void - let openPeer: (Peer) -> Void + let openPeer: (EnginePeer) -> Void let selectPeer: ()->Void - let updateRevealedPeerId:(PeerId?)->Void - let deletePeer:(Peer) -> Void + let updateRevealedPeerId: (EnginePeer.Id?)->Void + let deletePeer:(EnginePeer) -> Void let removeAll:() -> Void - init(context: AccountContext, activateSearch:@escaping() -> Void, openPeer: @escaping(Peer) -> Void, selectPeer: @escaping()->Void, updateRevealedPeerId:@escaping(PeerId?)->Void, deletePeer: @escaping(Peer) -> Void, removeAll:@escaping() -> Void) { + init(context: AccountContext, activateSearch:@escaping () -> Void, openPeer: @escaping (EnginePeer) -> Void, selectPeer: @escaping()->Void, updateRevealedPeerId:@escaping (EnginePeer.Id?)->Void, deletePeer: @escaping (EnginePeer) -> Void, removeAll:@escaping() -> Void) { self.context = context self.activateSearch = activateSearch self.openPeer = openPeer @@ -286,8 +286,8 @@ private enum NotificationExceptionEntry : ItemListNodeEntry { typealias ItemGenerationArguments = NotificationExceptionArguments case search(PresentationTheme, PresentationStrings) - case peer(index: Int, peer: Peer, theme: PresentationTheme, strings: PresentationStrings, dateFormat: PresentationDateTimeFormat, nameDisplayOrder: PresentationPersonNameOrder, description: String, notificationSettings: TelegramPeerNotificationSettings, revealed: Bool, editing: Bool, isSearching: Bool) - case addPeer(index: Int, peer: Peer, theme: PresentationTheme, strings: PresentationStrings, dateFormat: PresentationDateTimeFormat, nameDisplayOrder: PresentationPersonNameOrder) + case peer(index: Int, peer: EnginePeer, theme: PresentationTheme, strings: PresentationStrings, dateFormat: PresentationDateTimeFormat, nameDisplayOrder: PresentationPersonNameOrder, description: String, notificationSettings: TelegramPeerNotificationSettings, revealed: Bool, editing: Bool, isSearching: Bool) + case addPeer(index: Int, peer: EnginePeer, theme: PresentationTheme, strings: PresentationStrings, dateFormat: PresentationDateTimeFormat, nameDisplayOrder: PresentationPersonNameOrder) case addException(PresentationTheme, PresentationStrings, NotificationExceptionMode.Mode, Bool) case removeAll(PresentationTheme, PresentationStrings) @@ -312,7 +312,7 @@ private enum NotificationExceptionEntry : ItemListNodeEntry { arguments.selectPeer() }) case let .peer(_, peer, _, _, dateTimeFormat, nameDisplayOrder, value, _, revealed, editing, isSearching): - return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, context: arguments.context, peer: EnginePeer(peer), presence: nil, text: .text(value, .secondary), label: .none, editing: ItemListPeerItemEditing(editable: true, editing: editing, revealed: revealed), switchValue: nil, enabled: true, selectable: true, sectionId: self.section, action: { + return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, context: arguments.context, peer: peer, presence: nil, text: .text(value, .secondary), label: .none, editing: ItemListPeerItemEditing(editable: true, editing: editing, revealed: revealed), switchValue: nil, enabled: true, selectable: true, sectionId: self.section, action: { arguments.openPeer(peer) }, setPeerIdWithRevealedOptions: { peerId, fromPeerId in arguments.updateRevealedPeerId(peerId) @@ -320,7 +320,7 @@ private enum NotificationExceptionEntry : ItemListNodeEntry { arguments.deletePeer(peer) }, hasTopStripe: false, hasTopGroupInset: false, noInsets: isSearching) case let .addPeer(_, peer, theme, strings, _, nameDisplayOrder): - return ContactsPeerItem(presentationData: presentationData, sortOrder: nameDisplayOrder, displayOrder: nameDisplayOrder, context: arguments.context, peerMode: .peer, peer: .peer(peer: EnginePeer(peer), chatPeer: EnginePeer(peer)), status: .none, enabled: true, selection: .none, editing: ContactsPeerItemEditing(editable: false, editing: false, revealed: false), options: [], actionIcon: .add, index: nil, header: ChatListSearchItemHeader(type: .addToExceptions, theme: theme, strings: strings, actionTitle: nil, action: nil), action: { _ in + return ContactsPeerItem(presentationData: presentationData, sortOrder: nameDisplayOrder, displayOrder: nameDisplayOrder, context: arguments.context, peerMode: .peer, peer: .peer(peer: peer, chatPeer: peer), status: .none, enabled: true, selection: .none, editing: ContactsPeerItemEditing(editable: false, editing: false, revealed: false), options: [], actionIcon: .add, index: nil, header: ChatListSearchItemHeader(type: .addToExceptions, theme: theme, strings: strings, actionTitle: nil, action: nil), action: { _ in arguments.openPeer(peer) }, setPeerIdWithRevealedOptions: { _, _ in }) @@ -365,14 +365,14 @@ private enum NotificationExceptionEntry : ItemListNodeEntry { case let .peer(lhsIndex, lhsPeer, lhsTheme, lhsStrings, lhsDateTimeFormat, lhsNameOrder, lhsValue, lhsSettings, lhsRevealed, lhsEditing, lhsIsSearching): switch rhs { case let .peer(rhsIndex, rhsPeer, rhsTheme, rhsStrings, rhsDateTimeFormat, rhsNameOrder, rhsValue, rhsSettings, rhsRevealed, rhsEditing, rhsIsSearching): - return lhsTheme === rhsTheme && lhsStrings === rhsStrings && lhsDateTimeFormat == rhsDateTimeFormat && lhsNameOrder == rhsNameOrder && lhsIndex == rhsIndex && lhsPeer.isEqual(rhsPeer) && lhsValue == rhsValue && lhsSettings == rhsSettings && lhsRevealed == rhsRevealed && lhsEditing == rhsEditing && lhsIsSearching == rhsIsSearching + return lhsTheme === rhsTheme && lhsStrings === rhsStrings && lhsDateTimeFormat == rhsDateTimeFormat && lhsNameOrder == rhsNameOrder && lhsIndex == rhsIndex && lhsPeer == rhsPeer && lhsValue == rhsValue && lhsSettings == rhsSettings && lhsRevealed == rhsRevealed && lhsEditing == rhsEditing && lhsIsSearching == rhsIsSearching default: return false } case let .addPeer(lhsIndex, lhsPeer, lhsTheme, lhsStrings, lhsDateTimeFormat, lhsNameOrder): switch rhs { case let .addPeer(rhsIndex, rhsPeer, rhsTheme, rhsStrings, rhsDateTimeFormat, rhsNameOrder): - return lhsTheme === rhsTheme && lhsStrings === rhsStrings && lhsDateTimeFormat == rhsDateTimeFormat && lhsNameOrder == rhsNameOrder && lhsIndex == rhsIndex && lhsPeer.isEqual(rhsPeer) + return lhsTheme === rhsTheme && lhsStrings === rhsStrings && lhsDateTimeFormat == rhsDateTimeFormat && lhsNameOrder == rhsNameOrder && lhsIndex == rhsIndex && lhsPeer == rhsPeer default: return false } @@ -515,7 +515,7 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { } let updateNotificationsDisposable = self.updateNotificationsDisposable - var peerIds: Set = Set(mode.peerIds) + var peerIds: Set = Set(mode.peerIds) let updateNotificationsView: (@escaping () -> Void) -> Void = { completion in updateState { current in @@ -534,12 +534,12 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { for (key, value) in notificationSettingsMap { if let local = current.mode.settings[key] { if !value._asNotificationSettings().isEqual(to: local.settings), let maybePeer = peerMap[key], let peer = maybePeer, let settings = notificationSettingsMap[key], !settings._asNotificationSettings().isEqual(to: local.settings) { - current = current.withUpdatedPeerSound(peer._asPeer(), settings.messageSound._asMessageSound()).withUpdatedPeerMuteInterval(peer._asPeer(), settings.muteState.timeInterval).withUpdatedPeerDisplayPreviews(peer._asPeer(), settings.displayPreviews._asDisplayPreviews()) + current = current.withUpdatedPeerSound(peer, settings.messageSound._asMessageSound()).withUpdatedPeerMuteInterval(peer, settings.muteState.timeInterval).withUpdatedPeerDisplayPreviews(peer, settings.displayPreviews._asDisplayPreviews()) } } else if let maybePeer = peerMap[key], let peer = maybePeer { if case .default = value.messageSound, case .unmuted = value.muteState, case .default = value.displayPreviews { } else { - current = current.withUpdatedPeerSound(peer._asPeer(), value.messageSound._asMessageSound()).withUpdatedPeerMuteInterval(peer._asPeer(), value.muteState.timeInterval).withUpdatedPeerDisplayPreviews(peer._asPeer(), value.displayPreviews._asDisplayPreviews()) + current = current.withUpdatedPeerSound(peer, value.messageSound._asMessageSound()).withUpdatedPeerMuteInterval(peer, value.muteState.timeInterval).withUpdatedPeerDisplayPreviews(peer, value.displayPreviews._asDisplayPreviews()) } } } @@ -560,15 +560,15 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { let presentationData = context.sharedContext.currentPresentationData.modify {$0} - let updatePeerSound: (PeerId, PeerMessageSound) -> Signal = { peerId, sound in + let updatePeerSound: (EnginePeer.Id, PeerMessageSound) -> Signal = { peerId, sound in return context.engine.peers.updatePeerNotificationSoundInteractive(peerId: peerId, threadId: nil, sound: sound) |> deliverOnMainQueue } - let updatePeerNotificationInterval: (PeerId, Int32?) -> Signal = { peerId, muteInterval in + let updatePeerNotificationInterval: (EnginePeer.Id, Int32?) -> Signal = { peerId, muteInterval in return context.engine.peers.updatePeerMuteSetting(peerId: peerId, threadId: nil, muteInterval: muteInterval) |> deliverOnMainQueue } - let updatePeerDisplayPreviews:(PeerId, PeerNotificationDisplayPreviews) -> Signal = { + let updatePeerDisplayPreviews:(EnginePeer.Id, PeerNotificationDisplayPreviews) -> Signal = { peerId, displayPreviews in return context.engine.peers.updatePeerDisplayPreviewsSetting(peerId: peerId, threadId: nil, displayPreviews: displayPreviews) |> deliverOnMainQueue } @@ -580,7 +580,7 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { requestActivateSearch() } - let presentPeerSettings: (PeerId, @escaping () -> Void) -> Void = { [weak self] peerId, completion in + let presentPeerSettings: (EnginePeer.Id, @escaping () -> Void) -> Void = { [weak self] peerId, completion in (self?.searchDisplayController?.contentNode as? NotificationExceptionsSearchContainerNode)?.listNode.clearHighlightAnimated(true) let _ = (context.engine.data.get( @@ -610,13 +610,13 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { defaultSound = globalSettings.privateChats.sound._asMessageSound() } - presentControllerImpl?(notificationPeerExceptionController(context: context, peer: peer._asPeer(), threadId: nil, canRemove: canRemove, defaultSound: defaultSound, updatePeerSound: { peerId, sound in + presentControllerImpl?(notificationPeerExceptionController(context: context, peer: peer, threadId: nil, canRemove: canRemove, defaultSound: defaultSound, updatePeerSound: { peerId, sound in _ = updatePeerSound(peer.id, sound).start(next: { _ in updateNotificationsDisposable.set(nil) _ = combineLatest(updatePeerSound(peer.id, sound), context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) |> deliverOnMainQueue).start(next: { _, peer in if let peer = peer { updateState { value in - return value.withUpdatedPeerSound(peer._asPeer(), sound) + return value.withUpdatedPeerSound(peer, sound) } } updateNotificationsView({}) @@ -627,7 +627,7 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { _ = combineLatest(updatePeerNotificationInterval(peerId, muteInterval), context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) |> deliverOnMainQueue).start(next: { _, peer in if let peer = peer { updateState { value in - return value.withUpdatedPeerMuteInterval(peer._asPeer(), muteInterval) + return value.withUpdatedPeerMuteInterval(peer, muteInterval) } } updateNotificationsView({}) @@ -637,7 +637,7 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { _ = combineLatest(updatePeerDisplayPreviews(peerId, displayPreviews), context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) |> deliverOnMainQueue).start(next: { _, peer in if let peer = peer { updateState { value in - return value.withUpdatedPeerDisplayPreviews(peer._asPeer(), displayPreviews) + return value.withUpdatedPeerDisplayPreviews(peer, displayPreviews) } } updateNotificationsView({}) @@ -652,7 +652,7 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { return } updateState { value in - return value.withUpdatedPeerDisplayPreviews(peer._asPeer(), .default).withUpdatedPeerSound(peer._asPeer(), .default).withUpdatedPeerMuteInterval(peer._asPeer(), nil) + return value.withUpdatedPeerDisplayPreviews(peer, .default).withUpdatedPeerSound(peer, .default).withUpdatedPeerMuteInterval(peer, nil) } updateNotificationsView({}) }) @@ -693,7 +693,7 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { return current.withUpdatedRevealedPeerId(peerId) } }, deletePeer: { peer in - let _ = (context.engine.peers.ensurePeersAreLocallyAvailable(peers: [EnginePeer(peer)]) + let _ = (context.engine.peers.ensurePeersAreLocallyAvailable(peers: [peer]) |> deliverOnMainQueue).start(completed: { updateNotificationsDisposable.set(nil) updateState { value in @@ -713,7 +713,7 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { actionSheet?.dismissAnimated() let values = stateValue.with { $0.mode.settings.values } - let _ = (context.engine.peers.ensurePeersAreLocallyAvailable(peers: values.map { EnginePeer($0.peer) }) + let _ = (context.engine.peers.ensurePeersAreLocallyAvailable(peers: values.map { $0.peer }) |> deliverOnMainQueue).start(completed: { updateNotificationsDisposable.set(nil) updateState { state in @@ -979,7 +979,7 @@ private final class NotificationExceptionsSearchContainerNode: SearchDisplayCont for (key, value) in notificationSettingsMap { if let local = current.mode.settings[key] { if !value._asNotificationSettings().isEqual(to: local.settings), let maybePeer = peerMap[key], let peer = maybePeer, let settings = notificationSettingsMap[key], !settings._asNotificationSettings().isEqual(to: local.settings) { - current = current.withUpdatedPeerSound(peer._asPeer(), settings.messageSound._asMessageSound()).withUpdatedPeerMuteInterval(peer._asPeer(), settings.muteState.timeInterval) + current = current.withUpdatedPeerSound(peer, settings.messageSound._asMessageSound()).withUpdatedPeerMuteInterval(peer, settings.muteState.timeInterval) } } } @@ -1013,10 +1013,13 @@ private final class NotificationExceptionsSearchContainerNode: SearchDisplayCont |> distinctUntilChanged let searchSignal = stateQuery - |> mapToSignal { query -> Signal<(PresentationData, NotificationSoundList?, (NotificationExceptionState, String?), PreferencesView, [RenderedPeer]), NoError> in - var contactsSignal: Signal<[RenderedPeer], NoError> = .single([]) + |> mapToSignal { query -> Signal<(PresentationData, NotificationSoundList?, (NotificationExceptionState, String?), PreferencesView, [EngineRenderedPeer]), NoError> in + var contactsSignal: Signal<[EngineRenderedPeer], NoError> = .single([]) if let query = query { contactsSignal = context.account.postbox.searchPeers(query: query) + |> map { items -> [EngineRenderedPeer] in + return items.map(EngineRenderedPeer.init) + } } return combineLatest(context.sharedContext.presentationData, context.engine.peers.notificationSoundList(), stateAndPeers, preferences, contactsSignal) } diff --git a/submodules/SettingsUI/Sources/Notifications/NotificationsAndSoundsController.swift b/submodules/SettingsUI/Sources/Notifications/NotificationsAndSoundsController.swift index 934bd43a6d..2ad55a81a8 100644 --- a/submodules/SettingsUI/Sources/Notifications/NotificationsAndSoundsController.swift +++ b/submodules/SettingsUI/Sources/Notifications/NotificationsAndSoundsController.swift @@ -726,24 +726,24 @@ public func notificationsAndSoundsController(context: AccountContext, exceptions default: switch key.namespace { case Namespaces.Peer.CloudUser: - users[key] = NotificationExceptionWrapper(settings: value, peer: peer) + users[key] = NotificationExceptionWrapper(settings: value, peer: EnginePeer(peer)) default: if let peer = peer as? TelegramChannel, case .broadcast = peer.info { - channels[key] = NotificationExceptionWrapper(settings: value, peer: peer) + channels[key] = NotificationExceptionWrapper(settings: value, peer: .channel(peer)) } else { - groups[key] = NotificationExceptionWrapper(settings: value, peer: peer) + groups[key] = NotificationExceptionWrapper(settings: value, peer: EnginePeer(peer)) } } } default: switch key.namespace { case Namespaces.Peer.CloudUser: - users[key] = NotificationExceptionWrapper(settings: value, peer: peer) + users[key] = NotificationExceptionWrapper(settings: value, peer: EnginePeer(peer)) default: if let peer = peer as? TelegramChannel, case .broadcast = peer.info { - channels[key] = NotificationExceptionWrapper(settings: value, peer: peer) + channels[key] = NotificationExceptionWrapper(settings: value, peer: .channel(peer)) } else { - groups[key] = NotificationExceptionWrapper(settings: value, peer: peer) + groups[key] = NotificationExceptionWrapper(settings: value, peer: EnginePeer(peer)) } } } diff --git a/submodules/SettingsUI/Sources/NotificationsPeerCategoryController.swift b/submodules/SettingsUI/Sources/NotificationsPeerCategoryController.swift index bc5cf90044..ba2dc6aefc 100644 --- a/submodules/SettingsUI/Sources/NotificationsPeerCategoryController.swift +++ b/submodules/SettingsUI/Sources/NotificationsPeerCategoryController.swift @@ -3,7 +3,6 @@ import UIKit import Display import AsyncDisplayKit import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -43,14 +42,14 @@ private final class NotificationsPeerCategoryControllerArguments { let openSound: (PeerMessageSound) -> Void let addException: () -> Void - let openException: (Peer) -> Void + let openException: (EnginePeer) -> Void let removeAllExceptions: () -> Void - let updateRevealedPeerId: (PeerId?) -> Void - let removePeer: (Peer) -> Void + let updateRevealedPeerId: (EnginePeer.Id?) -> Void + let removePeer: (EnginePeer) -> Void let updatedExceptionMode: (NotificationExceptionMode) -> Void - init(context: AccountContext, soundSelectionDisposable: MetaDisposable, updateEnabled: @escaping (Bool) -> Void, updatePreviews: @escaping (Bool) -> Void, openSound: @escaping (PeerMessageSound) -> Void, addException: @escaping () -> Void, openException: @escaping (Peer) -> Void, removeAllExceptions: @escaping () -> Void, updateRevealedPeerId: @escaping (PeerId?) -> Void, removePeer: @escaping (Peer) -> Void, updatedExceptionMode: @escaping (NotificationExceptionMode) -> Void) { + init(context: AccountContext, soundSelectionDisposable: MetaDisposable, updateEnabled: @escaping (Bool) -> Void, updatePreviews: @escaping (Bool) -> Void, openSound: @escaping (PeerMessageSound) -> Void, addException: @escaping () -> Void, openException: @escaping (EnginePeer) -> Void, removeAllExceptions: @escaping () -> Void, updateRevealedPeerId: @escaping (EnginePeer.Id?) -> Void, removePeer: @escaping (EnginePeer) -> Void, updatedExceptionMode: @escaping (NotificationExceptionMode) -> Void) { self.context = context self.soundSelectionDisposable = soundSelectionDisposable @@ -97,7 +96,7 @@ private enum NotificationsPeerCategoryEntry: ItemListNodeEntry { case exceptionsHeader(PresentationTheme, String) case addException(PresentationTheme, String) - case exception(Int32, PresentationTheme, PresentationStrings, PresentationDateTimeFormat, PresentationPersonNameOrder, Peer, String, TelegramPeerNotificationSettings, Bool, Bool) + case exception(Int32, PresentationTheme, PresentationStrings, PresentationDateTimeFormat, PresentationPersonNameOrder, EnginePeer, String, TelegramPeerNotificationSettings, Bool, Bool) case removeAllExceptions(PresentationTheme, String) var section: ItemListSectionId { @@ -184,7 +183,7 @@ private enum NotificationsPeerCategoryEntry: ItemListNodeEntry { return false } case let .exception(lhsIndex, lhsTheme, lhsStrings, lhsDateTimeFormat, lhsDisplayNameOrder, lhsPeer, lhsDescription, lhsSettings, lhsEditing, lhsRevealed): - if case let .exception(rhsIndex, rhsTheme, rhsStrings, rhsDateTimeFormat, rhsDisplayNameOrder, rhsPeer, rhsDescription, rhsSettings, rhsEditing, rhsRevealed) = rhs, lhsIndex == rhsIndex, lhsTheme === rhsTheme, lhsStrings === rhsStrings, lhsDateTimeFormat == rhsDateTimeFormat, lhsDisplayNameOrder == rhsDisplayNameOrder, arePeersEqual(lhsPeer, rhsPeer), lhsDescription == rhsDescription, lhsSettings == rhsSettings, lhsEditing == rhsEditing, lhsRevealed == rhsRevealed { + if case let .exception(rhsIndex, rhsTheme, rhsStrings, rhsDateTimeFormat, rhsDisplayNameOrder, rhsPeer, rhsDescription, rhsSettings, rhsEditing, rhsRevealed) = rhs, lhsIndex == rhsIndex, lhsTheme === rhsTheme, lhsStrings === rhsStrings, lhsDateTimeFormat == rhsDateTimeFormat, lhsDisplayNameOrder == rhsDisplayNameOrder, lhsPeer == rhsPeer, lhsDescription == rhsDescription, lhsSettings == rhsSettings, lhsEditing == rhsEditing, lhsRevealed == rhsRevealed { return true } else { return false @@ -227,7 +226,7 @@ private enum NotificationsPeerCategoryEntry: ItemListNodeEntry { arguments.addException() }) case let .exception(_, _, _, dateTimeFormat, nameDisplayOrder, peer, description, _, editing, revealed): - return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, context: arguments.context, peer: EnginePeer(peer), presence: nil, text: .text(description, .secondary), label: .none, editing: ItemListPeerItemEditing(editable: true, editing: editing, revealed: revealed), switchValue: nil, enabled: true, selectable: true, sectionId: self.section, action: { + return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, context: arguments.context, peer: peer, presence: nil, text: .text(description, .secondary), label: .none, editing: ItemListPeerItemEditing(editable: true, editing: editing, revealed: revealed), switchValue: nil, enabled: true, selectable: true, sectionId: self.section, action: { arguments.openException(peer) }, setPeerIdWithRevealedOptions: { peerId, fromPeerId in arguments.updateRevealedPeerId(peerId) @@ -277,8 +276,8 @@ private func notificationsPeerCategoryEntries(category: NotificationsPeerCategor let sortedExceptions = notificationExceptions.settings.sorted(by: { lhs, rhs in - let lhsName = EnginePeer(lhs.value.peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) - let rhsName = EnginePeer(rhs.value.peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) + let lhsName = lhs.value.peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) + let rhsName = rhs.value.peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) if let lhsDate = lhs.value.date, let rhsDate = rhs.value.date { return lhsDate > rhsDate @@ -288,7 +287,7 @@ private func notificationsPeerCategoryEntries(category: NotificationsPeerCategor return false } - if let lhsPeer = lhs.value.peer as? TelegramUser, let rhsPeer = rhs.value.peer as? TelegramUser { + if case let .user(lhsPeer) = lhs.value.peer, case let .user(rhsPeer) = rhs.value.peer { if lhsPeer.botInfo != nil && rhsPeer.botInfo == nil { return false } else if lhsPeer.botInfo == nil && rhsPeer.botInfo != nil { @@ -299,7 +298,7 @@ private func notificationsPeerCategoryEntries(category: NotificationsPeerCategor return lhsName < rhsName }) - var existingPeerIds = Set() + var existingPeerIds = Set() var index: Int = 0 for (_, value) in sortedExceptions { @@ -379,10 +378,10 @@ public enum NotificationsPeerCategory { private final class NotificationExceptionState : Equatable { let mode: NotificationExceptionMode - let revealedPeerId: PeerId? + let revealedPeerId: EnginePeer.Id? let editing: Bool - init(mode: NotificationExceptionMode, revealedPeerId: PeerId? = nil, editing: Bool = false) { + init(mode: NotificationExceptionMode, revealedPeerId: EnginePeer.Id? = nil, editing: Bool = false) { self.mode = mode self.revealedPeerId = revealedPeerId self.editing = editing @@ -396,19 +395,19 @@ private final class NotificationExceptionState : Equatable { return NotificationExceptionState(mode: self.mode, revealedPeerId: self.revealedPeerId, editing: editing) } - func withUpdatedRevealedPeerId(_ revealedPeerId: PeerId?) -> NotificationExceptionState { + func withUpdatedRevealedPeerId(_ revealedPeerId: EnginePeer.Id?) -> NotificationExceptionState { return NotificationExceptionState(mode: self.mode, revealedPeerId: revealedPeerId, editing: self.editing) } - func withUpdatedPeerSound(_ peer: Peer, _ sound: PeerMessageSound) -> NotificationExceptionState { + func withUpdatedPeerSound(_ peer: EnginePeer, _ sound: PeerMessageSound) -> NotificationExceptionState { return NotificationExceptionState(mode: mode.withUpdatedPeerSound(peer, sound), revealedPeerId: self.revealedPeerId, editing: self.editing) } - func withUpdatedPeerMuteInterval(_ peer: Peer, _ muteInterval: Int32?) -> NotificationExceptionState { + func withUpdatedPeerMuteInterval(_ peer: EnginePeer, _ muteInterval: Int32?) -> NotificationExceptionState { return NotificationExceptionState(mode: mode.withUpdatedPeerMuteInterval(peer, muteInterval), revealedPeerId: self.revealedPeerId, editing: self.editing) } - func withUpdatedPeerDisplayPreviews(_ peer: Peer, _ displayPreviews: PeerNotificationDisplayPreviews) -> NotificationExceptionState { + func withUpdatedPeerDisplayPreviews(_ peer: EnginePeer, _ displayPreviews: PeerNotificationDisplayPreviews) -> NotificationExceptionState { return NotificationExceptionState(mode: mode.withUpdatedPeerDisplayPreviews(peer, displayPreviews), revealedPeerId: self.revealedPeerId, editing: self.editing) } @@ -438,20 +437,20 @@ public func notificationsPeerCategoryController(context: AccountContext, categor updatedMode(result.mode) } - let updatePeerSound: (PeerId, PeerMessageSound) -> Signal = { peerId, sound in + let updatePeerSound: (EnginePeer.Id, PeerMessageSound) -> Signal = { peerId, sound in return context.engine.peers.updatePeerNotificationSoundInteractive(peerId: peerId, threadId: nil, sound: sound) |> deliverOnMainQueue } - let updatePeerNotificationInterval: (PeerId, Int32?) -> Signal = { peerId, muteInterval in + let updatePeerNotificationInterval: (EnginePeer.Id, Int32?) -> Signal = { peerId, muteInterval in return context.engine.peers.updatePeerMuteSetting(peerId: peerId, threadId: nil, muteInterval: muteInterval) |> deliverOnMainQueue } - let updatePeerDisplayPreviews:(PeerId, PeerNotificationDisplayPreviews) -> Signal = { + let updatePeerDisplayPreviews:(EnginePeer.Id, PeerNotificationDisplayPreviews) -> Signal = { peerId, displayPreviews in return context.engine.peers.updatePeerDisplayPreviewsSetting(peerId: peerId, threadId: nil, displayPreviews: displayPreviews) |> deliverOnMainQueue } - var peerIds: Set = Set(mode.peerIds) + var peerIds: Set = Set(mode.peerIds) let updateNotificationsDisposable = MetaDisposable() let updateNotificationsView: (@escaping () -> Void) -> Void = { completion in updateState { current in @@ -472,12 +471,12 @@ public func notificationsPeerCategoryController(context: AccountContext, categor for (key, value) in combinedPeerNotificationSettings { if let local = current.mode.settings[key] { if !value._asNotificationSettings().isEqual(to: local.settings), let maybePeer = peerMap[key], let peer = maybePeer, let settings = notificationSettingsMap[key], !settings._asNotificationSettings().isEqual(to: local.settings) { - current = current.withUpdatedPeerSound(peer._asPeer(), settings.messageSound._asMessageSound()).withUpdatedPeerMuteInterval(peer._asPeer(), settings.muteState.timeInterval).withUpdatedPeerDisplayPreviews(peer._asPeer(), settings.displayPreviews._asDisplayPreviews()) + current = current.withUpdatedPeerSound(peer, settings.messageSound._asMessageSound()).withUpdatedPeerMuteInterval(peer, settings.muteState.timeInterval).withUpdatedPeerDisplayPreviews(peer, settings.displayPreviews._asDisplayPreviews()) } } else if let maybePeer = peerMap[key], let peer = maybePeer { if case .default = value.messageSound, case .unmuted = value.muteState, case .default = value.displayPreviews { } else { - current = current.withUpdatedPeerSound(peer._asPeer(), value.messageSound._asMessageSound()).withUpdatedPeerMuteInterval(peer._asPeer(), value.muteState.timeInterval).withUpdatedPeerDisplayPreviews(peer._asPeer(), value.displayPreviews._asDisplayPreviews()) + current = current.withUpdatedPeerSound(peer, value.messageSound._asMessageSound()).withUpdatedPeerMuteInterval(peer, value.muteState.timeInterval).withUpdatedPeerDisplayPreviews(peer, value.displayPreviews._asDisplayPreviews()) } } } @@ -493,7 +492,7 @@ public func notificationsPeerCategoryController(context: AccountContext, categor updateNotificationsView({}) - let presentPeerSettings: (PeerId, @escaping () -> Void) -> Void = { peerId, completion in + let presentPeerSettings: (EnginePeer.Id, @escaping () -> Void) -> Void = { peerId, completion in let _ = (context.engine.data.get( TelegramEngine.EngineData.Item.Peer.Peer(id: peerId), TelegramEngine.EngineData.Item.NotificationSettings.Global() @@ -519,13 +518,13 @@ public func notificationsPeerCategoryController(context: AccountContext, categor defaultSound = globalSettings.privateChats.sound._asMessageSound() } - pushControllerImpl?(notificationPeerExceptionController(context: context, peer: peer._asPeer(), threadId: nil, canRemove: canRemove, defaultSound: defaultSound, updatePeerSound: { peerId, sound in + pushControllerImpl?(notificationPeerExceptionController(context: context, peer: peer, threadId: nil, canRemove: canRemove, defaultSound: defaultSound, updatePeerSound: { peerId, sound in _ = updatePeerSound(peer.id, sound).start(next: { _ in updateNotificationsDisposable.set(nil) _ = combineLatest(updatePeerSound(peer.id, sound), context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) |> deliverOnMainQueue).start(next: { _, peer in if let peer = peer { updateState { value in - return value.withUpdatedPeerSound(peer._asPeer(), sound) + return value.withUpdatedPeerSound(peer, sound) } } updateNotificationsView({}) @@ -536,7 +535,7 @@ public func notificationsPeerCategoryController(context: AccountContext, categor _ = combineLatest(updatePeerNotificationInterval(peerId, muteInterval), context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) |> deliverOnMainQueue).start(next: { _, peer in if let peer = peer { updateState { value in - return value.withUpdatedPeerMuteInterval(peer._asPeer(), muteInterval) + return value.withUpdatedPeerMuteInterval(peer, muteInterval) } } updateNotificationsView({}) @@ -546,7 +545,7 @@ public func notificationsPeerCategoryController(context: AccountContext, categor _ = combineLatest(updatePeerDisplayPreviews(peerId, displayPreviews), context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) |> deliverOnMainQueue).start(next: { _, peer in if let peer = peer { updateState { value in - return value.withUpdatedPeerDisplayPreviews(peer._asPeer(), displayPreviews) + return value.withUpdatedPeerDisplayPreviews(peer, displayPreviews) } } updateNotificationsView({}) @@ -561,7 +560,7 @@ public func notificationsPeerCategoryController(context: AccountContext, categor return } updateState { value in - return value.withUpdatedPeerDisplayPreviews(peer._asPeer(), .default).withUpdatedPeerSound(peer._asPeer(), .default).withUpdatedPeerMuteInterval(peer._asPeer(), nil) + return value.withUpdatedPeerDisplayPreviews(peer, .default).withUpdatedPeerSound(peer, .default).withUpdatedPeerMuteInterval(peer, nil) } updateNotificationsView({}) }) @@ -647,7 +646,7 @@ public func notificationsPeerCategoryController(context: AccountContext, categor let values = stateValue.with { $0.mode.settings.values } - let _ = (context.engine.peers.ensurePeersAreLocallyAvailable(peers: values.map { EnginePeer($0.peer) }) + let _ = (context.engine.peers.ensurePeersAreLocallyAvailable(peers: values.map { $0.peer }) |> deliverOnMainQueue).start(completed: { updateNotificationsDisposable.set(nil) updateState { state in @@ -674,7 +673,7 @@ public func notificationsPeerCategoryController(context: AccountContext, categor return current.withUpdatedRevealedPeerId(peerId) } }, removePeer: { peer in - let _ = (context.engine.peers.ensurePeersAreLocallyAvailable(peers: [EnginePeer(peer)]) + let _ = (context.engine.peers.ensurePeersAreLocallyAvailable(peers: [peer]) |> deliverOnMainQueue).start(completed: { updateNotificationsDisposable.set(nil) updateState { value in diff --git a/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift b/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift index d7e2205182..2d45a6f58b 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import ItemListUI diff --git a/submodules/SettingsUI/Sources/Privacy and Security/CreatePasswordController.swift b/submodules/SettingsUI/Sources/Privacy and Security/CreatePasswordController.swift index 1bee2600cf..67bb0ba0e3 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/CreatePasswordController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/CreatePasswordController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import ItemListUI diff --git a/submodules/SettingsUI/Sources/Privacy and Security/GlobalAutoremoveScreen.swift b/submodules/SettingsUI/Sources/Privacy and Security/GlobalAutoremoveScreen.swift index 0492707e9b..50fa263b07 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/GlobalAutoremoveScreen.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/GlobalAutoremoveScreen.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroControllerNode.swift b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroControllerNode.swift index 66a1e65b1a..4265629d2c 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroControllerNode.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroControllerNode.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import AsyncDisplayKit -import Postbox import TelegramCore import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListRecentSessionItem.swift b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListRecentSessionItem.swift index 1f7a766846..209f328de8 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListRecentSessionItem.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListRecentSessionItem.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/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift index 293df2023a..1bc481e1dd 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift @@ -712,7 +712,7 @@ public func recentSessionsController(context: AccountContext, activeSessionsCont }) presentControllerImpl?(controller, nil) }, openWebSession: { session, peer in - let controller = RecentSessionScreen(context: context, subject: .website(session, peer), updateAcceptSecretChats: { _ in }, updateAcceptIncomingCalls: { _ in }, remove: { completion in + let controller = RecentSessionScreen(context: context, subject: .website(session, peer.flatMap(EnginePeer.init)), updateAcceptSecretChats: { _ in }, updateAcceptIncomingCalls: { _ in }, remove: { completion in removeWebSessionImpl(session.hash) completion() }) diff --git a/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift b/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift index 7847792e6e..a4640d3867 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import AsyncDisplayKit -import Postbox import TelegramCore import SwiftSignalKit import AccountContext @@ -44,7 +43,7 @@ private func closeButtonImage(theme: PresentationTheme) -> UIImage? { final class RecentSessionScreen: ViewController { enum Subject { case session(RecentAccountSession) - case website(WebAuthorization, Peer?) + case website(WebAuthorization, EnginePeer?) } private var controllerNode: RecentSessionScreenNode { return self.displayNode as! RecentSessionScreenNode @@ -361,7 +360,7 @@ private class RecentSessionScreenNode: ViewControllerTracingNode, UIScrollViewDe self.terminateButton.title = self.presentationData.strings.AuthSessions_View_Logout if let peer = peer { - title = EnginePeer(peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) + title = peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) } else { title = "" } @@ -388,7 +387,7 @@ private class RecentSessionScreenNode: ViewControllerTracingNode, UIScrollViewDe let avatarNode = AvatarNode(font: avatarPlaceholderFont(size: 12.0)) avatarNode.clipsToBounds = true avatarNode.cornerRadius = 17.0 - if let peer = peer.flatMap({ EnginePeer($0) }) { + if let peer { avatarNode.setPeer(context: context, theme: presentationData.theme, peer: peer, authorOfMessage: nil, overrideImage: nil, emptyColor: nil, clipStyle: .none, synchronousLoad: false, displayDimensions: CGSize(width: 72.0, height: 72.0), storeUnrounded: false) } self.avatarNode = avatarNode diff --git a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift index b5a667f6c0..f1287de315 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences @@ -85,7 +84,7 @@ private enum SelectivePrivacySettingsSection: Int32 { case photo } -private func stringForUserCount(_ peers: [PeerId: SelectivePrivacyPeer], strings: PresentationStrings) -> String { +private func stringForUserCount(_ peers: [EnginePeer.Id: SelectivePrivacyPeer], strings: PresentationStrings) -> String { if peers.isEmpty { return strings.PrivacyLastSeenSettings_EmpryUsersPlaceholder } else { @@ -486,22 +485,22 @@ private enum SelectivePrivacySettingsEntry: ItemListNodeEntry { private struct SelectivePrivacySettingsControllerState: Equatable { let setting: SelectivePrivacySettingType - let enableFor: [PeerId: SelectivePrivacyPeer] - let disableFor: [PeerId: SelectivePrivacyPeer] + let enableFor: [EnginePeer.Id: SelectivePrivacyPeer] + let disableFor: [EnginePeer.Id: SelectivePrivacyPeer] let saving: Bool let callDataSaving: VoiceCallDataSaving? let callP2PMode: SelectivePrivacySettingType? - let callP2PEnableFor: [PeerId: SelectivePrivacyPeer]? - let callP2PDisableFor: [PeerId: SelectivePrivacyPeer]? + let callP2PEnableFor: [EnginePeer.Id: SelectivePrivacyPeer]? + let callP2PDisableFor: [EnginePeer.Id: SelectivePrivacyPeer]? let callIntegrationAvailable: Bool? let callIntegrationEnabled: Bool? let phoneDiscoveryEnabled: Bool? let uploadedPhoto: UIImage? - init(setting: SelectivePrivacySettingType, enableFor: [PeerId: SelectivePrivacyPeer], disableFor: [PeerId: SelectivePrivacyPeer], saving: Bool, callDataSaving: VoiceCallDataSaving?, callP2PMode: SelectivePrivacySettingType?, callP2PEnableFor: [PeerId: SelectivePrivacyPeer]?, callP2PDisableFor: [PeerId: SelectivePrivacyPeer]?, callIntegrationAvailable: Bool?, callIntegrationEnabled: Bool?, phoneDiscoveryEnabled: Bool?, uploadedPhoto: UIImage?) { + init(setting: SelectivePrivacySettingType, enableFor: [EnginePeer.Id: SelectivePrivacyPeer], disableFor: [EnginePeer.Id: SelectivePrivacyPeer], saving: Bool, callDataSaving: VoiceCallDataSaving?, callP2PMode: SelectivePrivacySettingType?, callP2PEnableFor: [EnginePeer.Id: SelectivePrivacyPeer]?, callP2PDisableFor: [EnginePeer.Id: SelectivePrivacyPeer]?, callIntegrationAvailable: Bool?, callIntegrationEnabled: Bool?, phoneDiscoveryEnabled: Bool?, uploadedPhoto: UIImage?) { self.setting = setting self.enableFor = enableFor self.disableFor = disableFor @@ -561,11 +560,11 @@ private struct SelectivePrivacySettingsControllerState: Equatable { return SelectivePrivacySettingsControllerState(setting: setting, enableFor: self.enableFor, disableFor: self.disableFor, saving: self.saving, callDataSaving: self.callDataSaving, callP2PMode: self.callP2PMode, callP2PEnableFor: self.callP2PEnableFor, callP2PDisableFor: self.callP2PDisableFor, callIntegrationAvailable: self.callIntegrationAvailable, callIntegrationEnabled: self.callIntegrationEnabled, phoneDiscoveryEnabled: self.phoneDiscoveryEnabled, uploadedPhoto: self.uploadedPhoto) } - func withUpdatedEnableFor(_ enableFor: [PeerId: SelectivePrivacyPeer]) -> SelectivePrivacySettingsControllerState { + func withUpdatedEnableFor(_ enableFor: [EnginePeer.Id: SelectivePrivacyPeer]) -> SelectivePrivacySettingsControllerState { return SelectivePrivacySettingsControllerState(setting: self.setting, enableFor: enableFor, disableFor: self.disableFor, saving: self.saving, callDataSaving: self.callDataSaving, callP2PMode: self.callP2PMode, callP2PEnableFor: self.callP2PEnableFor, callP2PDisableFor: self.callP2PDisableFor, callIntegrationAvailable: self.callIntegrationAvailable, callIntegrationEnabled: self.callIntegrationEnabled, phoneDiscoveryEnabled: self.phoneDiscoveryEnabled, uploadedPhoto: self.uploadedPhoto) } - func withUpdatedDisableFor(_ disableFor: [PeerId: SelectivePrivacyPeer]) -> SelectivePrivacySettingsControllerState { + func withUpdatedDisableFor(_ disableFor: [EnginePeer.Id: SelectivePrivacyPeer]) -> SelectivePrivacySettingsControllerState { return SelectivePrivacySettingsControllerState(setting: self.setting, enableFor: self.enableFor, disableFor: disableFor, saving: self.saving, callDataSaving: self.callDataSaving, callP2PMode: self.callP2PMode, callP2PEnableFor: self.callP2PEnableFor, callP2PDisableFor: self.callP2PDisableFor, callIntegrationAvailable: self.callIntegrationAvailable, callIntegrationEnabled: self.callIntegrationEnabled, phoneDiscoveryEnabled: self.phoneDiscoveryEnabled, uploadedPhoto: self.uploadedPhoto) } @@ -577,11 +576,11 @@ private struct SelectivePrivacySettingsControllerState: Equatable { return SelectivePrivacySettingsControllerState(setting: self.setting, enableFor: self.enableFor, disableFor: self.disableFor, saving: self.saving, callDataSaving: self.callDataSaving, callP2PMode: mode, callP2PEnableFor: self.callP2PEnableFor, callP2PDisableFor: self.callP2PDisableFor, callIntegrationAvailable: self.callIntegrationAvailable, callIntegrationEnabled: self.callIntegrationEnabled, phoneDiscoveryEnabled: self.phoneDiscoveryEnabled, uploadedPhoto: self.uploadedPhoto) } - func withUpdatedCallP2PEnableFor(_ enableFor: [PeerId: SelectivePrivacyPeer]) -> SelectivePrivacySettingsControllerState { + func withUpdatedCallP2PEnableFor(_ enableFor: [EnginePeer.Id: SelectivePrivacyPeer]) -> SelectivePrivacySettingsControllerState { return SelectivePrivacySettingsControllerState(setting: self.setting, enableFor: self.enableFor, disableFor: self.disableFor, saving: self.saving, callDataSaving: self.callDataSaving, callP2PMode: self.callP2PMode, callP2PEnableFor: enableFor, callP2PDisableFor: self.callP2PDisableFor, callIntegrationAvailable: self.callIntegrationAvailable, callIntegrationEnabled: self.callIntegrationEnabled, phoneDiscoveryEnabled: self.phoneDiscoveryEnabled, uploadedPhoto: self.uploadedPhoto) } - func withUpdatedCallP2PDisableFor(_ disableFor: [PeerId: SelectivePrivacyPeer]) -> SelectivePrivacySettingsControllerState { + func withUpdatedCallP2PDisableFor(_ disableFor: [EnginePeer.Id: SelectivePrivacyPeer]) -> SelectivePrivacySettingsControllerState { return SelectivePrivacySettingsControllerState(setting: self.setting, enableFor: self.enableFor, disableFor: self.disableFor, saving: self.saving, callDataSaving: self.callDataSaving, callP2PMode: self.callP2PMode, callP2PEnableFor: self.callP2PEnableFor, callP2PDisableFor: disableFor, callIntegrationAvailable: self.callIntegrationAvailable, callIntegrationEnabled: self.callIntegrationEnabled, phoneDiscoveryEnabled: self.phoneDiscoveryEnabled, uploadedPhoto: self.uploadedPhoto) } @@ -763,8 +762,8 @@ func selectivePrivacySettingsController( ) -> ViewController { let strings = context.sharedContext.currentPresentationData.with { $0 }.strings - var initialEnableFor: [PeerId: SelectivePrivacyPeer] = [:] - var initialDisableFor: [PeerId: SelectivePrivacyPeer] = [:] + var initialEnableFor: [EnginePeer.Id: SelectivePrivacyPeer] = [:] + var initialDisableFor: [EnginePeer.Id: SelectivePrivacyPeer] = [:] switch current { case let .disableEveryone(enableFor): initialEnableFor = enableFor @@ -774,8 +773,8 @@ func selectivePrivacySettingsController( case let .enableEveryone(disableFor): initialDisableFor = disableFor } - var initialCallP2PEnableFor: [PeerId: SelectivePrivacyPeer]? - var initialCallP2PDisableFor: [PeerId: SelectivePrivacyPeer]? + var initialCallP2PEnableFor: [EnginePeer.Id: SelectivePrivacyPeer]? + var initialCallP2PDisableFor: [EnginePeer.Id: SelectivePrivacyPeer]? if let callCurrent = callSettings?.0 { switch callCurrent { case let .disableEveryone(enableFor): @@ -847,7 +846,7 @@ func selectivePrivacySettingsController( title = strings.Privacy_VoiceMessages_NeverAllow_Title } } - var peerIds: [PeerId: SelectivePrivacyPeer] = [:] + var peerIds: [EnginePeer.Id: SelectivePrivacyPeer] = [:] updateState { state in if enable { switch target { @@ -896,8 +895,8 @@ func selectivePrivacySettingsController( EngineDataMap(filteredIds.map(TelegramEngine.EngineData.Item.Peer.Peer.init)), EngineDataMap(filteredIds.map(TelegramEngine.EngineData.Item.Peer.ParticipantCount.init)) ) - |> map { peerMap, participantCountMap -> [PeerId: SelectivePrivacyPeer] in - var updatedPeers: [PeerId: SelectivePrivacyPeer] = [:] + |> map { peerMap, participantCountMap -> [EnginePeer.Id: SelectivePrivacyPeer] in + var updatedPeers: [EnginePeer.Id: SelectivePrivacyPeer] = [:] var existingIds = Set(updatedPeers.values.map { $0.peer.id }) for peerId in peerIds { guard case let .peer(peerId) = peerId else { diff --git a/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift b/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift index f4f70ba9f8..bd3b7a722c 100644 --- a/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift +++ b/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift @@ -414,24 +414,24 @@ private func notificationSearchableItems(context: AccountContext, settings: Glob default: switch key.namespace { case Namespaces.Peer.CloudUser: - users[key] = NotificationExceptionWrapper(settings: value, peer: peer) + users[key] = NotificationExceptionWrapper(settings: value, peer: EnginePeer(peer)) default: if let peer = peer as? TelegramChannel, case .broadcast = peer.info { - channels[key] = NotificationExceptionWrapper(settings: value, peer: peer) + channels[key] = NotificationExceptionWrapper(settings: value, peer: .channel(peer)) } else { - groups[key] = NotificationExceptionWrapper(settings: value, peer: peer) + groups[key] = NotificationExceptionWrapper(settings: value, peer: EnginePeer(peer)) } } } default: switch key.namespace { case Namespaces.Peer.CloudUser: - users[key] = NotificationExceptionWrapper(settings: value, peer: peer) + users[key] = NotificationExceptionWrapper(settings: value, peer: EnginePeer(peer)) default: if let peer = peer as? TelegramChannel, case .broadcast = peer.info { - channels[key] = NotificationExceptionWrapper(settings: value, peer: peer) + channels[key] = NotificationExceptionWrapper(settings: value, peer: .channel(peer)) } else { - groups[key] = NotificationExceptionWrapper(settings: value, peer: peer) + groups[key] = NotificationExceptionWrapper(settings: value, peer: EnginePeer(peer)) } } } diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift index 65455e1c73..281dc08339 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift @@ -3,7 +3,6 @@ import UIKit import Display import AsyncDisplayKit import SwiftSignalKit -import Postbox import CheckNode import AnimationUI diff --git a/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift b/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift index e863dd1dae..481e5d5320 100644 --- a/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift +++ b/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/ShareController/Sources/ShareContentContainerNode.swift b/submodules/ShareController/Sources/ShareContentContainerNode.swift index 507514063c..57179bcf47 100644 --- a/submodules/ShareController/Sources/ShareContentContainerNode.swift +++ b/submodules/ShareController/Sources/ShareContentContainerNode.swift @@ -1,7 +1,6 @@ import Foundation import UIKit import Display -import Postbox import TelegramCore import TelegramPresentationData diff --git a/submodules/ShareController/Sources/ShareControllerRecentPeersGridItem.swift b/submodules/ShareController/Sources/ShareControllerRecentPeersGridItem.swift index c1ee78c826..0efd076ebe 100644 --- a/submodules/ShareController/Sources/ShareControllerRecentPeersGridItem.swift +++ b/submodules/ShareController/Sources/ShareControllerRecentPeersGridItem.swift @@ -4,7 +4,6 @@ import Display import TelegramCore import SwiftSignalKit import AsyncDisplayKit -import Postbox import TelegramPresentationData import ChatListSearchRecentPeersNode import AccountContext diff --git a/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift b/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift index e33ed339f7..45a2f734ea 100644 --- a/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift +++ b/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift @@ -3,7 +3,6 @@ import UIKit import CallKit import Intents import AVFoundation -import Postbox import TelegramCore import SwiftSignalKit import AppBundle @@ -70,7 +69,7 @@ public final class CallKitIntegration { } } - func startCall(context: AccountContext, peerId: PeerId, phoneNumber: String?, localContactId: String?, isVideo: Bool, displayTitle: String) { + func startCall(context: AccountContext, peerId: EnginePeer.Id, phoneNumber: String?, localContactId: String?, isVideo: Bool, displayTitle: String) { if #available(iOSApplicationExtension 10.0, iOS 10.0, *) { (sharedProviderDelegate as? CallKitProviderDelegate)?.startCall(context: context, peerId: peerId, phoneNumber: phoneNumber, isVideo: isVideo, displayTitle: displayTitle) self.donateIntent(peerId: peerId, displayTitle: displayTitle, localContactId: localContactId) @@ -101,7 +100,7 @@ public final class CallKitIntegration { } } - private func donateIntent(peerId: PeerId, displayTitle: String, localContactId: String?) { + private func donateIntent(peerId: EnginePeer.Id, displayTitle: String, localContactId: String?) { if #available(iOSApplicationExtension 10.0, iOS 10.0, *) { let handle = INPersonHandle(value: "tg\(peerId.id._internalGetInt64Value())", type: .unknown) let contact = INPerson(personHandle: handle, nameComponents: nil, displayName: displayTitle, image: nil, contactIdentifier: localContactId, customIdentifier: "tg\(peerId.id._internalGetInt64Value())") @@ -218,7 +217,7 @@ class CallKitProviderDelegate: NSObject, CXProviderDelegate { self.requestTransaction(transaction) } - func startCall(context: AccountContext, peerId: PeerId, phoneNumber: String?, isVideo: Bool, displayTitle: String) { + func startCall(context: AccountContext, peerId: EnginePeer.Id, phoneNumber: String?, isVideo: Bool, displayTitle: String) { let uuid = UUID() self.currentStartCallAccount = (uuid, context) let handle: CXHandle diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index b2293dd85e..c4e26a38ce 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -1239,8 +1239,6 @@ public final class VoiceChatControllerImpl: ViewController, VoiceChatController return } - let peer = EnginePeer(peer) - let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } if peer.id == strongSelf.callState?.myPeerId { return diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift index ba0442c7c5..b92a84d4cb 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift @@ -9,6 +9,8 @@ public enum AddressNameValidationStatus: Equatable { case availability(AddressNameAvailability) } +public typealias EngineStringIndexTokenTransliteration = StringIndexTokenTransliteration + public final class OpaqueChatInterfaceState { public let opaqueData: Data? public let historyScrollMessageIndex: MessageIndex? @@ -64,8 +66,11 @@ public extension TelegramEngine { return _internal_checkPublicChannelCreationAvailability(account: self.account, location: location) } - public func adminedPublicChannels(scope: AdminedPublicChannelsScope = .all) -> Signal<[Peer], NoError> { + public func adminedPublicChannels(scope: AdminedPublicChannelsScope = .all) -> Signal<[EnginePeer], NoError> { return _internal_adminedPublicChannels(account: self.account, scope: scope) + |> map { peers -> [EnginePeer] in + return peers.map(EnginePeer.init) + } } public func channelAddressNameAssignmentAvailability(peerId: PeerId?) -> Signal { @@ -373,8 +378,11 @@ public extension TelegramEngine { return _internal_removePeerMember(account: self.account, peerId: peerId, memberId: memberId) } - public func availableGroupsForChannelDiscussion() -> Signal<[Peer], AvailableChannelDiscussionGroupError> { + public func availableGroupsForChannelDiscussion() -> Signal<[EnginePeer], AvailableChannelDiscussionGroupError> { return _internal_availableGroupsForChannelDiscussion(postbox: self.account.postbox, network: self.account.network) + |> map { peers -> [EnginePeer] in + return peers.map(EnginePeer.init) + } } public func updateGroupDiscussionForChannel(channelId: PeerId?, groupId: PeerId?) -> Signal { @@ -1115,6 +1123,15 @@ public extension TelegramEngine { public func requestLeaveChatFolderSuggestions(folderId: Int32) -> Signal<[EnginePeer.Id], NoError> { return _internal_requestLeaveChatFolderSuggestions(account: self.account, folderId: folderId) } + + public func keepPeerUpdated(id: EnginePeer.Id, forceUpdate: Bool) -> Signal { + return self.account.viewTracker.peerView(id, updateData: forceUpdate) + |> ignoreValues + } + + public func tokenizeSearchString(string: String, transliteration: EngineStringIndexTokenTransliteration) -> [EngineDataBuffer] { + return stringIndexTokens(string, transliteration: transliteration) + } } } diff --git a/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/ChatFolderLinkPreviewScreen.swift b/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/ChatFolderLinkPreviewScreen.swift index b91f2cbd83..5a44d2a9b2 100644 --- a/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/ChatFolderLinkPreviewScreen.swift +++ b/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/ChatFolderLinkPreviewScreen.swift @@ -10,7 +10,6 @@ import TelegramPresentationData import AccountContext import TelegramCore import MultilineTextComponent -import Postbox import SolidRoundedButtonComponent import PresentationDataUtils import Markdown diff --git a/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/PeerListItemComponent.swift b/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/PeerListItemComponent.swift index d5acbc67b8..10f12a5634 100644 --- a/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/PeerListItemComponent.swift +++ b/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/PeerListItemComponent.swift @@ -7,7 +7,6 @@ import SwiftSignalKit import AccountContext import TelegramCore import MultilineTextComponent -import Postbox import AvatarNode import TelegramPresentationData import CheckNode diff --git a/submodules/TelegramUI/Components/ChatTimerScreen/Sources/ChatTimerScreen.swift b/submodules/TelegramUI/Components/ChatTimerScreen/Sources/ChatTimerScreen.swift index 586b4780c9..3866a794c9 100644 --- a/submodules/TelegramUI/Components/ChatTimerScreen/Sources/ChatTimerScreen.swift +++ b/submodules/TelegramUI/Components/ChatTimerScreen/Sources/ChatTimerScreen.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import AsyncDisplayKit -import Postbox import TelegramCore import SwiftSignalKit import AccountContext diff --git a/submodules/TelegramUI/Components/ForumCreateTopicScreen/Sources/ForumCreateTopicScreen.swift b/submodules/TelegramUI/Components/ForumCreateTopicScreen/Sources/ForumCreateTopicScreen.swift index a36e244c2f..508ae2bda0 100644 --- a/submodules/TelegramUI/Components/ForumCreateTopicScreen/Sources/ForumCreateTopicScreen.swift +++ b/submodules/TelegramUI/Components/ForumCreateTopicScreen/Sources/ForumCreateTopicScreen.swift @@ -13,9 +13,9 @@ import EntityKeyboard import PagerComponent import MultilineTextComponent import EmojiStatusComponent -import Postbox import PremiumUI import ProgressNavigationButtonNode +import Postbox private final class SwitchComponent: Component { typealias EnvironmentType = Empty @@ -654,7 +654,7 @@ private final class ForumCreateTopicScreenComponent: CombinedComponent { areUnicodeEmojiEnabled: false, areCustomEmojiEnabled: true, chatPeerId: self.context.account.peerId, - selectedItems: Set([MediaId(namespace: Namespaces.Media.CloudFile, id: self.fileId)]), + selectedItems: Set([EngineMedia.Id(namespace: Namespaces.Media.CloudFile, id: self.fileId)]), topicTitle: self.title, topicColor: self.iconColor ) diff --git a/submodules/TelegramUI/Components/NotificationExceptionsScreen/Sources/NotificationExceptionsScreen.swift b/submodules/TelegramUI/Components/NotificationExceptionsScreen/Sources/NotificationExceptionsScreen.swift index 7c2aff0683..418228f4d0 100644 --- a/submodules/TelegramUI/Components/NotificationExceptionsScreen/Sources/NotificationExceptionsScreen.swift +++ b/submodules/TelegramUI/Components/NotificationExceptionsScreen/Sources/NotificationExceptionsScreen.swift @@ -466,7 +466,7 @@ public func threadNotificationExceptionsScreen(context: AccountContext, peerId: let canRemove = true let defaultSound: PeerMessageSound = globalSettings.groupChats.sound._asMessageSound() - pushControllerImpl?(notificationPeerExceptionController(context: context, peer: peer._asPeer(), customTitle: item.info.title, threadId: item.threadId, canRemove: canRemove, defaultSound: defaultSound, updatePeerSound: { _, sound in + pushControllerImpl?(notificationPeerExceptionController(context: context, peer: peer, customTitle: item.info.title, threadId: item.threadId, canRemove: canRemove, defaultSound: defaultSound, updatePeerSound: { _, sound in let _ = (updateThreadSound(item.threadId, sound) |> deliverOnMainQueue).start(next: { _ in updateState { value in diff --git a/submodules/TelegramUI/Components/NotificationPeerExceptionController/Sources/NotificationPeerExceptionController.swift b/submodules/TelegramUI/Components/NotificationPeerExceptionController/Sources/NotificationPeerExceptionController.swift index ab90c03438..de14533077 100644 --- a/submodules/TelegramUI/Components/NotificationPeerExceptionController/Sources/NotificationPeerExceptionController.swift +++ b/submodules/TelegramUI/Components/NotificationPeerExceptionController/Sources/NotificationPeerExceptionController.swift @@ -2,7 +2,6 @@ import Foundation import UIKit import Display import AsyncDisplayKit -import Postbox import TelegramCore import SwiftSignalKit import TelegramPresentationData @@ -16,9 +15,9 @@ import NotificationSoundSelectionUI public struct NotificationExceptionWrapper : Equatable { public let settings: TelegramPeerNotificationSettings public let date: TimeInterval? - public let peer: Peer + public let peer: EnginePeer - public init(settings: TelegramPeerNotificationSettings, peer: Peer, date: TimeInterval? = nil) { + public init(settings: TelegramPeerNotificationSettings, peer: EnginePeer, date: TimeInterval? = nil) { self.settings = settings self.date = date self.peer = peer @@ -90,12 +89,12 @@ public enum NotificationExceptionMode : Equatable { } } - case users([PeerId : NotificationExceptionWrapper]) - case groups([PeerId : NotificationExceptionWrapper]) - case channels([PeerId : NotificationExceptionWrapper]) + case users([EnginePeer.Id : NotificationExceptionWrapper]) + case groups([EnginePeer.Id : NotificationExceptionWrapper]) + case channels([EnginePeer.Id : NotificationExceptionWrapper]) - public func withUpdatedPeerSound(_ peer: Peer, _ sound: PeerMessageSound) -> NotificationExceptionMode { - let apply:([PeerId : NotificationExceptionWrapper], PeerId, PeerMessageSound) -> [PeerId : NotificationExceptionWrapper] = { values, peerId, sound in + public func withUpdatedPeerSound(_ peer: EnginePeer, _ sound: PeerMessageSound) -> NotificationExceptionMode { + let apply:([EnginePeer.Id : NotificationExceptionWrapper], EnginePeer.Id, PeerMessageSound) -> [EnginePeer.Id : NotificationExceptionWrapper] = { values, peerId, sound in var values = values if let value = values[peerId] { switch sound { @@ -130,8 +129,8 @@ public enum NotificationExceptionMode : Equatable { } } - public func withUpdatedPeerMuteInterval(_ peer: Peer, _ muteInterval: Int32?) -> NotificationExceptionMode { - let apply:([PeerId : NotificationExceptionWrapper], PeerId, PeerMuteState) -> [PeerId : NotificationExceptionWrapper] = { values, peerId, muteState in + public func withUpdatedPeerMuteInterval(_ peer: EnginePeer, _ muteInterval: Int32?) -> NotificationExceptionMode { + let apply:([EnginePeer.Id : NotificationExceptionWrapper], EnginePeer.Id, PeerMuteState) -> [EnginePeer.Id : NotificationExceptionWrapper] = { values, peerId, muteState in var values = values if let value = values[peerId] { switch muteState { @@ -182,8 +181,8 @@ public enum NotificationExceptionMode : Equatable { } } - public func withUpdatedPeerDisplayPreviews(_ peer: Peer, _ displayPreviews: PeerNotificationDisplayPreviews) -> NotificationExceptionMode { - let apply:([PeerId : NotificationExceptionWrapper], PeerId, PeerNotificationDisplayPreviews) -> [PeerId : NotificationExceptionWrapper] = { values, peerId, displayPreviews in + public func withUpdatedPeerDisplayPreviews(_ peer: EnginePeer, _ displayPreviews: PeerNotificationDisplayPreviews) -> NotificationExceptionMode { + let apply:([EnginePeer.Id : NotificationExceptionWrapper], EnginePeer.Id, PeerNotificationDisplayPreviews) -> [EnginePeer.Id : NotificationExceptionWrapper] = { values, peerId, displayPreviews in var values = values if let value = values[peerId] { switch displayPreviews { @@ -218,14 +217,14 @@ public enum NotificationExceptionMode : Equatable { } } - public var peerIds: [PeerId] { + public var peerIds: [EnginePeer.Id] { switch self { case let .users(settings), let .groups(settings), let .channels(settings): return settings.map {$0.key} } } - public var settings: [PeerId : NotificationExceptionWrapper] { + public var settings: [EnginePeer.Id : NotificationExceptionWrapper] { switch self { case let .users(settings), let .groups(settings), let .channels(settings): return settings @@ -585,7 +584,7 @@ private struct NotificationExceptionPeerState : Equatable { } } -public func notificationPeerExceptionController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peer: Peer, customTitle: String? = nil, threadId: Int64?, canRemove: Bool, defaultSound: PeerMessageSound, edit: Bool = false, updatePeerSound: @escaping(PeerId, PeerMessageSound) -> Void, updatePeerNotificationInterval: @escaping(PeerId, Int32?) -> Void, updatePeerDisplayPreviews: @escaping(PeerId, PeerNotificationDisplayPreviews) -> Void, removePeerFromExceptions: @escaping () -> Void, modifiedPeer: @escaping () -> Void) -> ViewController { +public func notificationPeerExceptionController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peer: EnginePeer, customTitle: String? = nil, threadId: Int64?, canRemove: Bool, defaultSound: PeerMessageSound, edit: Bool = false, updatePeerSound: @escaping(EnginePeer.Id, PeerMessageSound) -> Void, updatePeerNotificationInterval: @escaping(EnginePeer.Id, Int32?) -> Void, updatePeerDisplayPreviews: @escaping(EnginePeer.Id, PeerNotificationDisplayPreviews) -> Void, removePeerFromExceptions: @escaping () -> Void, modifiedPeer: @escaping () -> Void) -> ViewController { let initialState = NotificationExceptionPeerState(canRemove: false) let statePromise = Promise(initialState) let stateValue = Atomic(value: initialState) @@ -683,7 +682,7 @@ public func notificationPeerExceptionController(context: AccountContext, updated if let customTitle = customTitle { titleString = customTitle } else { - titleString = EnginePeer(peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) + titleString = peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) } let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(titleString), leftNavigationButton: leftNavigationButton, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back)) diff --git a/submodules/TelegramUI/Components/SendInviteLinkScreen/Sources/SendInviteLinkScreen.swift b/submodules/TelegramUI/Components/SendInviteLinkScreen/Sources/SendInviteLinkScreen.swift index 1c7609aeb1..ea93f3a000 100644 --- a/submodules/TelegramUI/Components/SendInviteLinkScreen/Sources/SendInviteLinkScreen.swift +++ b/submodules/TelegramUI/Components/SendInviteLinkScreen/Sources/SendInviteLinkScreen.swift @@ -10,7 +10,6 @@ import TelegramPresentationData import AccountContext import TelegramCore import MultilineTextComponent -import Postbox import SolidRoundedButtonComponent import PresentationDataUtils import Markdown diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataCategoriesComponent.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataCategoriesComponent.swift index eb6a9587ff..5faf537638 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataCategoriesComponent.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataCategoriesComponent.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox import CheckNode import SolidRoundedButtonComponent diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataCategoryItemCompoment.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataCategoryItemCompoment.swift index d9d6280419..0e7f6e926d 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataCategoryItemCompoment.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataCategoryItemCompoment.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox import TelegramStringFormatting import CheckNode diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataUsageScreen.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataUsageScreen.swift index d4463a89a4..d26fa0d642 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataUsageScreen.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/DataUsageScreen.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox import Markdown import ContextUI import AnimatedAvatarSetNode diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/PieChartComponent.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/PieChartComponent.swift index cd901ca5b8..0ebd20b6f7 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/PieChartComponent.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/PieChartComponent.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox private func processChartData(data: PieChartComponent.ChartData) -> PieChartComponent.ChartData { var data = data diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/SegmentControlComponent.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/SegmentControlComponent.swift index 1b71a910ec..e6ff6db679 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/SegmentControlComponent.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/SegmentControlComponent.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox import TelegramStringFormatting import CheckNode import SegmentedControlNode diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageCategoriesComponent.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageCategoriesComponent.swift index 9588072219..44056145f0 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageCategoriesComponent.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageCategoriesComponent.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox import CheckNode import SolidRoundedButtonComponent diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageCategoryItemCompoment.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageCategoryItemCompoment.swift index 41605decc5..10e3360b82 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageCategoryItemCompoment.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageCategoryItemCompoment.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox import TelegramStringFormatting import CheckNode diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageKeepSizeComponent.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageKeepSizeComponent.swift index 95c6c5623e..783f1b1901 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageKeepSizeComponent.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageKeepSizeComponent.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox import CheckNode import SolidRoundedButtonComponent import LegacyComponents diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageMediaGridPanelComponent.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageMediaGridPanelComponent.swift index 8057e16c8b..7d61c393cd 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageMediaGridPanelComponent.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageMediaGridPanelComponent.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox import TelegramStringFormatting import CheckNode import AvatarNode @@ -27,7 +26,7 @@ private final class MediaGridLayer: SimpleLayer { case editing(isSelected: Bool) } - private(set) var message: Message? + private(set) var message: EngineMessage? private var disposable: Disposable? private var size: CGSize? @@ -77,7 +76,7 @@ private final class MediaGridLayer: SimpleLayer { } } - func setup(context: AccountContext, strings: PresentationStrings, message: Message, size: Int64) { + func setup(context: AccountContext, strings: PresentationStrings, message: EngineMessage, size: Int64) { self.message = message var isVideo = false @@ -221,11 +220,11 @@ final class StorageMediaGridPanelComponent: Component { typealias EnvironmentType = StorageUsagePanelEnvironment final class Item: Equatable { - let message: Message + let message: EngineMessage let size: Int64 init( - message: Message, + message: EngineMessage, size: Int64 ) { self.message = message @@ -478,7 +477,7 @@ final class StorageMediaGridPanelComponent: Component { fatalError("init(coder:) has not been implemented") } - func transitionNodeForGallery(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { + func transitionNodeForGallery(messageId: EngineMessage.Id, media: EngineMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { var foundItemLayer: MediaGridLayer? for (_, itemLayer) in self.visibleLayers { if let message = itemLayer.message, message.id == messageId { diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StoragePeerListPanelComponent.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StoragePeerListPanelComponent.swift index b1f3e311bb..6e9f125649 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StoragePeerListPanelComponent.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StoragePeerListPanelComponent.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox import TelegramStringFormatting import CheckNode import AvatarNode diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StoragePeerTypeItemComponent.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StoragePeerTypeItemComponent.swift index 9a75fced24..8e54180182 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StoragePeerTypeItemComponent.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StoragePeerTypeItemComponent.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox import TelegramStringFormatting import CheckNode diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift index e379cd1fec..43115b1632 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift @@ -9,9 +9,9 @@ import ComponentDisplayAdapters import TelegramPresentationData import AccountContext import TelegramCore +import Postbox import MultilineTextComponent import EmojiStatusComponent -import Postbox import Markdown import ContextUI import AnimatedAvatarSetNode @@ -571,7 +571,7 @@ final class StorageUsageScreenComponent: Component { for item in imageItems.items { if deselectedPhotos.contains(item.message.id) { selectedSize -= item.size - clearExcludeMessages.append(item.message) + clearExcludeMessages.append(item.message._asMessage()) } } } @@ -581,7 +581,7 @@ final class StorageUsageScreenComponent: Component { for item in imageItems.items { if selectedPhotos.contains(item.message.id) { selectedSize += item.size - clearIncludeMessages.append(item.message) + clearIncludeMessages.append(item.message._asMessage()) } } } @@ -593,7 +593,7 @@ final class StorageUsageScreenComponent: Component { for item in imageItems.items { if deselectedVideos.contains(item.message.id) { selectedSize -= item.size - clearExcludeMessages.append(item.message) + clearExcludeMessages.append(item.message._asMessage()) } } } @@ -603,7 +603,7 @@ final class StorageUsageScreenComponent: Component { for item in imageItems.items { if selectedVideos.contains(item.message.id) { selectedSize += item.size - clearIncludeMessages.append(item.message) + clearIncludeMessages.append(item.message._asMessage()) } } } @@ -2356,7 +2356,7 @@ final class StorageUsageScreenComponent: Component { if matches { result.imageItems.append(StorageMediaGridPanelComponent.Item( - message: message, + message: EngineMessage(message), size: messageSize )) } @@ -2728,7 +2728,7 @@ final class StorageUsageScreenComponent: Component { if let panelContainerView = self.panelContainer.view as? StorageUsagePanelContainerComponent.View { if let currentPanelView = panelContainerView.currentPanelView as? StorageMediaGridPanelComponent.View { - return currentPanelView.transitionNodeForGallery(messageId: messageId, media: media) + return currentPanelView.transitionNodeForGallery(messageId: messageId, media: EngineMedia(media)) } } diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreenSelectionPanelComponent.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreenSelectionPanelComponent.swift index 09fd43a2fc..96a324bb12 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreenSelectionPanelComponent.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreenSelectionPanelComponent.swift @@ -11,7 +11,6 @@ import AccountContext import TelegramCore import MultilineTextComponent import EmojiStatusComponent -import Postbox import TelegramStringFormatting import CheckNode import SolidRoundedButtonComponent diff --git a/submodules/TelegramUI/Sources/ChatMessageAttachedContentNode.swift b/submodules/TelegramUI/Sources/ChatMessageAttachedContentNode.swift index 9f240ce8a7..5d5f0f75de 100644 --- a/submodules/TelegramUI/Sources/ChatMessageAttachedContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageAttachedContentNode.swift @@ -5,7 +5,6 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore -import Postbox import TelegramPresentationData import TelegramUIPreferences import TextFormat diff --git a/submodules/TelegramUI/Sources/ChatMessageGiftItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageGiftItemNode.swift index 0bf736e88e..9eb69af77c 100644 --- a/submodules/TelegramUI/Sources/ChatMessageGiftItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageGiftItemNode.swift @@ -3,7 +3,6 @@ import UIKit import AsyncDisplayKit import Display import SwiftSignalKit -import Postbox import TelegramCore import AccountContext import TelegramPresentationData @@ -19,8 +18,8 @@ import TelegramAnimatedStickerNode import ChatControllerInteraction import ShimmerEffect -private func attributedServiceMessageString(theme: ChatPresentationThemeData, strings: PresentationStrings, nameDisplayOrder: PresentationPersonNameOrder, dateTimeFormat: PresentationDateTimeFormat, message: Message, accountPeerId: PeerId) -> NSAttributedString? { - return universalServiceMessageString(presentationData: (theme.theme, theme.wallpaper), strings: strings, nameDisplayOrder: nameDisplayOrder, dateTimeFormat: dateTimeFormat, message: EngineMessage(message), accountPeerId: accountPeerId, forChatList: false, forForumOverview: false) +private func attributedServiceMessageString(theme: ChatPresentationThemeData, strings: PresentationStrings, nameDisplayOrder: PresentationPersonNameOrder, dateTimeFormat: PresentationDateTimeFormat, message: EngineMessage, accountPeerId: EnginePeer.Id) -> NSAttributedString? { + return universalServiceMessageString(presentationData: (theme.theme, theme.wallpaper), strings: strings, nameDisplayOrder: nameDisplayOrder, dateTimeFormat: dateTimeFormat, message: message, accountPeerId: accountPeerId, forChatList: false, forForumOverview: false) } class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode { @@ -176,7 +175,7 @@ class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode { return (contentProperties, nil, CGFloat.greatestFiniteMagnitude, { constrainedSize, position in let giftSize = CGSize(width: 220.0, height: 240.0) - let attributedString = attributedServiceMessageString(theme: item.presentationData.theme, strings: item.presentationData.strings, nameDisplayOrder: item.presentationData.nameDisplayOrder, dateTimeFormat: item.presentationData.dateTimeFormat, message: item.message, accountPeerId: item.context.account.peerId) + let attributedString = attributedServiceMessageString(theme: item.presentationData.theme, strings: item.presentationData.strings, nameDisplayOrder: item.presentationData.nameDisplayOrder, dateTimeFormat: item.presentationData.dateTimeFormat, message: EngineMessage(item.message), accountPeerId: item.context.account.peerId) let primaryTextColor = serviceMessageColorComponents(theme: item.presentationData.theme.theme, wallpaper: item.presentationData.theme.wallpaper).primaryText diff --git a/submodules/TelegramUI/Sources/OwnershipTransferController.swift b/submodules/TelegramUI/Sources/OwnershipTransferController.swift index 10ff585ed3..82cf7b3d44 100644 --- a/submodules/TelegramUI/Sources/OwnershipTransferController.swift +++ b/submodules/TelegramUI/Sources/OwnershipTransferController.swift @@ -3,7 +3,6 @@ import UIKit import AsyncDisplayKit import Display import SwiftSignalKit -import Postbox import TelegramCore import TelegramPresentationData import ActivityIndicator diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index 734ece2992..450d31e755 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -4573,7 +4573,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate let canRemove = false - let exceptionController = notificationPeerExceptionController(context: context, updatedPresentationData: strongSelf.controller?.updatedPresentationData, peer: peer, threadId: threadId, canRemove: canRemove, defaultSound: defaultSound, edit: true, updatePeerSound: { peerId, sound in + let exceptionController = notificationPeerExceptionController(context: context, updatedPresentationData: strongSelf.controller?.updatedPresentationData, peer: EnginePeer(peer), threadId: threadId, canRemove: canRemove, defaultSound: defaultSound, edit: true, updatePeerSound: { peerId, sound in let _ = (updatePeerSound(peer.id, sound) |> deliverOnMainQueue).start(next: { _ in }) @@ -6522,7 +6522,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate guard let data = self.data, let peer = data.peer, let encryptionKeyFingerprint = data.encryptionKeyFingerprint else { return } - self.controller?.push(SecretChatKeyController(context: self.context, fingerprint: encryptionKeyFingerprint, peer: peer)) + self.controller?.push(SecretChatKeyController(context: self.context, fingerprint: encryptionKeyFingerprint, peer: EnginePeer(peer))) } private func openShareBot() { diff --git a/submodules/TelegramUI/Sources/PeersNearbyManager.swift b/submodules/TelegramUI/Sources/PeersNearbyManager.swift index 8faddf9d12..dc44ce6199 100644 --- a/submodules/TelegramUI/Sources/PeersNearbyManager.swift +++ b/submodules/TelegramUI/Sources/PeersNearbyManager.swift @@ -1,6 +1,5 @@ import Foundation import SwiftSignalKit -import Postbox import TelegramCore import TelegramApi import DeviceLocationManager diff --git a/submodules/TelegramUI/Sources/PollResultsController.swift b/submodules/TelegramUI/Sources/PollResultsController.swift index 8e486a83c7..7642dab1cc 100644 --- a/submodules/TelegramUI/Sources/PollResultsController.swift +++ b/submodules/TelegramUI/Sources/PollResultsController.swift @@ -1,5 +1,4 @@ import Foundation -import Postbox import TelegramCore import SwiftSignalKit import TelegramPresentationData @@ -16,10 +15,10 @@ private final class PollResultsControllerArguments { let context: AccountContext let collapseOption: (Data) -> Void let expandOption: (Data) -> Void - let openPeer: (RenderedPeer) -> Void + let openPeer: (EngineRenderedPeer) -> Void let expandSolution: () -> Void - init(context: AccountContext, collapseOption: @escaping (Data) -> Void, expandOption: @escaping (Data) -> Void, openPeer: @escaping (RenderedPeer) -> Void, expandSolution: @escaping () -> Void) { + init(context: AccountContext, collapseOption: @escaping (Data) -> Void, expandOption: @escaping (Data) -> Void, openPeer: @escaping (EngineRenderedPeer) -> Void, expandSolution: @escaping () -> Void) { self.context = context self.collapseOption = collapseOption self.expandOption = expandOption @@ -67,7 +66,7 @@ private enum PollResultsItemTag: ItemListItemTag, Equatable { private enum PollResultsEntry: ItemListNodeEntry { case text(String) - case optionPeer(optionId: Int, index: Int, peer: RenderedPeer, optionText: String, optionAdditionalText: String, optionCount: Int32, optionExpanded: Bool, opaqueIdentifier: Data, shimmeringAlternation: Int?, isFirstInOption: Bool) + case optionPeer(optionId: Int, index: Int, peer: EngineRenderedPeer, optionText: String, optionAdditionalText: String, optionCount: Int32, optionExpanded: Bool, opaqueIdentifier: Data, shimmeringAlternation: Int?, isFirstInOption: Bool) case optionExpand(optionId: Int, opaqueIdentifier: Data, text: String, enabled: Bool) case solutionHeader(String) case solutionText(String) @@ -187,7 +186,7 @@ private enum PollResultsEntry: ItemListNodeEntry { let header = ItemListPeerItemHeader(theme: presentationData.theme, strings: presentationData.strings, text: optionText, additionalText: optionAdditionalText, actionTitle: optionExpanded ? presentationData.strings.PollResults_Collapse : presentationData.strings.MessagePoll_VotedCount(optionCount), id: Int64(optionId), action: optionExpanded ? { arguments.collapseOption(opaqueIdentifier) } : nil) - return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: PresentationDateTimeFormat(), nameDisplayOrder: .firstLast, context: arguments.context, peer: EnginePeer(peer.peers[peer.peerId]!), presence: nil, text: .none, label: .none, editing: ItemListPeerItemEditing(editable: false, editing: false, revealed: false), switchValue: nil, enabled: true, selectable: shimmeringAlternation == nil, sectionId: self.section, action: { + return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: PresentationDateTimeFormat(), nameDisplayOrder: .firstLast, context: arguments.context, peer: peer.peers[peer.peerId]!, presence: nil, text: .none, label: .none, editing: ItemListPeerItemEditing(editable: false, editing: false, revealed: false), switchValue: nil, enabled: true, selectable: shimmeringAlternation == nil, sectionId: self.section, action: { arguments.openPeer(peer) }, setPeerIdWithRevealedOptions: { _, _ in }, removePeer: { _ in @@ -251,8 +250,8 @@ private func pollResultsControllerEntries(presentationData: PresentationData, po displayCount = Int(voterCount) } for peerIndex in 0 ..< displayCount { - let fakeUser = TelegramUser(id: PeerId(namespace: .max, id: PeerId.Id._internalFromInt64Value(0)), accessHash: nil, firstName: "", lastName: "", username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: [], emojiStatus: nil, usernames: []) - let peer = RenderedPeer(peer: fakeUser) + let fakeUser = TelegramUser(id: EnginePeer.Id(namespace: .max, id: EnginePeer.Id.Id._internalFromInt64Value(0)), accessHash: nil, firstName: "", lastName: "", username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: [], emojiStatus: nil, usernames: []) + let peer = EngineRenderedPeer(peer: EnginePeer(fakeUser)) entries.append(.optionPeer(optionId: i, index: peerIndex, peer: peer, optionText: optionTextHeader, optionAdditionalText: optionAdditionalTextHeader, optionCount: voterCount, optionExpanded: false, opaqueIdentifier: option.opaqueIdentifier, shimmeringAlternation: peerIndex % 2, isFirstInOption: peerIndex == 0)) } if displayCount < Int(voterCount) { @@ -295,7 +294,7 @@ private func pollResultsControllerEntries(presentationData: PresentationData, po if peerIndex >= displayCount { break inner } - entries.append(.optionPeer(optionId: i, index: peerIndex, peer: peer, optionText: optionTextHeader, optionAdditionalText: optionAdditionalTextHeader, optionCount: Int32(count), optionExpanded: optionExpandedAtCount != nil, opaqueIdentifier: option.opaqueIdentifier, shimmeringAlternation: nil, isFirstInOption: peerIndex == 0)) + entries.append(.optionPeer(optionId: i, index: peerIndex, peer: EngineRenderedPeer(peer), optionText: optionTextHeader, optionAdditionalText: optionAdditionalTextHeader, optionCount: Int32(count), optionExpanded: optionExpandedAtCount != nil, opaqueIdentifier: option.opaqueIdentifier, shimmeringAlternation: nil, isFirstInOption: peerIndex == 0)) peerIndex += 1 } @@ -310,7 +309,7 @@ private func pollResultsControllerEntries(presentationData: PresentationData, po return entries } -public func pollResultsController(context: AccountContext, messageId: MessageId, poll: TelegramMediaPoll, focusOnOptionWithOpaqueIdentifier: Data? = nil) -> ViewController { +public func pollResultsController(context: AccountContext, messageId: EngineMessage.Id, poll: TelegramMediaPoll, focusOnOptionWithOpaqueIdentifier: Data? = nil) -> ViewController { let statePromise = ValuePromise(PollResultsControllerState(), ignoreRepeated: true) let stateValue = Atomic(value: PollResultsControllerState()) let updateState: ((PollResultsControllerState) -> PollResultsControllerState) -> Void = { f in @@ -349,7 +348,7 @@ public func pollResultsController(context: AccountContext, messageId: MessageId, }) }, openPeer: { peer in if let peer = peer.peers[peer.peerId] { - if let controller = context.sharedContext.makePeerInfoController(context: context, updatedPresentationData: nil, peer: peer, mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) { + if let controller = context.sharedContext.makePeerInfoController(context: context, updatedPresentationData: nil, peer: peer._asPeer(), mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) { pushControllerImpl?(controller) } }