diff --git a/submodules/ChatListUI/Sources/ChatContextMenus.swift b/submodules/ChatListUI/Sources/ChatContextMenus.swift index 3d103eb618..e33fe9e2b3 100644 --- a/submodules/ChatListUI/Sources/ChatContextMenus.swift +++ b/submodules/ChatListUI/Sources/ChatContextMenus.swift @@ -68,7 +68,7 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch items.append(.separator) case .recentSearch: items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_RemoveFromRecents, textColor: .destructive, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Clear"), color: theme.contextMenu.destructiveColor) }, action: { _, f in - let _ = (removeRecentlySearchedPeer(postbox: context.account.postbox, peerId: peerId) + let _ = (context.engine.peers.removeRecentlySearchedPeer(peerId: peerId) |> deliverOnMainQueue).start(completed: { f(.default) }) diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index a084e3f295..97130371d5 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -2004,11 +2004,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController |> delay(0.8, queue: Queue.mainQueue()) let progressDisposable = progressSignal.start() - let signal: Signal = strongSelf.context.account.postbox.transaction { transaction -> Void in - for peerId in peerIds { - removePeerChat(account: context.account, transaction: transaction, mediaBox: context.account.postbox.mediaBox, peerId: peerId, reportChatSpam: false, deleteGloballyIfPossible: peerId.namespace == Namespaces.Peer.SecretChat) - } - } + let signal: Signal = strongSelf.context.engine.peers.removePeerChats(peerIds: Array(peerIds)) |> afterDisposed { Queue.mainQueue().async { progressDisposable.dispose() @@ -2693,7 +2689,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController if let channel = chatPeer as? TelegramChannel { strongSelf.context.peerChannelMemberCategoriesContextsManager.externallyRemoved(peerId: channel.id, memberId: strongSelf.context.account.peerId) } - let _ = removePeerChat(account: strongSelf.context.account, peerId: peerId, reportChatSpam: false, deleteGloballyIfPossible: deleteGloballyIfPossible).start(completed: { + let _ = strongSelf.context.engine.peers.removePeerChat(peerId: peerId, reportChatSpam: false, deleteGloballyIfPossible: deleteGloballyIfPossible).start(completed: { guard let strongSelf = self else { return } diff --git a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift index cafbbffdd3..041708249f 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift @@ -191,7 +191,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo guard let strongSelf = self else { return } - let _ = (clearRecentlySearchedPeers(postbox: strongSelf.context.account.postbox) + let _ = (strongSelf.context.engine.peers.clearRecentlySearchedPeers() |> deliverOnMainQueue).start() }) ]), ActionSheetItemGroup(items: [ diff --git a/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift b/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift index eb284e2f4e..c7da79e5f3 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift @@ -1213,7 +1213,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { }, peerSelected: { [weak self] peer, _ in interaction.dismissInput() interaction.openPeer(peer, false) - let _ = addRecentlySearchedPeer(postbox: context.account.postbox, peerId: peer.id).start() + let _ = context.engine.peers.addRecentlySearchedPeer(peerId: peer.id).start() self?.listNode.clearHighlightAnimated(true) }, disabledPeerSelected: { _ in }, togglePeerSelected: { _ in @@ -1407,7 +1407,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { |> distinctUntilChanged let previousRecentlySearchedPeerOrder = Atomic<[PeerId]>(value: []) - let fixedRecentlySearchedPeers = recentlySearchedPeers(postbox: context.account.postbox) + let fixedRecentlySearchedPeers = context.engine.peers.recentlySearchedPeers() |> map { peers -> [RecentlySearchedPeer] in var result: [RecentlySearchedPeer] = [] let _ = previousRecentlySearchedPeerOrder.modify { current in @@ -1479,7 +1479,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { let firstTime = previousEntries == nil let transition = chatListSearchContainerPreparedRecentTransition(from: previousEntries ?? [], to: entries, context: context, presentationData: presentationData, filter: peersFilter, peerSelected: { peer in interaction.openPeer(peer, true) - let _ = addRecentlySearchedPeer(postbox: context.account.postbox, peerId: peer.id).start() + let _ = context.engine.peers.addRecentlySearchedPeer(peerId: peer.id).start() self?.recentListNode.clearHighlightAnimated(true) }, disabledPeerSelected: { peer in interaction.openDisabledPeer(peer) @@ -1492,7 +1492,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { }, clearRecentlySearchedPeers: { interaction.clearRecentSearch() }, deletePeer: { peerId in - let _ = removeRecentlySearchedPeer(postbox: context.account.postbox, peerId: peerId).start() + let _ = context.engine.peers.removeRecentlySearchedPeer(peerId: peerId).start() }) strongSelf.enqueueRecentTransition(transition, firstTime: firstTime) } diff --git a/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift b/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift index 9ff8e0da6d..ba498852d8 100644 --- a/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift +++ b/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift @@ -450,7 +450,7 @@ public final class SecretMediaPreviewController: ViewController { self?.didSetReady = true } self._ready.set(ready |> map { true }) - self.markMessageAsConsumedDisposable.set(markMessageContentAsConsumedInteractively(postbox: self.context.account.postbox, messageId: message.id).start()) + self.markMessageAsConsumedDisposable.set(self.context.engine.messages.markMessageContentAsConsumedInteractively(messageId: message.id).start()) } else { var beginTimeAndTimeout: (Double, Double)? var videoDuration: Int32? diff --git a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift index 74ab715d1f..2c3c31104b 100644 --- a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift @@ -927,14 +927,14 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi return current.withUpdatedUpdating(true) } if peerId.namespace == Namespaces.Peer.CloudGroup { - updateRightsDisposable.set((removeGroupAdmin(account: context.account, peerId: peerId, adminId: adminId) + updateRightsDisposable.set((context.engine.peers.removeGroupAdmin(peerId: peerId, adminId: adminId) |> deliverOnMainQueue).start(error: { _ in }, completed: { updated(nil) dismissImpl?() })) } else { - updateRightsDisposable.set((context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(account: context.account, peerId: peerId, memberId: adminId, adminRights: nil, rank: nil) |> deliverOnMainQueue).start(error: { _ in + updateRightsDisposable.set((context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(engine: context.engine, peerId: peerId, memberId: adminId, adminRights: nil, rank: nil) |> deliverOnMainQueue).start(error: { _ in }, completed: { updated(nil) @@ -1041,7 +1041,7 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi updateState { current in return current.withUpdatedUpdating(true) } - updateRightsDisposable.set((context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(account: context.account, peerId: peerId, memberId: adminId, adminRights: TelegramChatAdminRights(rights: updateFlags ?? []), rank: effectiveRank) |> deliverOnMainQueue).start(error: { error in + updateRightsDisposable.set((context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(engine: context.engine, peerId: peerId, memberId: adminId, adminRights: TelegramChatAdminRights(rights: updateFlags ?? []), rank: effectiveRank) |> deliverOnMainQueue).start(error: { error in updateState { current in return current.withUpdatedUpdating(false) } @@ -1089,7 +1089,7 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi updateState { current in return current.withUpdatedUpdating(true) } - updateRightsDisposable.set((context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(account: context.account, peerId: peerId, memberId: adminId, adminRights: TelegramChatAdminRights(rights: currentFlags), rank: updateRank) |> deliverOnMainQueue).start(error: { _ in + updateRightsDisposable.set((context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(engine: context.engine, peerId: peerId, memberId: adminId, adminRights: TelegramChatAdminRights(rights: currentFlags), rank: updateRank) |> deliverOnMainQueue).start(error: { _ in }, completed: { updated(TelegramChatAdminRights(rights: currentFlags)) @@ -1134,7 +1134,7 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi updateState { current in return current.withUpdatedUpdating(true) } - updateRightsDisposable.set((context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(account: context.account, peerId: peerId, memberId: adminId, adminRights: TelegramChatAdminRights(rights: updateFlags), rank: updateRank) |> deliverOnMainQueue).start(error: { error in + updateRightsDisposable.set((context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(engine: context.engine, peerId: peerId, memberId: adminId, adminRights: TelegramChatAdminRights(rights: updateFlags), rank: updateRank) |> deliverOnMainQueue).start(error: { error in if case let .addMemberError(addMemberError) = error, let admin = adminView.peers[adminView.peerId] { var text = presentationData.strings.Login_UnknownError switch addMemberError { @@ -1201,7 +1201,7 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi updateState { current in return current.withUpdatedUpdating(true) } - updateRightsDisposable.set((addGroupAdmin(account: context.account, peerId: peerId, adminId: adminId) + updateRightsDisposable.set((context.engine.peers.addGroupAdmin(peerId: peerId, adminId: adminId) |> deliverOnMainQueue).start(error: { error in if case let .addMemberError(error) = error, case .privacy = error, let admin = adminView.peers[adminView.peerId] { presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.Privacy_GroupsAndChannels_InviteToGroupError(admin.compactDisplayTitle, admin.compactDisplayTitle).0, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil) @@ -1234,7 +1234,7 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi guard let upgradedPeerId = upgradedPeerId else { return .fail(.conversionFailed) } - return context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(account: context.account, peerId: upgradedPeerId, memberId: adminId, adminRights: TelegramChatAdminRights(rights: updateFlags), rank: updateRank) + return context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(engine: context.engine, peerId: upgradedPeerId, memberId: adminId, adminRights: TelegramChatAdminRights(rights: updateFlags), rank: updateRank) |> mapError { error -> WrappedUpdateChannelAdminRightsError in return .direct(error) } diff --git a/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift b/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift index 57354a8240..d0b16d3986 100644 --- a/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift @@ -583,14 +583,14 @@ public func channelAdminsController(context: AccountContext, peerId initialPeerI return $0.withUpdatedRemovingPeerId(adminId) } if peerId.namespace == Namespaces.Peer.CloudGroup { - removeAdminDisposable.set((removeGroupAdmin(account: context.account, peerId: peerId, adminId: adminId) + removeAdminDisposable.set((context.engine.peers.removeGroupAdmin(peerId: peerId, adminId: adminId) |> deliverOnMainQueue).start(completed: { updateState { return $0.withUpdatedRemovingPeerId(nil) } })) } else { - removeAdminDisposable.set((context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(account: context.account, peerId: peerId, memberId: adminId, adminRights: nil, rank: nil) + removeAdminDisposable.set((context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(engine: context.engine, peerId: peerId, memberId: adminId, adminRights: nil, rank: nil) |> deliverOnMainQueue).start(completed: { updateState { return $0.withUpdatedRemovingPeerId(nil) diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift b/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift index 113009b18f..fe3b052e30 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift @@ -437,7 +437,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon if peerId.namespace == Namespaces.Peer.CloudChannel { if case .searchAdmins = mode { - return context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(account: context.account, peerId: peerId, memberId: memberId, adminRights: nil, rank: nil) + return context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(engine: context.engine, peerId: peerId, memberId: memberId, adminRights: nil, rank: nil) |> `catch` { _ -> Signal in return .complete() } @@ -465,7 +465,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon } if case .searchAdmins = mode { - return removeGroupAdmin(account: context.account, peerId: peerId, adminId: memberId) + return context.engine.peers.removeGroupAdmin(peerId: peerId, adminId: memberId) |> `catch` { _ -> Signal in return .complete() } diff --git a/submodules/PeerInfoUI/Sources/OldChannelsController.swift b/submodules/PeerInfoUI/Sources/OldChannelsController.swift index 4da1e82f73..3a4edeb23e 100644 --- a/submodules/PeerInfoUI/Sources/OldChannelsController.swift +++ b/submodules/PeerInfoUI/Sources/OldChannelsController.swift @@ -455,21 +455,21 @@ public func oldChannelsController(context: AccountContext, intent: OldChannelsCo let state = stateValue.with { $0 } let _ = (peersPromise.get() |> take(1) - |> mapToSignal { peers in + |> mapToSignal { peers -> Signal in + let peers = peers ?? [] return context.account.postbox.transaction { transaction -> Void in - if let peers = peers { - for peer in peers { - if state.selectedPeers.contains(peer.peer.id) { - if transaction.getPeer(peer.peer.id) == nil { - updatePeers(transaction: transaction, peers: [peer.peer], update: { _, updated in - return updated - }) - } - removePeerChat(account: context.account, transaction: transaction, mediaBox: context.account.postbox.mediaBox, peerId: peer.peer.id, reportChatSpam: false, deleteGloballyIfPossible: false) + for peer in peers { + if state.selectedPeers.contains(peer.peer.id) { + if transaction.getPeer(peer.peer.id) == nil { + updatePeers(transaction: transaction, peers: [peer.peer], update: { _, updated in + return updated + }) } } } } + |> ignoreValues + |> then(context.engine.peers.removePeerChats(peerIds: Array(peers.map(\.peer.id)))) } |> deliverOnMainQueue).start(completed: { completed(true) diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift index 1d186c20cc..1f7ef63018 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift @@ -848,7 +848,7 @@ final class ThemeGridSearchContentNode: SearchDisplayControllerContentNode { } private func clearRecentSearch() { - let _ = (clearRecentlySearchedPeers(postbox: self.context.account.postbox) |> deliverOnMainQueue).start() + let _ = (self.context.engine.peers.clearRecentlySearchedPeers() |> deliverOnMainQueue).start() } override func scrollToTop() { diff --git a/submodules/ShareController/Sources/ShareControllerNode.swift b/submodules/ShareController/Sources/ShareControllerNode.swift index 0aa3efa75b..9608e6275e 100644 --- a/submodules/ShareController/Sources/ShareControllerNode.swift +++ b/submodules/ShareController/Sources/ShareControllerNode.swift @@ -743,7 +743,7 @@ final class ShareControllerNode: ViewControllerTracingNode, UIScrollViewDelegate }, extendedInitialReveal: self.presetText != nil, segmentedValues: self.segmentedValues) self.peersContentNode = peersContentNode peersContentNode.openSearch = { [weak self] in - let _ = (recentlySearchedPeers(postbox: context.account.postbox) + let _ = (context.engine.peers.recentlySearchedPeers() |> take(1) |> deliverOnMainQueue).start(next: { peers in if let strongSelf = self { diff --git a/submodules/StatisticsUI/Sources/GroupStatsController.swift b/submodules/StatisticsUI/Sources/GroupStatsController.swift index 7370caed78..d2fc365197 100644 --- a/submodules/StatisticsUI/Sources/GroupStatsController.swift +++ b/submodules/StatisticsUI/Sources/GroupStatsController.swift @@ -901,7 +901,7 @@ public func groupStatsController(context: AccountContext, peerId: PeerId, cached } promotePeerImpl = { [weak controller] participantPeerId in if let navigationController = controller?.navigationController as? NavigationController { - let _ = (fetchChannelParticipant(account: context.account, peerId: peerId, participantId: participantPeerId) + let _ = (context.engine.peers.fetchChannelParticipant(peerId: peerId, participantId: participantPeerId) |> take(1) |> deliverOnMainQueue).start(next: { participant in if let participant = participant, let controller = context.sharedContext.makeChannelAdminController(context: context, peerId: peerId, adminId: participantPeerId, initialParticipant: participant) { diff --git a/submodules/TelegramCore/Sources/AddPeerMember.swift b/submodules/TelegramCore/Sources/AddPeerMember.swift index f58bdc6e24..871b3285c3 100644 --- a/submodules/TelegramCore/Sources/AddPeerMember.swift +++ b/submodules/TelegramCore/Sources/AddPeerMember.swift @@ -80,7 +80,7 @@ public enum AddChannelMemberError { } public func addChannelMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal<(ChannelParticipant?, RenderedChannelParticipant), AddChannelMemberError> { - return fetchChannelParticipant(account: account, peerId: peerId, participantId: memberId) + return _internal_fetchChannelParticipant(account: account, peerId: peerId, participantId: memberId) |> mapError { error -> AddChannelMemberError in } |> mapToSignal { currentParticipant -> Signal<(ChannelParticipant?, RenderedChannelParticipant), AddChannelMemberError> in diff --git a/submodules/TelegramCore/Sources/MediaResourceApiUtils.swift b/submodules/TelegramCore/Sources/ApiUtils/MediaResourceApiUtils.swift similarity index 100% rename from submodules/TelegramCore/Sources/MediaResourceApiUtils.swift rename to submodules/TelegramCore/Sources/ApiUtils/MediaResourceApiUtils.swift diff --git a/submodules/TelegramCore/Sources/RegisterNotificationToken.swift b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/RegisterNotificationToken.swift similarity index 79% rename from submodules/TelegramCore/Sources/RegisterNotificationToken.swift rename to submodules/TelegramCore/Sources/TelegramEngine/AccountData/RegisterNotificationToken.swift index 5d6ee65829..9349247abb 100644 --- a/submodules/TelegramCore/Sources/RegisterNotificationToken.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/RegisterNotificationToken.swift @@ -10,7 +10,7 @@ public enum NotificationTokenType { case voip } -public func unregisterNotificationToken(account: Account, token: Data, type: NotificationTokenType, otherAccountUserIds: [PeerId.Id]) -> Signal { +func _internal_unregisterNotificationToken(account: Account, token: Data, type: NotificationTokenType, otherAccountUserIds: [PeerId.Id]) -> Signal { let mappedType: Int32 switch type { case .aps: @@ -23,7 +23,7 @@ public func unregisterNotificationToken(account: Account, token: Data, type: Not |> ignoreValues } -public func registerNotificationToken(account: Account, token: Data, type: NotificationTokenType, sandbox: Bool, otherAccountUserIds: [PeerId.Id], excludeMutedChats: Bool) -> Signal { +func _internal_registerNotificationToken(account: Account, token: Data, type: NotificationTokenType, sandbox: Bool, otherAccountUserIds: [PeerId.Id], excludeMutedChats: Bool) -> Signal { return masterNotificationsKey(account: account, ignoreDisabled: false) |> mapToSignal { masterKey -> Signal in let mappedType: Int32 diff --git a/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift index f9a025c8b2..8ea9a469ae 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift @@ -1,4 +1,7 @@ +import Foundation import SwiftSignalKit +import Postbox +import SyncCore public extension TelegramEngine { final class AccountData { @@ -35,5 +38,13 @@ public extension TelegramEngine { public func updateAbout(about: String?) -> Signal { return _internal_updateAbout(account: self.account, about: about) } + + public func unregisterNotificationToken(token: Data, type: NotificationTokenType, otherAccountUserIds: [PeerId.Id]) -> Signal { + return _internal_unregisterNotificationToken(account: self.account, token: token, type: type, otherAccountUserIds: otherAccountUserIds) + } + + public func registerNotificationToken(token: Data, type: NotificationTokenType, sandbox: Bool, otherAccountUserIds: [PeerId.Id], excludeMutedChats: Bool) -> Signal { + return _internal_registerNotificationToken(account: self.account, token: token, type: type, sandbox: sandbox, otherAccountUserIds: otherAccountUserIds, excludeMutedChats: excludeMutedChats) + } } } diff --git a/submodules/TelegramCore/Sources/EarliestUnseenPersonalMentionMessage.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/EarliestUnseenPersonalMentionMessage.swift similarity index 95% rename from submodules/TelegramCore/Sources/EarliestUnseenPersonalMentionMessage.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/EarliestUnseenPersonalMentionMessage.swift index 54c5a0b320..d3aa62b2bf 100644 --- a/submodules/TelegramCore/Sources/EarliestUnseenPersonalMentionMessage.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/EarliestUnseenPersonalMentionMessage.swift @@ -10,7 +10,7 @@ public enum EarliestUnseenPersonalMentionMessageResult: Equatable { case result(MessageId?) } -public func earliestUnseenPersonalMentionMessage(account: Account, peerId: PeerId) -> Signal { +func _internal_earliestUnseenPersonalMentionMessage(account: Account, peerId: PeerId) -> Signal { return account.viewTracker.aroundMessageHistoryViewForLocation(.peer(peerId), index: .lowerBound, anchorIndex: .lowerBound, count: 4, fixedCombinedReadStates: nil, tagMask: .unseenPersonalMessage, additionalData: [.peerChatState(peerId)]) |> mapToSignal { view -> Signal in if view.0.isLoading { diff --git a/submodules/TelegramCore/Sources/InstallInteractiveReadMessagesAction.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/InstallInteractiveReadMessagesAction.swift similarity index 95% rename from submodules/TelegramCore/Sources/InstallInteractiveReadMessagesAction.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/InstallInteractiveReadMessagesAction.swift index fd5a79dc92..4b853a0b0f 100644 --- a/submodules/TelegramCore/Sources/InstallInteractiveReadMessagesAction.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/InstallInteractiveReadMessagesAction.swift @@ -5,7 +5,7 @@ import SwiftSignalKit import SyncCore -public func installInteractiveReadMessagesAction(postbox: Postbox, stateManager: AccountStateManager, peerId: PeerId) -> Disposable { +func _internal_installInteractiveReadMessagesAction(postbox: Postbox, stateManager: AccountStateManager, peerId: PeerId) -> Disposable { return postbox.installStoreMessageAction(peerId: peerId, { messages, transaction in var consumeMessageIds: [MessageId] = [] diff --git a/submodules/TelegramCore/Sources/MarkMessageContentAsConsumedInteractively.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/MarkMessageContentAsConsumedInteractively.swift similarity index 99% rename from submodules/TelegramCore/Sources/MarkMessageContentAsConsumedInteractively.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/MarkMessageContentAsConsumedInteractively.swift index 53a1202972..7a39d5bb17 100644 --- a/submodules/TelegramCore/Sources/MarkMessageContentAsConsumedInteractively.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/MarkMessageContentAsConsumedInteractively.swift @@ -5,7 +5,7 @@ import SwiftSignalKit import SyncCore -public func markMessageContentAsConsumedInteractively(postbox: Postbox, messageId: MessageId) -> Signal { +func _internal_markMessageContentAsConsumedInteractively(postbox: Postbox, messageId: MessageId) -> Signal { return postbox.transaction { transaction -> Void in if let message = transaction.getMessage(messageId), message.flags.contains(.Incoming) { var updateMessage = false diff --git a/submodules/TelegramCore/Sources/Polls.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Polls.swift similarity index 97% rename from submodules/TelegramCore/Sources/Polls.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/Polls.swift index b8228f08e5..6aefb2b7eb 100644 --- a/submodules/TelegramCore/Sources/Polls.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Polls.swift @@ -10,7 +10,7 @@ public enum RequestMessageSelectPollOptionError { case generic } -public func requestMessageSelectPollOption(account: Account, messageId: MessageId, opaqueIdentifiers: [Data]) -> Signal { +func _internal_requestMessageSelectPollOption(account: Account, messageId: MessageId, opaqueIdentifiers: [Data]) -> Signal { return account.postbox.loadedPeerWithId(messageId.peerId) |> take(1) |> castError(RequestMessageSelectPollOptionError.self) @@ -80,7 +80,7 @@ public func requestMessageSelectPollOption(account: Account, messageId: MessageI } } -public func requestClosePoll(postbox: Postbox, network: Network, stateManager: AccountStateManager, messageId: MessageId) -> Signal { +func _internal_requestClosePoll(postbox: Postbox, network: Network, stateManager: AccountStateManager, messageId: MessageId) -> Signal { return postbox.transaction { transaction -> (TelegramMediaPoll, Api.InputPeer)? in guard let inputPeer = transaction.getPeer(messageId.peerId).flatMap(apiInputPeer) else { return nil @@ -419,7 +419,7 @@ public final class PollResultsContext { } } - public init(account: Account, messageId: MessageId, poll: TelegramMediaPoll) { + init(account: Account, messageId: MessageId, poll: TelegramMediaPoll) { let queue = self.queue self.impl = QueueLocalObject(queue: queue, generate: { return PollResultsContextImpl(queue: queue, account: account, messageId: messageId, poll: poll) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/RequestStartBot.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/RequestStartBot.swift index d0081e14f2..9b46a05b71 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/RequestStartBot.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/RequestStartBot.swift @@ -55,7 +55,7 @@ func _internal_requestStartBotInGroup(account: Account, botPeerId: PeerId, group |> mapToSignal { result -> Signal in account.stateManager.addUpdates(result) if groupPeerId.namespace == Namespaces.Peer.CloudChannel { - return fetchChannelParticipant(account: account, peerId: groupPeerId, participantId: botPeerId) + return _internal_fetchChannelParticipant(account: account, peerId: groupPeerId, participantId: botPeerId) |> mapError { _ -> RequestStartBotInGroupError in return .generic } |> mapToSignal { participant -> Signal in diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift index c29e9cfed1..144bf90c38 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift @@ -1,3 +1,4 @@ +import Foundation import SwiftSignalKit import Postbox import SyncCore @@ -122,5 +123,29 @@ public extension TelegramEngine { public func getMessagesLoadIfNecessary(_ messageIds: [MessageId], strategy: GetMessagesStrategy = .cloud) -> Signal <[Message], NoError> { return _internal_getMessagesLoadIfNecessary(messageIds, postbox: self.account.postbox, network: self.account.network, accountPeerId: self.account.peerId, strategy: strategy) } + + public func markMessageContentAsConsumedInteractively(messageId: MessageId) -> Signal { + return _internal_markMessageContentAsConsumedInteractively(postbox: self.account.postbox, messageId: messageId) + } + + public func installInteractiveReadMessagesAction(peerId: PeerId) -> Disposable { + return _internal_installInteractiveReadMessagesAction(postbox: self.account.postbox, stateManager: self.account.stateManager, peerId: peerId) + } + + public func requestMessageSelectPollOption(messageId: MessageId, opaqueIdentifiers: [Data]) -> Signal { + return _internal_requestMessageSelectPollOption(account: self.account, messageId: messageId, opaqueIdentifiers: opaqueIdentifiers) + } + + public func requestClosePoll(messageId: MessageId) -> Signal { + return _internal_requestClosePoll(postbox: self.account.postbox, network: self.account.network, stateManager: self.account.stateManager, messageId: messageId) + } + + public func pollResults(messageId: MessageId, poll: TelegramMediaPoll) -> PollResultsContext { + return PollResultsContext(account: self.account, messageId: messageId, poll: poll) + } + + public func earliestUnseenPersonalMentionMessage(peerId: PeerId) -> Signal { + return _internal_earliestUnseenPersonalMentionMessage(account: self.account, peerId: peerId) + } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelBlacklist.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelBlacklist.swift index 7cab29aba5..91bd5c9ef3 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelBlacklist.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelBlacklist.swift @@ -6,7 +6,7 @@ import MtProtoKit import SyncCore func _internal_updateChannelMemberBannedRights(account: Account, peerId: PeerId, memberId: PeerId, rights: TelegramChatBannedRights?) -> Signal<(ChannelParticipant?, RenderedChannelParticipant?, Bool), NoError> { - return fetchChannelParticipant(account: account, peerId: peerId, participantId: memberId) + return _internal_fetchChannelParticipant(account: account, peerId: peerId, participantId: memberId) |> mapToSignal { currentParticipant -> Signal<(ChannelParticipant?, RenderedChannelParticipant?, Bool), NoError> in return account.postbox.transaction { transaction -> Signal<(ChannelParticipant?, RenderedChannelParticipant?, Bool), NoError> in if let peer = transaction.getPeer(peerId), let inputChannel = apiInputChannel(peer), let _ = transaction.getPeer(account.peerId), let memberPeer = transaction.getPeer(memberId), let inputPeer = apiInputPeer(memberPeer) { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelOwnershipTransfer.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelOwnershipTransfer.swift index 2abce2834d..8d57c103a8 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelOwnershipTransfer.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelOwnershipTransfer.swift @@ -77,7 +77,7 @@ func _internal_updateChannelOwnership(account: Account, accountStateManager: Acc return .fail(.invalidPassword) } - return combineLatest(fetchChannelParticipant(account: account, peerId: channelId, participantId: account.peerId), fetchChannelParticipant(account: account, peerId: channelId, participantId: memberId)) + return combineLatest(_internal_fetchChannelParticipant(account: account, peerId: channelId, participantId: account.peerId), _internal_fetchChannelParticipant(account: account, peerId: channelId, participantId: memberId)) |> mapError { error -> ChannelOwnershipTransferError in return .generic } diff --git a/submodules/TelegramCore/Sources/PeerAdmins.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/PeerAdmins.swift similarity index 95% rename from submodules/TelegramCore/Sources/PeerAdmins.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Peers/PeerAdmins.swift index 5f9c1f3f3f..e27931644d 100644 --- a/submodules/TelegramCore/Sources/PeerAdmins.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/PeerAdmins.swift @@ -10,7 +10,7 @@ public enum RemoveGroupAdminError { case generic } -public func removeGroupAdmin(account: Account, peerId: PeerId, adminId: PeerId) -> Signal { +func _internal_removeGroupAdmin(account: Account, peerId: PeerId, adminId: PeerId) -> Signal { return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId), let adminPeer = transaction.getPeer(adminId), let inputUser = apiInputUser(adminPeer) { if let group = peer as? TelegramGroup { @@ -58,7 +58,7 @@ public enum AddGroupAdminError { case adminsTooMuch } -public func addGroupAdmin(account: Account, peerId: PeerId, adminId: PeerId) -> Signal { +func _internal_addGroupAdmin(account: Account, peerId: PeerId, adminId: PeerId) -> Signal { return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId), let adminPeer = transaction.getPeer(adminId), let inputUser = apiInputUser(adminPeer) { if let group = peer as? TelegramGroup { @@ -127,7 +127,7 @@ public enum UpdateChannelAdminRightsError { case adminsTooMuch } -public func fetchChannelParticipant(account: Account, peerId: PeerId, participantId: PeerId) -> Signal { +func _internal_fetchChannelParticipant(account: Account, peerId: PeerId, participantId: PeerId) -> Signal { return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId), let adminPeer = transaction.getPeer(participantId), let inputPeer = apiInputPeer(adminPeer) { if let channel = peer as? TelegramChannel, let inputChannel = apiInputChannel(channel) { @@ -150,8 +150,8 @@ public func fetchChannelParticipant(account: Account, peerId: PeerId, participan } |> switchToLatest } -public func updateChannelAdminRights(account: Account, peerId: PeerId, adminId: PeerId, rights: TelegramChatAdminRights?, rank: String?) -> Signal<(ChannelParticipant?, RenderedChannelParticipant), UpdateChannelAdminRightsError> { - return fetchChannelParticipant(account: account, peerId: peerId, participantId: adminId) +func _internal_updateChannelAdminRights(account: Account, peerId: PeerId, adminId: PeerId, rights: TelegramChatAdminRights?, rank: String?) -> Signal<(ChannelParticipant?, RenderedChannelParticipant), UpdateChannelAdminRightsError> { + return _internal_fetchChannelParticipant(account: account, peerId: peerId, participantId: adminId) |> mapError { error -> UpdateChannelAdminRightsError in } |> mapToSignal { currentParticipant -> Signal<(ChannelParticipant?, RenderedChannelParticipant), UpdateChannelAdminRightsError> in diff --git a/submodules/TelegramCore/Sources/PeerSpecificStickerPack.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/PeerSpecificStickerPack.swift similarity index 93% rename from submodules/TelegramCore/Sources/PeerSpecificStickerPack.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Peers/PeerSpecificStickerPack.swift index acd61c4511..c50de3ef03 100644 --- a/submodules/TelegramCore/Sources/PeerSpecificStickerPack.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/PeerSpecificStickerPack.swift @@ -17,7 +17,7 @@ public struct PeerSpecificStickerPackData { public let canSetup: Bool } -public func peerSpecificStickerPack(postbox: Postbox, network: Network, peerId: PeerId) -> Signal { +func _internal_peerSpecificStickerPack(postbox: Postbox, network: Network, peerId: PeerId) -> Signal { if peerId.namespace == Namespaces.Peer.CloudChannel { let signal: Signal<(WrappedStickerPackCollectionInfo, Bool), NoError> = postbox.combinedView(keys: [.cachedPeerData(peerId: peerId)]) |> map { view -> (WrappedStickerPackCollectionInfo, Bool) in diff --git a/submodules/TelegramCore/Sources/RecentlySearchedPeerIds.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/RecentlySearchedPeerIds.swift similarity index 92% rename from submodules/TelegramCore/Sources/RecentlySearchedPeerIds.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Peers/RecentlySearchedPeerIds.swift index ad9544f4dc..f54fc35884 100644 --- a/submodules/TelegramCore/Sources/RecentlySearchedPeerIds.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/RecentlySearchedPeerIds.swift @@ -4,19 +4,19 @@ import SwiftSignalKit import SyncCore -public func addRecentlySearchedPeer(postbox: Postbox, peerId: PeerId) -> Signal { +func _internal_addRecentlySearchedPeer(postbox: Postbox, peerId: PeerId) -> Signal { return postbox.transaction { transaction -> Void in transaction.addOrMoveToFirstPositionOrderedItemListItem(collectionId: Namespaces.OrderedItemList.RecentlySearchedPeerIds, item: OrderedItemListEntry(id: RecentPeerItemId(peerId).rawValue, contents: RecentPeerItem(rating: 0.0)), removeTailIfCountExceeds: 20) } } -public func removeRecentlySearchedPeer(postbox: Postbox, peerId: PeerId) -> Signal { +func _internal_removeRecentlySearchedPeer(postbox: Postbox, peerId: PeerId) -> Signal { return postbox.transaction { transaction -> Void in transaction.removeOrderedItemListItem(collectionId: Namespaces.OrderedItemList.RecentlySearchedPeerIds, itemId: RecentPeerItemId(peerId).rawValue) } } -public func clearRecentlySearchedPeers(postbox: Postbox) -> Signal { +func _internal_clearRecentlySearchedPeers(postbox: Postbox) -> Signal { return postbox.transaction { transaction -> Void in transaction.replaceOrderedItemListItems(collectionId: Namespaces.OrderedItemList.RecentlySearchedPeerIds, items: []) } @@ -34,7 +34,7 @@ public struct RecentlySearchedPeer: Equatable { public let subpeerSummary: RecentlySearchedPeerSubpeerSummary? } -public func recentlySearchedPeers(postbox: Postbox) -> Signal<[RecentlySearchedPeer], NoError> { +func _internal_recentlySearchedPeers(postbox: Postbox) -> Signal<[RecentlySearchedPeer], NoError> { return postbox.combinedView(keys: [.orderedItemList(id: Namespaces.OrderedItemList.RecentlySearchedPeerIds)]) |> mapToSignal { view -> Signal<[RecentlySearchedPeer], NoError> in var peerIds: [PeerId] = [] diff --git a/submodules/TelegramCore/Sources/RemovePeerChat.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/RemovePeerChat.swift similarity index 87% rename from submodules/TelegramCore/Sources/RemovePeerChat.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Peers/RemovePeerChat.swift index 1b72cd2cdd..f5c31ba638 100644 --- a/submodules/TelegramCore/Sources/RemovePeerChat.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/RemovePeerChat.swift @@ -4,13 +4,13 @@ import SwiftSignalKit import SyncCore -public func removePeerChat(account: Account, peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool = false) -> Signal { +func _internal_removePeerChat(account: Account, peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool = false) -> Signal { return account.postbox.transaction { transaction -> Void in - removePeerChat(account: account, transaction: transaction, mediaBox: account.postbox.mediaBox, peerId: peerId, reportChatSpam: reportChatSpam, deleteGloballyIfPossible: deleteGloballyIfPossible) + _internal_removePeerChat(account: account, transaction: transaction, mediaBox: account.postbox.mediaBox, peerId: peerId, reportChatSpam: reportChatSpam, deleteGloballyIfPossible: deleteGloballyIfPossible) } } -public func terminateSecretChat(transaction: Transaction, peerId: PeerId, requestRemoteHistoryRemoval: Bool) { +func _internal_terminateSecretChat(transaction: Transaction, peerId: PeerId, requestRemoteHistoryRemoval: Bool) { if let state = transaction.getPeerChatState(peerId) as? SecretChatState, state.embeddedState != .terminated { let updatedState = addSecretChatOutgoingOperation(transaction: transaction, peerId: peerId, operation: SecretChatOutgoingOperationContents.terminate(reportSpam: false, requestRemoteHistoryRemoval: requestRemoteHistoryRemoval), state: state).withUpdatedEmbeddedState(.terminated) if updatedState != state { @@ -24,7 +24,7 @@ public func terminateSecretChat(transaction: Transaction, peerId: PeerId, reques } } -public func removePeerChat(account: Account, transaction: Transaction, mediaBox: MediaBox, peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool) { +func _internal_removePeerChat(account: Account, transaction: Transaction, mediaBox: MediaBox, peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool) { if let _ = transaction.getPeerChatInterfaceState(peerId) { transaction.updatePeerChatInterfaceState(peerId, update: { current in if let current = current { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift index 312e3aeae2..23e6f94320 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift @@ -231,5 +231,61 @@ public extension TelegramEngine { public func peerCommands(id: PeerId) -> Signal { return _internal_peerCommands(account: self.account, id: id) } + + public func addGroupAdmin(peerId: PeerId, adminId: PeerId) -> Signal { + return _internal_addGroupAdmin(account: self.account, peerId: peerId, adminId: adminId) + } + + public func removeGroupAdmin(peerId: PeerId, adminId: PeerId) -> Signal { + return _internal_removeGroupAdmin(account: self.account, peerId: peerId, adminId: adminId) + } + + public func fetchChannelParticipant(peerId: PeerId, participantId: PeerId) -> Signal { + return _internal_fetchChannelParticipant(account: self.account, peerId: peerId, participantId: participantId) + } + + public func updateChannelAdminRights(peerId: PeerId, adminId: PeerId, rights: TelegramChatAdminRights?, rank: String?) -> Signal<(ChannelParticipant?, RenderedChannelParticipant), UpdateChannelAdminRightsError> { + return _internal_updateChannelAdminRights(account: self.account, peerId: peerId, adminId: adminId, rights: rights, rank: rank) + } + + public func peerSpecificStickerPack(peerId: PeerId) -> Signal { + return _internal_peerSpecificStickerPack(postbox: self.account.postbox, network: self.account.network, peerId: peerId) + } + + public func addRecentlySearchedPeer(peerId: PeerId) -> Signal { + return _internal_addRecentlySearchedPeer(postbox: self.account.postbox, peerId: peerId) + } + + public func removeRecentlySearchedPeer(peerId: PeerId) -> Signal { + return _internal_removeRecentlySearchedPeer(postbox: self.account.postbox, peerId: peerId) + } + + public func clearRecentlySearchedPeers() -> Signal { + return _internal_clearRecentlySearchedPeers(postbox: self.account.postbox) + } + + public func recentlySearchedPeers() -> Signal<[RecentlySearchedPeer], NoError> { + return _internal_recentlySearchedPeers(postbox: self.account.postbox) + } + + public func removePeerChat(peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool = false) -> Signal { + return _internal_removePeerChat(account: self.account, peerId: peerId, reportChatSpam: reportChatSpam, deleteGloballyIfPossible: deleteGloballyIfPossible) + } + + public func removePeerChats(peerIds: [PeerId]) -> Signal { + return self.account.postbox.transaction { transaction -> Void in + for peerId in peerIds { + _internal_removePeerChat(account: self.account, transaction: transaction, mediaBox: self.account.postbox.mediaBox, peerId: peerId, reportChatSpam: false, deleteGloballyIfPossible: peerId.namespace == Namespaces.Peer.SecretChat) + } + } + |> ignoreValues + } + + public func terminateSecretChat(peerId: PeerId, requestRemoteHistoryRemoval: Bool) -> Signal { + return self.account.postbox.transaction { transaction -> Void in + _internal_terminateSecretChat(transaction: transaction, peerId: peerId, requestRemoteHistoryRemoval: requestRemoteHistoryRemoval) + } + |> ignoreValues + } } } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index a89c916c27..f14b19780d 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -2281,7 +2281,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G disposables = DisposableDict() strongSelf.selectMessagePollOptionDisposables = disposables } - let signal = requestMessageSelectPollOption(account: strongSelf.context.account, messageId: id, opaqueIdentifiers: opaqueIdentifiers) + let signal = strongSelf.context.engine.messages.requestMessageSelectPollOption(messageId: id, opaqueIdentifiers: opaqueIdentifiers) disposables.set((signal |> deliverOnMainQueue).start(next: { resultPoll in guard let strongSelf = self, let resultPoll = resultPoll else { @@ -4909,7 +4909,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G self.chatDisplayNode.navigateButtons.mentionsPressed = { [weak self] in if let strongSelf = self, strongSelf.isNodeLoaded, case let .peer(peerId) = strongSelf.chatLocation { - let signal = earliestUnseenPersonalMentionMessage(account: strongSelf.context.account, peerId: peerId) + let signal = strongSelf.context.engine.messages.earliestUnseenPersonalMentionMessage(peerId: peerId) strongSelf.navigationActionDisposable.set((signal |> deliverOnMainQueue).start(next: { result in if let strongSelf = self { switch result { @@ -6385,7 +6385,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } let controller = OverlayStatusController(theme: strongSelf.presentationData.theme, type: .loading(cancelled: nil)) strongSelf.present(controller, in: .window(.root)) - let signal = requestMessageSelectPollOption(account: strongSelf.context.account, messageId: id, opaqueIdentifiers: []) + let signal = strongSelf.context.engine.messages.requestMessageSelectPollOption(messageId: id, opaqueIdentifiers: []) |> afterDisposed { [weak controller] in Queue.mainQueue().async { controller?.dismiss() @@ -6447,7 +6447,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } let controller = OverlayStatusController(theme: strongSelf.presentationData.theme, type: .loading(cancelled: nil)) strongSelf.present(controller, in: .window(.root)) - let signal = requestClosePoll(postbox: strongSelf.context.account.postbox, network: strongSelf.context.account.network, stateManager: strongSelf.context.account.stateManager, messageId: id) + let signal = strongSelf.context.engine.messages.requestClosePoll(messageId: id) |> afterDisposed { [weak controller] in Queue.mainQueue().async { controller?.dismiss() @@ -11421,12 +11421,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } let _ = strongSelf.context.engine.privacy.requestUpdatePeerIsBlocked(peerId: peer.id, isBlocked: true).start() if let _ = chatPeer as? TelegramSecretChat { - let _ = (strongSelf.context.account.postbox.transaction { transaction in - terminateSecretChat(transaction: transaction, peerId: chatPeer.id, requestRemoteHistoryRemoval: true) - }).start() + let _ = strongSelf.context.engine.peers.terminateSecretChat(peerId: chatPeer.id, requestRemoteHistoryRemoval: true).start() } if deleteChat { - let _ = removePeerChat(account: strongSelf.context.account, peerId: chatPeer.id, reportChatSpam: reportSpam).start() + let _ = strongSelf.context.engine.peers.removePeerChat(peerId: chatPeer.id, reportChatSpam: reportSpam).start() strongSelf.effectiveNavigationController?.filterController(strongSelf, animated: true) } else if reportSpam { let _ = strongSelf.context.engine.peers.reportPeer(peerId: peer.id, reason: .spam, message: "").start() @@ -11562,7 +11560,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } self.commitPurposefulAction() self.chatDisplayNode.historyNode.disconnect() - let _ = removePeerChat(account: self.context.account, peerId: peerId, reportChatSpam: reportChatSpam).start() + let _ = self.context.engine.peers.removePeerChat(peerId: peerId, reportChatSpam: reportChatSpam).start() self.effectiveNavigationController?.popToRoot(animated: true) let _ = self.context.engine.privacy.requestUpdatePeerIsBlocked(peerId: peerId, isBlocked: true).start() @@ -11808,7 +11806,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G private func presentBanMessageOptions(accountPeerId: PeerId, author: Peer, messageIds: Set, options: ChatAvailableMessageActionOptions) { let peerId = self.chatLocation.peerId do { - self.navigationActionDisposable.set((fetchChannelParticipant(account: self.context.account, peerId: peerId, participantId: author.id) + self.navigationActionDisposable.set((self.context.engine.peers.fetchChannelParticipant(peerId: peerId, participantId: author.id) |> deliverOnMainQueue).start(next: { [weak self] participant in if let strongSelf = self { let canBan = participant?.canBeBannedBy(peerId: accountPeerId) ?? true diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index 402a41e116..383e50988d 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -2001,7 +2001,7 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { } else if self.interactiveReadActionDisposable == nil { if case let .peer(peerId) = self.chatLocation { if !self.context.sharedContext.immediateExperimentalUISettings.skipReadHistory { - self.interactiveReadActionDisposable = installInteractiveReadMessagesAction(postbox: self.context.account.postbox, stateManager: self.context.account.stateManager, peerId: peerId) + self.interactiveReadActionDisposable = self.context.engine.messages.installInteractiveReadMessagesAction(peerId: peerId) } } } diff --git a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift index e69da972e9..c514206dbb 100644 --- a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift +++ b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift @@ -772,7 +772,7 @@ final class ChatMediaInputNode: ChatInputNode { return false }) - peerSpecificPack = combineLatest(peerSpecificStickerPack(postbox: context.account.postbox, network: context.account.network, peerId: peerId), context.account.postbox.multiplePeersView([peerId]), self.dismissedPeerSpecificStickerPack.get()) + peerSpecificPack = combineLatest(context.engine.peers.peerSpecificStickerPack(peerId: peerId), context.account.postbox.multiplePeersView([peerId]), self.dismissedPeerSpecificStickerPack.get()) |> map { packData, peersView, dismissedPeerSpecificPack -> (PeerSpecificPackData?, CanInstallPeerSpecificPack) in if let peer = peersView.peers[peerId] { var canInstall: CanInstallPeerSpecificPack = .none diff --git a/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift b/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift index 95d171f0d6..5c0076a5bb 100644 --- a/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift @@ -839,7 +839,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { if canBan { actions.append(ContextMenuAction(content: .text(title: self.presentationData.strings.Conversation_ContextMenuBan, accessibilityLabel: self.presentationData.strings.Conversation_ContextMenuBan), action: { [weak self] in if let strongSelf = self { - strongSelf.banDisposables.set((fetchChannelParticipant(account: strongSelf.context.account, peerId: strongSelf.peer.id, participantId: author.id) + strongSelf.banDisposables.set((strongSelf.context.engine.peers.fetchChannelParticipant(peerId: strongSelf.peer.id, participantId: author.id) |> deliverOnMainQueue).start(next: { participant in if let strongSelf = self { strongSelf.presentController(channelBannedMemberController(context: strongSelf.context, peerId: strongSelf.peer.id, memberId: author.id, initialParticipant: participant, updated: { _ in }, upgradedToSupergroup: { _, f in f() }), .window(.root), ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index c09507fd58..d5f10e6eec 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -4294,7 +4294,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD strongSelf.activeActionDisposable.set(strongSelf.context.engine.privacy.requestUpdatePeerIsBlocked(peerId: peer.id, isBlocked: true).start()) if deleteChat { - let _ = removePeerChat(account: strongSelf.context.account, peerId: strongSelf.peerId, reportChatSpam: reportSpam).start() + let _ = strongSelf.context.engine.peers.removePeerChat(peerId: strongSelf.peerId, reportChatSpam: reportSpam).start() (strongSelf.controller?.navigationController as? NavigationController)?.popToRoot(animated: true) } else if reportSpam { let _ = strongSelf.context.engine.peers.reportPeer(peerId: strongSelf.peerId, reason: .spam, message: "").start() diff --git a/submodules/TelegramUI/Sources/PeerMessagesMediaPlaylist.swift b/submodules/TelegramUI/Sources/PeerMessagesMediaPlaylist.swift index 28f65a474c..f6aade2b53 100644 --- a/submodules/TelegramUI/Sources/PeerMessagesMediaPlaylist.swift +++ b/submodules/TelegramUI/Sources/PeerMessagesMediaPlaylist.swift @@ -808,7 +808,7 @@ final class PeerMessagesMediaPlaylist: SharedMediaPlaylist { default: break } - let _ = markMessageContentAsConsumedInteractively(postbox: self.context.account.postbox, messageId: item.message.id).start() + let _ = self.context.engine.messages.markMessageContentAsConsumedInteractively(messageId: item.message.id).start() } } } diff --git a/submodules/TelegramUI/Sources/PollResultsController.swift b/submodules/TelegramUI/Sources/PollResultsController.swift index 1efa4db7d6..69c0c154b0 100644 --- a/submodules/TelegramUI/Sources/PollResultsController.swift +++ b/submodules/TelegramUI/Sources/PollResultsController.swift @@ -323,7 +323,7 @@ public func pollResultsController(context: AccountContext, messageId: MessageId, let actionsDisposable = DisposableSet() - let resultsContext = PollResultsContext(account: context.account, messageId: messageId, poll: poll) + let resultsContext = context.engine.messages.pollResults(messageId: messageId, poll: poll) let arguments = PollResultsControllerArguments(context: context, collapseOption: { optionId in diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index 5f2eac1bf6..7e98762c38 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -867,7 +867,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { guard let token = token else { return .complete() } - return unregisterNotificationToken(account: account, token: token, type: .aps(encrypt: false), otherAccountUserIds: (account.testingEnvironment ? allTestingUserIds : allProductionUserIds).filter({ $0 != account.peerId.id })) + return TelegramEngine(account: account).accountData.unregisterNotificationToken(token: token, type: .aps(encrypt: false), otherAccountUserIds: (account.testingEnvironment ? allTestingUserIds : allProductionUserIds).filter({ $0 != account.peerId.id })) } appliedVoip = self.voipNotificationToken |> distinctUntilChanged(isEqual: { $0 == $1 }) @@ -875,7 +875,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { guard let token = token else { return .complete() } - return unregisterNotificationToken(account: account, token: token, type: .voip, otherAccountUserIds: (account.testingEnvironment ? allTestingUserIds : allProductionUserIds).filter({ $0 != account.peerId.id })) + return TelegramEngine(account: account).accountData.unregisterNotificationToken(token: token, type: .voip, otherAccountUserIds: (account.testingEnvironment ? allTestingUserIds : allProductionUserIds).filter({ $0 != account.peerId.id })) } } else { appliedAps = self.apsNotificationToken @@ -890,7 +890,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { } else { encrypt = false } - return registerNotificationToken(account: account, token: token, type: .aps(encrypt: encrypt), sandbox: sandbox, otherAccountUserIds: (account.testingEnvironment ? activeTestingUserIds : activeProductionUserIds).filter({ $0 != account.peerId.id }), excludeMutedChats: !settings.includeMuted) + return TelegramEngine(account: account).accountData.registerNotificationToken(token: token, type: .aps(encrypt: encrypt), sandbox: sandbox, otherAccountUserIds: (account.testingEnvironment ? activeTestingUserIds : activeProductionUserIds).filter({ $0 != account.peerId.id }), excludeMutedChats: !settings.includeMuted) } appliedVoip = self.voipNotificationToken |> distinctUntilChanged(isEqual: { $0 == $1 }) @@ -898,7 +898,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { guard let token = token else { return .complete() } - return registerNotificationToken(account: account, token: token, type: .voip, sandbox: sandbox, otherAccountUserIds: (account.testingEnvironment ? activeTestingUserIds : activeProductionUserIds).filter({ $0 != account.peerId.id }), excludeMutedChats: !settings.includeMuted) + return TelegramEngine(account: account).accountData.registerNotificationToken(token: token, type: .voip, sandbox: sandbox, otherAccountUserIds: (account.testingEnvironment ? activeTestingUserIds : activeProductionUserIds).filter({ $0 != account.peerId.id }), excludeMutedChats: !settings.includeMuted) } } diff --git a/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift b/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift index 7ec4920062..4a3c25ab61 100644 --- a/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift +++ b/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift @@ -378,8 +378,8 @@ public final class PeerChannelMemberCategoriesContextsManager { } } - public func updateMemberAdminRights(account: Account, peerId: PeerId, memberId: PeerId, adminRights: TelegramChatAdminRights?, rank: String?) -> Signal { - return updateChannelAdminRights(account: account, peerId: peerId, adminId: memberId, rights: adminRights, rank: rank) + public func updateMemberAdminRights(engine: TelegramEngine, peerId: PeerId, memberId: PeerId, adminRights: TelegramChatAdminRights?, rank: String?) -> Signal { + return engine.peers.updateChannelAdminRights(peerId: peerId, adminId: memberId, rights: adminRights, rank: rank) |> map(Optional.init) |> deliverOnMainQueue |> beforeNext { [weak self] result in