diff --git a/Telegram/SiriIntents/IntentHandler.swift b/Telegram/SiriIntents/IntentHandler.swift index deeca75664..9429b3d762 100644 --- a/Telegram/SiriIntents/IntentHandler.swift +++ b/Telegram/SiriIntents/IntentHandler.swift @@ -1048,7 +1048,7 @@ private final class WidgetIntentHandler { accountResults.append(accountTransaction(rootPath: rootPath, id: accountId, encryptionParameters: encryptionParameters, isReadOnly: true, useCopy: false, transaction: { postbox, transaction -> [Friend] in var peers: [Peer] = [] - for id in getRecentPeers(transaction: transaction) { + for id in _internal_getRecentPeers(transaction: transaction) { if let peer = transaction.getPeer(id), !(peer is TelegramSecretChat), !peer.isDeleted { peers.append(peer) } diff --git a/submodules/ChatListSearchRecentPeersNode/Sources/ChatListSearchRecentPeersNode.swift b/submodules/ChatListSearchRecentPeersNode/Sources/ChatListSearchRecentPeersNode.swift index eef6e3b9ab..5cc3470630 100644 --- a/submodules/ChatListSearchRecentPeersNode/Sources/ChatListSearchRecentPeersNode.swift +++ b/submodules/ChatListSearchRecentPeersNode/Sources/ChatListSearchRecentPeersNode.swift @@ -150,7 +150,7 @@ public final class ChatListSearchRecentPeersNode: ASDisplayNode { let peersDisposable = DisposableSet() - let recent: Signal<([Peer], [PeerId: (Int32, Bool)], [PeerId : PeerPresence]), NoError> = recentPeers(account: context.account) + let recent: Signal<([Peer], [PeerId: (Int32, Bool)], [PeerId : PeerPresence]), NoError> = context.engine.peers.recentPeers() |> filter { value -> Bool in switch value { case .disabled: @@ -224,7 +224,7 @@ public final class ChatListSearchRecentPeersNode: ASDisplayNode { } })) if case .actionSheet = mode { - peersDisposable.add(managedUpdatedRecentPeers(accountPeerId: context.account.peerId, postbox: context.account.postbox, network: context.account.network).start()) + peersDisposable.add(context.engine.peers.managedUpdatedRecentPeers().start()) } self.disposable.set(peersDisposable) } diff --git a/submodules/ChatListUI/Sources/ChatContextMenus.swift b/submodules/ChatListUI/Sources/ChatContextMenus.swift index e33fe9e2b3..9c97c1d8bc 100644 --- a/submodules/ChatListUI/Sources/ChatContextMenus.swift +++ b/submodules/ChatListUI/Sources/ChatContextMenus.swift @@ -60,7 +60,7 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch switch search { case .recentPeers: 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 _ = (removeRecentPeer(account: context.account, peerId: peerId) + let _ = (context.engine.peers.removeRecentPeer(peerId: peerId) |> deliverOnMainQueue).start(completed: { f(.default) }) diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 97130371d5..f1236b8fbb 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -744,7 +744,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController actionSheet?.dismissAnimated() if let strongSelf = self { - let _ = removeRecentPeer(account: strongSelf.context.account, peerId: peer.id).start() + let _ = strongSelf.context.engine.peers.removeRecentPeer(peerId: peer.id).start() } }) ]), diff --git a/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift b/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift index c7da79e5f3..04aba83ef0 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift @@ -1395,7 +1395,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { })) let previousRecentItems = Atomic<[ChatListRecentEntry]?>(value: nil) - let hasRecentPeers = recentPeers(account: context.account) + let hasRecentPeers = context.engine.peers.recentPeers() |> map { value -> Bool in switch value { case let .peers(peers): @@ -1465,7 +1465,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { } if tagMask == nil && !peersFilter.contains(.excludeRecent) { - self.updatedRecentPeersDisposable.set(managedUpdatedRecentPeers(accountPeerId: context.account.peerId, postbox: context.account.postbox, network: context.account.network).start()) + self.updatedRecentPeersDisposable.set(context.engine.peers.managedUpdatedRecentPeers().start()) } self.recentDisposable.set((combineLatest(queue: .mainQueue(), diff --git a/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift b/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift index 0e07ad58f6..9a180f0474 100644 --- a/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift @@ -391,7 +391,7 @@ public func channelBlacklistController(context: AccountContext, peerId: PeerId) let signal = context.peerChannelMemberCategoriesContextsManager.updateMemberBannedRights(engine: context.engine, peerId: peerId, memberId: memberId, bannedRights: nil) |> ignoreValues |> then( - context.peerChannelMemberCategoriesContextsManager.addMember(account: context.account, peerId: peerId, memberId: memberId) + context.peerChannelMemberCategoriesContextsManager.addMember(engine: context.engine, peerId: peerId, memberId: memberId) |> map { _ -> Void in return Void() } diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersController.swift b/submodules/PeerInfoUI/Sources/ChannelMembersController.swift index 575bc0ae00..dc424cb6ad 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersController.swift @@ -359,7 +359,7 @@ public func channelMembersController(context: AccountContext, peerId: PeerId) -> contacts = peerIdsValue } - let signal = context.peerChannelMemberCategoriesContextsManager.addMembers(account: context.account, peerId: peerId, memberIds: contacts.compactMap({ contact -> PeerId? in + let signal = context.peerChannelMemberCategoriesContextsManager.addMembers(engine: context.engine, peerId: peerId, memberIds: contacts.compactMap({ contact -> PeerId? in switch contact { case let .peer(contactId): return contactId diff --git a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift index 421fc2e13b..d00f4c957e 100644 --- a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift @@ -1357,7 +1357,7 @@ public func channelVisibilityController(context: AccountContext, peerId: PeerId, context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, chatController: nil, context: context, chatLocation: .peer(peerId), keepStack: .never, animated: true)) } else { selectionController.displayProgress = true - let _ = (addChannelMembers(account: context.account, peerId: peerId, memberIds: filteredPeerIds) + let _ = (context.engine.peers.addChannelMembers(peerId: peerId, memberIds: filteredPeerIds) |> deliverOnMainQueue).start(error: { [weak selectionController] _ in guard let selectionController = selectionController, let navigationController = selectionController.navigationController as? NavigationController else { return diff --git a/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift index f54573fca9..f8803407b2 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift @@ -453,7 +453,7 @@ public func dataPrivacyController(context: AccountContext) -> ViewController { state.updatedSuggestFrequentContacts = value return state } - let _ = updateRecentPeersEnabled(postbox: context.account.postbox, network: context.account.network, enabled: value).start() + let _ = context.engine.peers.updateRecentPeersEnabled(enabled: value).start() } if !value { let presentationData = context.sharedContext.currentPresentationData.with { $0 } @@ -503,9 +503,9 @@ public func dataPrivacyController(context: AccountContext) -> ViewController { let previousState = Atomic(value: nil) - actionsDisposable.add(managedUpdatedRecentPeers(accountPeerId: context.account.peerId, postbox: context.account.postbox, network: context.account.network).start()) + actionsDisposable.add(context.engine.peers.managedUpdatedRecentPeers().start()) - let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.secretChatLinkPreviewsKey()), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]), context.account.postbox.preferencesView(keys: [PreferencesKeys.contactsSettings]), recentPeers(account: context.account)) + let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.secretChatLinkPreviewsKey()), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]), context.account.postbox.preferencesView(keys: [PreferencesKeys.contactsSettings]), context.engine.peers.recentPeers()) |> map { presentationData, state, noticeView, sharedData, preferences, recentPeers -> (ItemListControllerState, (ItemListNodeState, Any)) in let secretChatLinkPreviews = noticeView.value.flatMap({ ApplicationSpecificNotice.getSecretChatLinkPreviews($0) }) diff --git a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift index ffd1980235..159a986e3c 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift @@ -851,7 +851,7 @@ public func privacyAndSecurityController(context: AccountContext, initialSetting pushControllerImpl?(dataPrivacyController(context: context), true) }) - actionsDisposable.add(managedUpdatedRecentPeers(accountPeerId: context.account.peerId, postbox: context.account.postbox, network: context.account.network).start()) + actionsDisposable.add(context.engine.peers.managedUpdatedRecentPeers().start()) actionsDisposable.add((privacySettingsPromise.get() |> deliverOnMainQueue).start(next: { settings in @@ -865,7 +865,7 @@ public func privacyAndSecurityController(context: AccountContext, initialSetting let preferencesKey: PostboxViewKey = .preferences(keys: Set([PreferencesKeys.appConfiguration])) - let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), privacySettingsPromise.get(), context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.secretChatLinkPreviewsKey()), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]), recentPeers(account: context.account), blockedPeersState.get(), webSessionsContext.state, context.sharedContext.accountManager.accessChallengeData(), combineLatest(twoStepAuth.get(), twoStepAuthDataValue.get()), context.account.postbox.combinedView(keys: [preferencesKey])) + let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), privacySettingsPromise.get(), context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.secretChatLinkPreviewsKey()), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]), context.engine.peers.recentPeers(), blockedPeersState.get(), webSessionsContext.state, context.sharedContext.accountManager.accessChallengeData(), combineLatest(twoStepAuth.get(), twoStepAuthDataValue.get()), context.account.postbox.combinedView(keys: [preferencesKey])) |> map { presentationData, state, privacySettings, noticeView, sharedData, recentPeers, blockedPeersState, activeWebsitesState, accessChallengeData, twoStepAuth, preferences -> (ItemListControllerState, (ItemListNodeState, Any)) in var canAutoarchive = false if let view = preferences.views[preferencesKey] as? PreferencesView, let appConfiguration = view.values[PreferencesKeys.appConfiguration] as? AppConfiguration, let data = appConfiguration.data, let hasAutoarchive = data["autoarchive_setting_available"] as? Bool { diff --git a/submodules/ShareController/Sources/ShareController.swift b/submodules/ShareController/Sources/ShareController.swift index 73d537fed4..081faecd24 100644 --- a/submodules/ShareController/Sources/ShareController.swift +++ b/submodules/ShareController/Sources/ShareController.swift @@ -435,7 +435,7 @@ public final class ShareController: ViewController { guard let strongSelf = self else { return } - let _ = (exportMessageLink(account: strongSelf.currentAccount, peerId: chatPeer.id, messageId: message.id) + let _ = (TelegramEngine(account: strongSelf.currentAccount).messages.exportMessageLink(peerId: chatPeer.id, messageId: message.id) |> map { result -> String? in return result } diff --git a/submodules/ShareController/Sources/ShareSearchContainerNode.swift b/submodules/ShareController/Sources/ShareSearchContainerNode.swift index f585d685f3..51dac1c75d 100644 --- a/submodules/ShareController/Sources/ShareSearchContainerNode.swift +++ b/submodules/ShareController/Sources/ShareSearchContainerNode.swift @@ -333,7 +333,7 @@ final class ShareSearchContainerNode: ASDisplayNode, ShareContentContainerNode { self?.searchQuery.set(text) } - let hasRecentPeers = recentPeers(account: context.account) + let hasRecentPeers = context.engine.peers.recentPeers() |> map { value -> Bool in switch value { case let .peers(peers): diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index 1f8817c752..984fcb65d2 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -1286,7 +1286,7 @@ public final class VoiceChatController: ViewController { if let groupPeer = groupPeer as? TelegramChannel { let selfController = strongSelf.controller let inviteDisposable = strongSelf.inviteDisposable - var inviteSignal = strongSelf.context.peerChannelMemberCategoriesContextsManager.addMembers(account: strongSelf.context.account, peerId: groupPeer.id, memberIds: [peer.id]) + var inviteSignal = strongSelf.context.peerChannelMemberCategoriesContextsManager.addMembers(engine: strongSelf.context.engine, peerId: groupPeer.id, memberIds: [peer.id]) var cancelImpl: (() -> Void)? let progressSignal = Signal { [weak selfController] subscriber in let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: { @@ -1358,7 +1358,7 @@ public final class VoiceChatController: ViewController { } else if let groupPeer = groupPeer as? TelegramGroup { let selfController = strongSelf.controller let inviteDisposable = strongSelf.inviteDisposable - var inviteSignal = addGroupMember(account: strongSelf.context.account, peerId: groupPeer.id, memberId: peer.id) + var inviteSignal = strongSelf.context.engine.peers.addGroupMember(peerId: groupPeer.id, memberId: peer.id) var cancelImpl: (() -> Void)? let progressSignal = Signal { [weak selfController] subscriber in let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: { diff --git a/submodules/TelegramCore/Sources/Account/Account.swift b/submodules/TelegramCore/Sources/Account/Account.swift index 60a3bb4429..cfe5c2e9f2 100644 --- a/submodules/TelegramCore/Sources/Account/Account.swift +++ b/submodules/TelegramCore/Sources/Account/Account.swift @@ -1055,7 +1055,7 @@ public class Account { self.managedOperationsDisposable.add(managedSynchronizeRecentlyUsedMediaOperations(postbox: self.postbox, network: self.network, category: .stickers, revalidationContext: self.mediaReferenceRevalidationContext).start()) self.managedOperationsDisposable.add(managedSynchronizeSavedGifsOperations(postbox: self.postbox, network: self.network, revalidationContext: self.mediaReferenceRevalidationContext).start()) self.managedOperationsDisposable.add(managedSynchronizeSavedStickersOperations(postbox: self.postbox, network: self.network, revalidationContext: self.mediaReferenceRevalidationContext).start()) - self.managedOperationsDisposable.add(managedRecentlyUsedInlineBots(postbox: self.postbox, network: self.network, accountPeerId: peerId).start()) + self.managedOperationsDisposable.add(_internal_managedRecentlyUsedInlineBots(postbox: self.postbox, network: self.network, accountPeerId: peerId).start()) self.managedOperationsDisposable.add(managedLocalTypingActivities(activities: self.localInputActivityManager.allActivities(), postbox: self.postbox, network: self.network, accountPeerId: self.peerId).start()) self.managedOperationsDisposable.add(managedSynchronizeConsumeMessageContentOperations(postbox: self.postbox, network: self.network, stateManager: self.stateManager).start()) self.managedOperationsDisposable.add(managedConsumePersonalMessagesActions(postbox: self.postbox, network: self.network, stateManager: self.stateManager).start()) diff --git a/submodules/TelegramCore/Sources/FetchedMediaResource.swift b/submodules/TelegramCore/Sources/Network/FetchedMediaResource.swift similarity index 100% rename from submodules/TelegramCore/Sources/FetchedMediaResource.swift rename to submodules/TelegramCore/Sources/Network/FetchedMediaResource.swift diff --git a/submodules/TelegramCore/Sources/ExportMessageLink.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ExportMessageLink.swift similarity index 89% rename from submodules/TelegramCore/Sources/ExportMessageLink.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/ExportMessageLink.swift index 2d32877418..66c64fce1e 100644 --- a/submodules/TelegramCore/Sources/ExportMessageLink.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ExportMessageLink.swift @@ -3,7 +3,7 @@ import Postbox import TelegramApi import SwiftSignalKit -public func exportMessageLink(account: Account, peerId: PeerId, messageId: MessageId, isThread: Bool = false) -> Signal { +func _internal_exportMessageLink(account: Account, peerId: PeerId, messageId: MessageId, isThread: Bool = false) -> Signal { return account.postbox.transaction { transaction -> (Peer, MessageId)? in var peer: Peer? = transaction.getPeer(messageId.peerId) if let peer = peer { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift index 144bf90c38..c11b8dca37 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift @@ -147,5 +147,9 @@ public extension TelegramEngine { public func earliestUnseenPersonalMentionMessage(peerId: PeerId) -> Signal { return _internal_earliestUnseenPersonalMentionMessage(account: self.account, peerId: peerId) } + + public func exportMessageLink(peerId: PeerId, messageId: MessageId, isThread: Bool = false) -> Signal { + return _internal_exportMessageLink(account: self.account, peerId: peerId, messageId: messageId, isThread: isThread) + } } } diff --git a/submodules/TelegramCore/Sources/AddPeerMember.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/AddPeerMember.swift similarity index 96% rename from submodules/TelegramCore/Sources/AddPeerMember.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Peers/AddPeerMember.swift index 871b3285c3..fffb6cc578 100644 --- a/submodules/TelegramCore/Sources/AddPeerMember.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/AddPeerMember.swift @@ -14,7 +14,7 @@ public enum AddGroupMemberError { case tooManyChannels } -public func addGroupMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal { +func _internal_addGroupMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal { return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId), let memberPeer = transaction.getPeer(memberId), let inputUser = apiInputUser(memberPeer) { if let group = peer as? TelegramGroup { @@ -79,7 +79,7 @@ public enum AddChannelMemberError { case tooMuchBots } -public func addChannelMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal<(ChannelParticipant?, RenderedChannelParticipant), AddChannelMemberError> { +func _internal_addChannelMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal<(ChannelParticipant?, RenderedChannelParticipant), AddChannelMemberError> { return _internal_fetchChannelParticipant(account: account, peerId: peerId, participantId: memberId) |> mapError { error -> AddChannelMemberError in } @@ -180,7 +180,7 @@ public func addChannelMember(account: Account, peerId: PeerId, memberId: PeerId) } } -public func addChannelMembers(account: Account, peerId: PeerId, memberIds: [PeerId]) -> Signal { +func _internal_addChannelMembers(account: Account, peerId: PeerId, memberIds: [PeerId]) -> Signal { let signal = account.postbox.transaction { transaction -> Signal in var memberPeerIds: [PeerId:Peer] = [:] var inputUsers: [Api.InputUser] = [] diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/PeerAdmins.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/PeerAdmins.swift index e27931644d..9a8eea7fdf 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/PeerAdmins.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/PeerAdmins.swift @@ -65,7 +65,7 @@ func _internal_addGroupAdmin(account: Account, peerId: PeerId, adminId: PeerId) return account.network.request(Api.functions.messages.editChatAdmin(chatId: group.id.id._internalGetInt32Value(), userId: inputUser, isAdmin: .boolTrue)) |> `catch` { error -> Signal in if error.errorDescription == "USER_NOT_PARTICIPANT" { - return addGroupMember(account: account, peerId: peerId, memberId: adminId) + return _internal_addGroupMember(account: account, peerId: peerId, memberId: adminId) |> mapError { error -> AddGroupAdminError in return .addMemberError(error) } @@ -188,7 +188,7 @@ func _internal_updateChannelAdminRights(account: Account, peerId: PeerId, adminI |> map { [$0] } |> `catch` { error -> Signal<[Api.Updates], UpdateChannelAdminRightsError> in if error.errorDescription == "USER_NOT_PARTICIPANT" { - return addChannelMember(account: account, peerId: peerId, memberId: adminId) + return _internal_addChannelMember(account: account, peerId: peerId, memberId: adminId) |> map { _ -> [Api.Updates] in return [] } diff --git a/submodules/TelegramCore/Sources/RecentPeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/RecentPeers.swift similarity index 92% rename from submodules/TelegramCore/Sources/RecentPeers.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Peers/RecentPeers.swift index 88108ac206..11926c1364 100644 --- a/submodules/TelegramCore/Sources/RecentPeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/RecentPeers.swift @@ -16,7 +16,7 @@ private func cachedRecentPeersEntryId() -> ItemCacheEntryId { return ItemCacheEntryId(collectionId: 101, key: CachedRecentPeers.cacheKey()) } -public func recentPeers(account: Account) -> Signal { +func _internal_recentPeers(account: Account) -> Signal { let key = PostboxViewKey.cachedItem(cachedRecentPeersEntryId()) return account.postbox.combinedView(keys: [key]) |> mapToSignal { views -> Signal in @@ -41,14 +41,14 @@ public func recentPeers(account: Account) -> Signal { } } -public func getRecentPeers(transaction: Transaction) -> [PeerId] { +public func _internal_getRecentPeers(transaction: Transaction) -> [PeerId] { guard let entry = transaction.retrieveItemCacheEntry(id: cachedRecentPeersEntryId()) as? CachedRecentPeers else { return [] } return entry.ids } -public func managedUpdatedRecentPeers(accountPeerId: PeerId, postbox: Postbox, network: Network) -> Signal { +func _internal_managedUpdatedRecentPeers(accountPeerId: PeerId, postbox: Postbox, network: Network) -> Signal { let key = PostboxViewKey.cachedItem(cachedRecentPeersEntryId()) let peersEnabled = postbox.combinedView(keys: [key]) |> map { views -> Bool in @@ -96,7 +96,7 @@ public func managedUpdatedRecentPeers(accountPeerId: PeerId, postbox: Postbox, n } } -public func removeRecentPeer(account: Account, peerId: PeerId) -> Signal { +func _internal_removeRecentPeer(account: Account, peerId: PeerId) -> Signal { return account.postbox.transaction { transaction -> Signal in guard let entry = transaction.retrieveItemCacheEntry(id: cachedRecentPeersEntryId()) as? CachedRecentPeers else { return .complete() @@ -121,7 +121,7 @@ public func removeRecentPeer(account: Account, peerId: PeerId) -> Signal switchToLatest } -public func updateRecentPeersEnabled(postbox: Postbox, network: Network, enabled: Bool) -> Signal { +func _internal_updateRecentPeersEnabled(postbox: Postbox, network: Network, enabled: Bool) -> Signal { return postbox.transaction { transaction -> Signal in var currentValue = true if let entry = transaction.retrieveItemCacheEntry(id: cachedRecentPeersEntryId()) as? CachedRecentPeers { @@ -149,7 +149,7 @@ public func updateRecentPeersEnabled(postbox: Postbox, network: Network, enabled } |> switchToLatest } -public func managedRecentlyUsedInlineBots(postbox: Postbox, network: Network, accountPeerId: PeerId) -> Signal { +func _internal_managedRecentlyUsedInlineBots(postbox: Postbox, network: Network, accountPeerId: PeerId) -> Signal { let remotePeers = network.request(Api.functions.contacts.getTopPeers(flags: 1 << 2, offset: 0, limit: 16, hash: 0)) |> retryRequest |> map { result -> ([Peer], [PeerId: PeerPresence], [(PeerId, Double)])? in @@ -207,7 +207,7 @@ public func managedRecentlyUsedInlineBots(postbox: Postbox, network: Network, ac return updatedRemotePeers } -public func addRecentlyUsedInlineBot(postbox: Postbox, peerId: PeerId) -> Signal { +func _internal_addRecentlyUsedInlineBot(postbox: Postbox, peerId: PeerId) -> Signal { return postbox.transaction { transaction -> Void in var maxRating = 1.0 for entry in transaction.getOrderedListItems(collectionId: Namespaces.OrderedItemList.CloudRecentInlineBots) { @@ -219,7 +219,7 @@ public func addRecentlyUsedInlineBot(postbox: Postbox, peerId: PeerId) -> Signal } } -public func recentlyUsedInlineBots(postbox: Postbox) -> Signal<[(Peer, Double)], NoError> { +func _internal_recentlyUsedInlineBots(postbox: Postbox) -> Signal<[(Peer, Double)], NoError> { return postbox.combinedView(keys: [.orderedItemList(id: Namespaces.OrderedItemList.CloudRecentInlineBots)]) |> take(1) |> mapToSignal { view -> Signal<[(Peer, Double)], NoError> in @@ -238,7 +238,7 @@ public func recentlyUsedInlineBots(postbox: Postbox) -> Signal<[(Peer, Double)], } } -public func removeRecentlyUsedInlineBot(account: Account, peerId: PeerId) -> Signal { +func _internal_removeRecentlyUsedInlineBot(account: Account, peerId: PeerId) -> Signal { return account.postbox.transaction { transaction -> Signal in transaction.removeOrderedItemListItem(collectionId: Namespaces.OrderedItemList.CloudRecentInlineBots, itemId: RecentPeerItemId(peerId).rawValue) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift index 23e6f94320..093d4af9f3 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift @@ -287,5 +287,45 @@ public extension TelegramEngine { } |> ignoreValues } + + public func addGroupMember(peerId: PeerId, memberId: PeerId) -> Signal { + return _internal_addGroupMember(account: self.account, peerId: peerId, memberId: memberId) + } + + public func addChannelMember(peerId: PeerId, memberId: PeerId) -> Signal<(ChannelParticipant?, RenderedChannelParticipant), AddChannelMemberError> { + return _internal_addChannelMember(account: self.account, peerId: peerId, memberId: memberId) + } + + public func addChannelMembers(peerId: PeerId, memberIds: [PeerId]) -> Signal { + return _internal_addChannelMembers(account: self.account, peerId: peerId, memberIds: memberIds) + } + + public func recentPeers() -> Signal { + return _internal_recentPeers(account: self.account) + } + + public func managedUpdatedRecentPeers() -> Signal { + return _internal_managedUpdatedRecentPeers(accountPeerId: self.account.peerId, postbox: self.account.postbox, network: self.account.network) + } + + public func removeRecentPeer(peerId: PeerId) -> Signal { + return _internal_removeRecentPeer(account: self.account, peerId: peerId) + } + + public func updateRecentPeersEnabled(enabled: Bool) -> Signal { + return _internal_updateRecentPeersEnabled(postbox: self.account.postbox, network: self.account.network, enabled: enabled) + } + + public func addRecentlyUsedInlineBot(peerId: PeerId) -> Signal { + return _internal_addRecentlyUsedInlineBot(postbox: self.account.postbox, peerId: peerId) + } + + public func recentlyUsedInlineBots() -> Signal<[(Peer, Double)], NoError> { + return _internal_recentlyUsedInlineBots(postbox: self.account.postbox) + } + + public func removeRecentlyUsedInlineBot(peerId: PeerId) -> Signal { + return _internal_removeRecentlyUsedInlineBot(account: self.account, peerId: peerId) + } } } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index f14b19780d..d68b675c11 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -1902,7 +1902,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if case let .replyThread(replyThreadMessage) = chatPresentationInterfaceState.chatLocation { threadMessageId = replyThreadMessage.messageId } - let _ = (exportMessageLink(account: context.account, peerId: message.id.peerId, messageId: message.id, isThread: threadMessageId != nil) + let _ = (context.engine.messages.exportMessageLink(peerId: message.id.peerId, messageId: message.id, isThread: threadMessageId != nil) |> map { result -> String? in return result } @@ -7056,7 +7056,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G self.chatDisplayNode.loadInputPanels(theme: self.presentationInterfaceState.theme, strings: self.presentationInterfaceState.strings, fontSize: self.presentationInterfaceState.fontSize) - self.recentlyUsedInlineBotsDisposable = (recentlyUsedInlineBots(postbox: self.context.account.postbox) |> deliverOnMainQueue).start(next: { [weak self] peers in + self.recentlyUsedInlineBotsDisposable = (self.context.engine.peers.recentlyUsedInlineBots() |> deliverOnMainQueue).start(next: { [weak self] peers in self?.recentlyUsedInlineBotsValue = peers.filter({ $0.1 >= 0.14 }).map({ $0.0 }) }) diff --git a/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift b/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift index 885d390aca..06abbb38fd 100644 --- a/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift +++ b/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift @@ -797,7 +797,7 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState if case let .replyThread(replyThreadMessage) = chatPresentationInterfaceState.chatLocation { threadMessageId = replyThreadMessage.messageId } - let _ = (exportMessageLink(account: context.account, peerId: message.id.peerId, messageId: message.id, isThread: threadMessageId != nil) + let _ = (context.engine.messages.exportMessageLink(peerId: message.id.peerId, messageId: message.id, isThread: threadMessageId != nil) |> map { result -> String? in return result } diff --git a/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift b/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift index 60298d5c02..8684fe0875 100644 --- a/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift +++ b/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift @@ -178,7 +178,7 @@ private func updatedContextQueryResultStateForQuery(context: AccountContext, pee signal = .single({ _ in return .mentions([]) }) } - let inlineBots: Signal<[(Peer, Double)], NoError> = types.contains(.contextBots) ? recentlyUsedInlineBots(postbox: context.account.postbox) : .single([]) + let inlineBots: Signal<[(Peer, Double)], NoError> = types.contains(.contextBots) ? context.engine.peers.recentlyUsedInlineBots() : .single([]) let participants = combineLatest(inlineBots, searchPeerMembers(context: context, peerId: peer.id, chatLocation: chatLocation, query: query, scope: .mention)) |> map { inlineBots, peers -> (ChatPresentationInputQueryResult?) -> ChatPresentationInputQueryResult? in let filteredInlineBots = inlineBots.sorted(by: { $0.1 > $1.1 }).filter { peer, rating in diff --git a/submodules/TelegramUI/Sources/MentionChatInputContextPanelNode.swift b/submodules/TelegramUI/Sources/MentionChatInputContextPanelNode.swift index 7a9fa94e10..1e908b3475 100644 --- a/submodules/TelegramUI/Sources/MentionChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/Sources/MentionChatInputContextPanelNode.swift @@ -165,7 +165,7 @@ final class MentionChatInputContextPanelNode: ChatInputContextPanelNode { } }, removeRequested: { [weak self] peerId in if let strongSelf = self { - let _ = removeRecentlyUsedInlineBot(account: strongSelf.context.account, peerId: peerId).start() + let _ = strongSelf.context.engine.peers.removeRecentlyUsedInlineBot(peerId: peerId).start() strongSelf.revealedPeerId = nil strongSelf.currentResults = strongSelf.currentResults.filter { $0.id != peerId } diff --git a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift index 888d39f43a..b368cf9faf 100644 --- a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift @@ -67,12 +67,12 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur if payload.isEmpty { if peerId.namespace == Namespaces.Peer.CloudGroup { - let _ = (addGroupMember(account: context.account, peerId: peerId, memberId: botPeerId) + let _ = (context.engine.peers.addGroupMember(peerId: peerId, memberId: botPeerId) |> deliverOnMainQueue).start(completed: { controller?.dismiss() }) } else { - let _ = (addChannelMember(account: context.account, peerId: peerId, memberId: botPeerId) + let _ = (context.engine.peers.addChannelMember(peerId: peerId, memberId: botPeerId) |> deliverOnMainQueue).start(completed: { controller?.dismiss() }) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index d5f10e6eec..43271b3c0e 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -7209,14 +7209,14 @@ func presentAddMembers(context: AccountContext, parentController: ViewController if case let .peer(selectedPeer, _, _) = memberPeer { let memberId = selectedPeer.id if groupPeer.id.namespace == Namespaces.Peer.CloudChannel { - return context.peerChannelMemberCategoriesContextsManager.addMember(account: context.account, peerId: groupPeer.id, memberId: memberId) + return context.peerChannelMemberCategoriesContextsManager.addMember(engine: context.engine, peerId: groupPeer.id, memberId: memberId) |> map { _ -> Void in } |> `catch` { _ -> Signal in return .complete() } } else { - return addGroupMember(account: context.account, peerId: groupPeer.id, memberId: memberId) + return context.engine.peers.addGroupMember(peerId: groupPeer.id, memberId: memberId) |> deliverOnMainQueue |> `catch` { error -> Signal in switch error { @@ -7264,7 +7264,7 @@ func presentAddMembers(context: AccountContext, parentController: ViewController guard let upgradedPeerId = upgradedPeerId else { return .single(nil) } - return context.peerChannelMemberCategoriesContextsManager.addMember(account: context.account, peerId: upgradedPeerId, memberId: memberId) + return context.peerChannelMemberCategoriesContextsManager.addMember(engine: context.engine, peerId: upgradedPeerId, memberId: memberId) |> `catch` { _ -> Signal in return .complete() } @@ -7300,11 +7300,11 @@ func presentAddMembers(context: AccountContext, parentController: ViewController |> castError(AddChannelMemberError.self) |> mapToSignal { view -> Signal in if memberIds.count == 1 { - return context.peerChannelMemberCategoriesContextsManager.addMember(account: context.account, peerId: groupPeer.id, memberId: memberIds[0]) + return context.peerChannelMemberCategoriesContextsManager.addMember(engine: context.engine, peerId: groupPeer.id, memberId: memberIds[0]) |> map { _ -> Void in } } else { - return context.peerChannelMemberCategoriesContextsManager.addMembers(account: context.account, peerId: groupPeer.id, memberIds: memberIds) |> map { _ in + return context.peerChannelMemberCategoriesContextsManager.addMembers(engine: context.engine, peerId: groupPeer.id, memberIds: memberIds) |> map { _ in } } } diff --git a/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift b/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift index 4a3c25ab61..b9372785ab 100644 --- a/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift +++ b/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift @@ -435,8 +435,8 @@ public final class PeerChannelMemberCategoriesContextsManager { |> ignoreValues } - public func addMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal { - return addChannelMember(account: account, peerId: peerId, memberId: memberId) + public func addMember(engine: TelegramEngine, peerId: PeerId, memberId: PeerId) -> Signal { + return engine.peers.addChannelMember(peerId: peerId, memberId: memberId) |> deliverOnMainQueue |> beforeNext { [weak self] result in if let strongSelf = self { @@ -453,9 +453,9 @@ public final class PeerChannelMemberCategoriesContextsManager { |> ignoreValues } - public func addMembers(account: Account, peerId: PeerId, memberIds: [PeerId]) -> Signal { + public func addMembers(engine: TelegramEngine, peerId: PeerId, memberIds: [PeerId]) -> Signal { let signals: [Signal<(ChannelParticipant?, RenderedChannelParticipant)?, AddChannelMemberError>] = memberIds.map({ memberId in - return addChannelMember(account: account, peerId: peerId, memberId: memberId) + return engine.peers.addChannelMember(peerId: peerId, memberId: memberId) |> map(Optional.init) |> `catch` { error -> Signal<(ChannelParticipant?, RenderedChannelParticipant)?, AddChannelMemberError> in return .fail(error)