diff --git a/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift b/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift index 93af51f808..1791e51326 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift @@ -881,7 +881,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { foundRemotePeers = ( .single((currentRemotePeersValue.0, currentRemotePeersValue.1, true)) |> then( - searchPeers(account: context.account, query: query) + context.engine.peers.searchPeers(query: query) |> map { ($0.0, $0.1, false) } |> delay(0.2, queue: Queue.concurrentDefaultQueue()) ) diff --git a/submodules/ContactListUI/Sources/ContactListNode.swift b/submodules/ContactListUI/Sources/ContactListNode.swift index 122dd2a09f..a24a0fa1b4 100644 --- a/submodules/ContactListUI/Sources/ContactListNode.swift +++ b/submodules/ContactListUI/Sources/ContactListNode.swift @@ -1095,7 +1095,7 @@ public final class ContactListNode: ASDisplayNode { if globalSearch { foundRemoteContacts = foundRemoteContacts |> then( - searchPeers(account: context.account, query: query) + context.engine.peers.searchPeers(query: query) |> map { ($0.0, $0.1) } |> delay(0.2, queue: Queue.concurrentDefaultQueue()) ) diff --git a/submodules/ContactListUI/Sources/ContactsSearchContainerNode.swift b/submodules/ContactListUI/Sources/ContactsSearchContainerNode.swift index 0c727b739b..a97308a242 100644 --- a/submodules/ContactListUI/Sources/ContactsSearchContainerNode.swift +++ b/submodules/ContactListUI/Sources/ContactsSearchContainerNode.swift @@ -269,7 +269,7 @@ public final class ContactsSearchContainerNode: SearchDisplayControllerContentNo if categories.contains(.global) { foundRemoteContacts = .single(previousFoundRemoteContacts.with({ $0 })) |> then( - searchPeers(account: context.account, query: query) + context.engine.peers.searchPeers(query: query) |> map { ($0.0, $0.1) } |> delay(0.2, queue: Queue.concurrentDefaultQueue()) ) diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift b/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift index 9e43448063..0b7c4e97c3 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift @@ -682,7 +682,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon foundRemotePeers = .single(([], [])) } else { foundContacts = context.account.postbox.searchContacts(query: query.lowercased()) - foundRemotePeers = .single(([], [])) |> then(searchPeers(account: context.account, query: query) + foundRemotePeers = .single(([], [])) |> then(context.engine.peers.searchPeers(query: query) |> delay(0.2, queue: Queue.concurrentDefaultQueue())) } case .searchMembers, .searchBanned, .searchKicked, .searchAdmins: @@ -996,7 +996,7 @@ public final class ChannelMembersSearchContainerNode: SearchDisplayControllerCon } if mode == .banAndPromoteActions || mode == .inviteActions { - foundRemotePeers = .single(([], [])) |> then(searchPeers(account: context.account, query: query) + foundRemotePeers = .single(([], [])) |> then(context.engine.peers.searchPeers(query: query) |> delay(0.2, queue: Queue.concurrentDefaultQueue())) } else { foundRemotePeers = .single(([], [])) diff --git a/submodules/ShareController/Sources/ShareSearchContainerNode.swift b/submodules/ShareController/Sources/ShareSearchContainerNode.swift index 2cba52dc8b..f585d685f3 100644 --- a/submodules/ShareController/Sources/ShareSearchContainerNode.swift +++ b/submodules/ShareController/Sources/ShareSearchContainerNode.swift @@ -249,7 +249,7 @@ final class ShareSearchContainerNode: ASDisplayNode, ShareContentContainerNode { let foundLocalPeers = context.account.postbox.searchPeers(query: query.lowercased()) let foundRemotePeers: Signal<([FoundPeer], [FoundPeer]), NoError> = .single(([], [])) |> then( - searchPeers(account: context.account, query: query) + context.engine.peers.searchPeers(query: query) |> delay(0.2, queue: Queue.concurrentDefaultQueue()) ) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift new file mode 100644 index 0000000000..06b733e278 --- /dev/null +++ b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift @@ -0,0 +1,19 @@ +import SwiftSignalKit + +public extension TelegramEngine { + final class AccountData { + private let account: Account + + init(account: Account) { + self.account = account + } + + public func acceptTermsOfService(id: String) -> Signal { + return _internal_acceptTermsOfService(account: self.account, id: id) + } + + func resetAccountDueTermsOfService() -> Signal { + return _internal_resetAccountDueTermsOfService(network: self.account.network) + } + } +} diff --git a/submodules/TelegramCore/Sources/TermsOfService.swift b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TermsOfService.swift similarity index 93% rename from submodules/TelegramCore/Sources/TermsOfService.swift rename to submodules/TelegramCore/Sources/TelegramEngine/AccountData/TermsOfService.swift index e3514b3fe9..b0c66a3537 100644 --- a/submodules/TelegramCore/Sources/TermsOfService.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TermsOfService.swift @@ -34,7 +34,7 @@ extension TermsOfServiceUpdate { } } -public func acceptTermsOfService(account: Account, id: String) -> Signal { +func _internal_acceptTermsOfService(account: Account, id: String) -> Signal { return account.network.request(Api.functions.help.acceptTermsOfService(id: .dataJSON(data: id))) |> `catch` { _ -> Signal in return .complete() @@ -45,7 +45,7 @@ public func acceptTermsOfService(account: Account, id: String) -> Signal Signal { +func _internal_resetAccountDueTermsOfService(network: Network) -> Signal { return network.request(Api.functions.account.deleteAccount(reason: "Decline ToS update")) |> retryRequest |> map { _ in return } diff --git a/submodules/TelegramCore/Sources/SearchPeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/SearchPeers.swift similarity index 97% rename from submodules/TelegramCore/Sources/SearchPeers.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Peers/SearchPeers.swift index 5276cffa85..0cd869c7d2 100644 --- a/submodules/TelegramCore/Sources/SearchPeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/SearchPeers.swift @@ -20,7 +20,7 @@ public struct FoundPeer: Equatable { } } -public func searchPeers(account: Account, query: String) -> Signal<([FoundPeer], [FoundPeer]), NoError> { +func _internal_searchPeers(account: Account, query: String) -> Signal<([FoundPeer], [FoundPeer]), NoError> { let searchResult = account.network.request(Api.functions.contacts.search(q: query, limit: 20), automaticFloodWait: false) |> map(Optional.init) |> `catch` { _ in diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift index da8ed4fc75..2a65d8f46e 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift @@ -65,5 +65,9 @@ public extension TelegramEngine { public func resolvePeerByName(name: String, ageLimit: Int32 = 2 * 60 * 60 * 24) -> Signal { return _internal_resolvePeerByName(account: self.account, name: name, ageLimit: ageLimit) } + + public func searchPeers(query: String) -> Signal<([FoundPeer], [FoundPeer]), NoError> { + return _internal_searchPeers(account: self.account, query: query) + } } } diff --git a/submodules/TelegramCore/Sources/SaveSecureIdValue.swift b/submodules/TelegramCore/Sources/TelegramEngine/SecureId/SaveSecureIdValue.swift similarity index 100% rename from submodules/TelegramCore/Sources/SaveSecureIdValue.swift rename to submodules/TelegramCore/Sources/TelegramEngine/SecureId/SaveSecureIdValue.swift diff --git a/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift b/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift index 4b051e74a4..78e12fc07f 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift @@ -27,6 +27,10 @@ public final class TelegramEngine { public lazy var auth: Auth = { return Auth(account: self.account) }() + + public lazy var accountData: AccountData = { + return AccountData(account: self.account) + }() } public final class TelegramEngineUnauthorized { diff --git a/submodules/TelegramUI/Sources/ApplicationContext.swift b/submodules/TelegramUI/Sources/ApplicationContext.swift index f9e4ffab5a..3b5106cb76 100644 --- a/submodules/TelegramUI/Sources/ApplicationContext.swift +++ b/submodules/TelegramUI/Sources/ApplicationContext.swift @@ -461,7 +461,7 @@ final class AuthorizedApplicationContext { guard let strongSelf = self else { return } - let _ = (acceptTermsOfService(account: strongSelf.context.account, id: termsOfServiceUpdate.id) + let _ = (strongSelf.context.engine.accountData.acceptTermsOfService(id: termsOfServiceUpdate.id) |> deliverOnMainQueue).start(completed: { controller?.dismiss() if let strongSelf = self, let botName = botName {