mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Refactoring
This commit is contained in:
parent
60d959bff8
commit
df4b313808
37 changed files with 64 additions and 57 deletions
|
|
@ -73,7 +73,7 @@ final class InstantPageFeedbackNode: ASDisplayNode, InstantPageNode {
|
|||
}
|
||||
|
||||
@objc func buttonPressed() {
|
||||
self.resolveDisposable.set((resolvePeerByName(account: self.context.account, name: "previews") |> deliverOnMainQueue).start(next: { [weak self] peerId in
|
||||
self.resolveDisposable.set((self.context.engine.peers.resolvePeerByName(name: "previews") |> deliverOnMainQueue).start(next: { [weak self] peerId in
|
||||
if let strongSelf = self, let _ = peerId, let webPageId = strongSelf.webPage.id?.id {
|
||||
strongSelf.openUrl(InstantPageUrlItem(url: "https://t.me/previews?start=webpage\(webPageId)", webpageId: nil))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,10 +147,11 @@ final class InstantPagePeerReferenceNode: ASDisplayNode, InstantPageNode {
|
|||
self.joinNode.addTarget(self, action: #selector(self.joinPressed), forControlEvents: .touchUpInside)
|
||||
|
||||
let account = self.context.account
|
||||
let context = self.context
|
||||
let signal = actualizedPeer(postbox: account.postbox, network: account.network, peer: initialPeer)
|
||||
|> mapToSignal({ peer -> Signal<Peer, NoError> in
|
||||
if let peer = peer as? TelegramChannel, let username = peer.username, peer.accessHash == nil {
|
||||
return .single(peer) |> then(resolvePeerByName(account: account, name: username)
|
||||
return .single(peer) |> then(context.engine.peers.resolvePeerByName(name: username)
|
||||
|> mapToSignal({ peerId -> Signal<Peer, NoError> in
|
||||
if let peerId = peerId {
|
||||
return account.postbox.transaction({ transaction -> Peer in
|
||||
|
|
|
|||
|
|
@ -403,7 +403,7 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
|
|||
throttledUserLocation(userLocation)
|
||||
|> mapToSignal { location -> Signal<[TelegramMediaMap]?, NoError> in
|
||||
if let location = location, location.horizontalAccuracy > 0 {
|
||||
return combineLatest(nearbyVenues(account: context.account, latitude: location.coordinate.latitude, longitude: location.coordinate.longitude), personalVenues)
|
||||
return combineLatest(nearbyVenues(context: context, latitude: location.coordinate.latitude, longitude: location.coordinate.longitude), personalVenues)
|
||||
|> map { nearbyVenues, personalVenues -> [TelegramMediaMap]? in
|
||||
var resultVenues: [TelegramMediaMap] = []
|
||||
if let personalVenues = personalVenues {
|
||||
|
|
@ -431,7 +431,7 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
|
|||
if let coordinate = coordinate {
|
||||
return (.single(nil)
|
||||
|> then(
|
||||
nearbyVenues(account: context.account, latitude: coordinate.latitude, longitude: coordinate.longitude)
|
||||
nearbyVenues(context: context, latitude: coordinate.latitude, longitude: coordinate.longitude)
|
||||
|> map { venues -> ([TelegramMediaMap], CLLocation)? in
|
||||
return (venues, CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ final class LocationSearchContainerNode: ASDisplayNode {
|
|||
}
|
||||
|> mapToSignal { query -> Signal<([LocationSearchEntry], String)?, NoError> in
|
||||
if let query = query, !query.isEmpty {
|
||||
let foundVenues = nearbyVenues(account: context.account, latitude: coordinate.latitude, longitude: coordinate.longitude, query: query)
|
||||
let foundVenues = nearbyVenues(context: context, latitude: coordinate.latitude, longitude: coordinate.longitude, query: query)
|
||||
|> afterCompleted {
|
||||
isSearching.set(false)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import TelegramCore
|
|||
import TelegramPresentationData
|
||||
import TelegramStringFormatting
|
||||
import MapKit
|
||||
import AccountContext
|
||||
|
||||
extension TelegramMediaMap {
|
||||
convenience init(coordinate: CLLocationCoordinate2D, liveBroadcastingTimeout: Int32? = nil, proximityNotificationRadius: Int32? = nil) {
|
||||
|
|
@ -32,17 +33,17 @@ public func ==(lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool
|
|||
return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
|
||||
}
|
||||
|
||||
public func nearbyVenues(account: Account, latitude: Double, longitude: Double, query: String? = nil) -> Signal<[TelegramMediaMap], NoError> {
|
||||
return account.postbox.transaction { transaction -> SearchBotsConfiguration in
|
||||
public func nearbyVenues(context: AccountContext, latitude: Double, longitude: Double, query: String? = nil) -> Signal<[TelegramMediaMap], NoError> {
|
||||
return context.account.postbox.transaction { transaction -> SearchBotsConfiguration in
|
||||
return currentSearchBotsConfiguration(transaction: transaction)
|
||||
} |> mapToSignal { searchBotsConfiguration in
|
||||
return resolvePeerByName(account: account, name: searchBotsConfiguration.venueBotUsername ?? "foursquare")
|
||||
return context.engine.peers.resolvePeerByName(name: searchBotsConfiguration.venueBotUsername ?? "foursquare")
|
||||
|> take(1)
|
||||
|> mapToSignal { peerId -> Signal<ChatContextResultCollection?, NoError> in
|
||||
guard let peerId = peerId else {
|
||||
return .single(nil)
|
||||
}
|
||||
return requestChatContextResults(account: account, botId: peerId, peerId: account.peerId, query: query ?? "", location: .single((latitude, longitude)), offset: "")
|
||||
return requestChatContextResults(account: context.account, botId: peerId, peerId: context.account.peerId, query: query ?? "", location: .single((latitude, longitude)), offset: "")
|
||||
|> map { results -> ChatContextResultCollection? in
|
||||
return results?.results
|
||||
}
|
||||
|
|
|
|||
|
|
@ -762,7 +762,7 @@ public func channelPermissionsController(context: AccountContext, peerId origina
|
|||
}
|
||||
pushControllerImpl?(controller)
|
||||
}, openChannelExample: {
|
||||
resolveDisposable.set((resolvePeerByName(account: context.account, name: "durov") |> deliverOnMainQueue).start(next: { peerId in
|
||||
resolveDisposable.set((context.engine.peers.resolvePeerByName(name: "durov") |> deliverOnMainQueue).start(next: { peerId in
|
||||
if let peerId = peerId {
|
||||
navigateToChatControllerImpl?(peerId)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -402,7 +402,7 @@ public func groupStickerPackSetupController(context: AccountContext, peerId: Pee
|
|||
}, updateSearchText: { text in
|
||||
searchText.set(text)
|
||||
}, openStickersBot: {
|
||||
resolveDisposable.set((resolvePeerByName(account: context.account, name: "stickers") |> deliverOnMainQueue).start(next: { peerId in
|
||||
resolveDisposable.set((context.engine.peers.resolvePeerByName(name: "stickers") |> deliverOnMainQueue).start(next: { peerId in
|
||||
if let peerId = peerId {
|
||||
dismissImpl?()
|
||||
navigateToChatControllerImpl?(peerId)
|
||||
|
|
|
|||
|
|
@ -581,7 +581,7 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta
|
|||
])
|
||||
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
}, openStickersBot: {
|
||||
resolveDisposable.set((resolvePeerByName(account: context.account, name: "stickers") |> deliverOnMainQueue).start(next: { peerId in
|
||||
resolveDisposable.set((context.engine.peers.resolvePeerByName(name: "stickers") |> deliverOnMainQueue).start(next: { peerId in
|
||||
if let peerId = peerId {
|
||||
navigateToChatControllerImpl?(peerId)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -497,7 +497,7 @@ final class ThemeGridSearchContentNode: SearchDisplayControllerContentNode {
|
|||
guard let name = configuration.imageBotUsername else {
|
||||
return .single(nil)
|
||||
}
|
||||
return resolvePeerByName(account: context.account, name: name)
|
||||
return context.engine.peers.resolvePeerByName(name: name)
|
||||
|> mapToSignal { peerId -> Signal<Peer?, NoError> in
|
||||
if let peerId = peerId {
|
||||
return context.account.postbox.loadedPeerWithId(peerId)
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ public final class StickerPackPreviewController: ViewController, StandalonePrese
|
|||
}
|
||||
|
||||
let account = strongSelf.context.account
|
||||
strongSelf.openMentionDisposable.set((resolvePeerByName(account: strongSelf.context.account, name: mention)
|
||||
strongSelf.openMentionDisposable.set((strongSelf.context.engine.peers.resolvePeerByName(name: mention)
|
||||
|> mapToSignal { peerId -> Signal<Peer?, NoError> in
|
||||
if let peerId = peerId {
|
||||
return account.postbox.loadedPeerWithId(peerId)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public enum InternalUpdaterError {
|
|||
}
|
||||
|
||||
public func requestUpdatesXml(account: Account, source: String) -> Signal<Data, InternalUpdaterError> {
|
||||
return resolvePeerByName(account: account, name: source)
|
||||
return TelegramEngine(account: account).peers.resolvePeerByName(name: source)
|
||||
|> castError(InternalUpdaterError.self)
|
||||
|> mapToSignal { peerId -> Signal<Peer?, InternalUpdaterError> in
|
||||
return account.postbox.transaction { transaction in
|
||||
|
|
@ -79,7 +79,7 @@ public enum AppUpdateDownloadResult {
|
|||
}
|
||||
|
||||
public func downloadAppUpdate(account: Account, source: String, messageId: Int32) -> Signal<AppUpdateDownloadResult, InternalUpdaterError> {
|
||||
return resolvePeerByName(account: account, name: source)
|
||||
return TelegramEngine(account: account).peers.resolvePeerByName(name: source)
|
||||
|> castError(InternalUpdaterError.self)
|
||||
|> mapToSignal { peerId -> Signal<Peer?, InternalUpdaterError> in
|
||||
return account.postbox.transaction { transaction in
|
||||
|
|
|
|||
|
|
@ -329,7 +329,7 @@ public func searchGifs(account: Account, query: String, nextOffset: String = "")
|
|||
let configuration = currentSearchBotsConfiguration(transaction: transaction)
|
||||
return configuration.gifBotUsername ?? "gif"
|
||||
} |> mapToSignal {
|
||||
return resolvePeerByName(account: account, name: $0)
|
||||
return _internal_resolvePeerByName(account: account, name: $0)
|
||||
} |> filter { $0 != nil }
|
||||
|> map { $0! }
|
||||
|> mapToSignal { peerId -> Signal<Peer, NoError> in
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public enum ResolvePeerByNameOptionRemote {
|
|||
case update
|
||||
}
|
||||
|
||||
public func resolvePeerByName(account: Account, name: String, ageLimit: Int32 = 2 * 60 * 60 * 24) -> Signal<PeerId?, NoError> {
|
||||
func _internal_resolvePeerByName(account: Account, name: String, ageLimit: Int32 = 2 * 60 * 60 * 24) -> Signal<PeerId?, NoError> {
|
||||
var normalizedName = name
|
||||
if normalizedName.hasPrefix("@") {
|
||||
normalizedName = String(normalizedName[name.index(after: name.startIndex)...])
|
||||
|
|
@ -61,5 +61,9 @@ public extension TelegramEngine {
|
|||
public func inactiveChannelList() -> Signal<[InactiveChannel], NoError> {
|
||||
return _internal_inactiveChannelList(network: self.account.network)
|
||||
}
|
||||
|
||||
public func resolvePeerByName(name: String, ageLimit: Int32 = 2 * 60 * 60 * 24) -> Signal<PeerId?, NoError> {
|
||||
return _internal_resolvePeerByName(account: self.account, name: name, ageLimit: ageLimit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -465,7 +465,7 @@ final class AuthorizedApplicationContext {
|
|||
|> deliverOnMainQueue).start(completed: {
|
||||
controller?.dismiss()
|
||||
if let strongSelf = self, let botName = botName {
|
||||
strongSelf.termsOfServiceProceedToBotDisposable.set((resolvePeerByName(account: strongSelf.context.account, name: botName, ageLimit: 10) |> take(1) |> deliverOnMainQueue).start(next: { peerId in
|
||||
strongSelf.termsOfServiceProceedToBotDisposable.set((strongSelf.context.engine.peers.resolvePeerByName(name: botName, ageLimit: 10) |> take(1) |> deliverOnMainQueue).start(next: { peerId in
|
||||
if let strongSelf = self, let peerId = peerId {
|
||||
self?.rootController.pushViewController(ChatControllerImpl(context: strongSelf.context, chatLocation: .peer(peerId)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10901,7 +10901,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
|||
disposable = MetaDisposable()
|
||||
self.resolvePeerByNameDisposable = disposable
|
||||
}
|
||||
var resolveSignal = resolvePeerByName(account: self.context.account, name: name, ageLimit: 10)
|
||||
var resolveSignal = self.context.engine.peers.resolvePeerByName(name: name, ageLimit: 10)
|
||||
|
||||
var cancelImpl: (() -> Void)?
|
||||
let presentationData = self.presentationData
|
||||
|
|
@ -10967,7 +10967,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
|||
let account = self.context.account
|
||||
var resolveSignal: Signal<Peer?, NoError>
|
||||
if let peerName = peerName {
|
||||
resolveSignal = resolvePeerByName(account: self.context.account, name: peerName)
|
||||
resolveSignal = self.context.engine.peers.resolvePeerByName(name: peerName)
|
||||
|> mapToSignal { peerId -> Signal<Peer?, NoError> in
|
||||
if let peerId = peerId {
|
||||
return account.postbox.loadedPeerWithId(peerId)
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ private func updatedContextQueryResultStateForQuery(context: AccountContext, pee
|
|||
}
|
||||
|
||||
let chatPeer = peer
|
||||
let contextBot = resolvePeerByName(account: context.account, name: addressName)
|
||||
let contextBot = context.engine.peers.resolvePeerByName(name: addressName)
|
||||
|> mapToSignal { peerId -> Signal<Peer?, NoError> in
|
||||
if let peerId = peerId {
|
||||
return context.account.postbox.loadedPeerWithId(peerId)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import SyncCore
|
|||
import SwiftSignalKit
|
||||
import TelegramPresentationData
|
||||
import ContextUI
|
||||
import AccountContext
|
||||
|
||||
private func fixListScrolling(_ multiplexedNode: MultiplexedVideoNode) {
|
||||
let searchBarHeight: CGFloat = 56.0
|
||||
|
|
@ -35,7 +36,7 @@ final class ChatMediaInputGifPaneTrendingState {
|
|||
}
|
||||
|
||||
final class ChatMediaInputGifPane: ChatMediaInputPane, UIScrollViewDelegate {
|
||||
private let account: Account
|
||||
private let context: AccountContext
|
||||
private var theme: PresentationTheme
|
||||
private var strings: PresentationStrings
|
||||
private let controllerInteraction: ChatControllerInteraction
|
||||
|
|
@ -70,8 +71,8 @@ final class ChatMediaInputGifPane: ChatMediaInputPane, UIScrollViewDelegate {
|
|||
private var isLoadingMore: Bool = false
|
||||
private var nextOffset: String?
|
||||
|
||||
init(account: Account, theme: PresentationTheme, strings: PresentationStrings, controllerInteraction: ChatControllerInteraction, paneDidScroll: @escaping (ChatMediaInputPane, ChatMediaInputPaneScrollState, ContainedViewLayoutTransition) -> Void, fixPaneScroll: @escaping (ChatMediaInputPane, ChatMediaInputPaneScrollState) -> Void, openGifContextMenu: @escaping (MultiplexedVideoNodeFile, ASDisplayNode, CGRect, ContextGesture, Bool) -> Void) {
|
||||
self.account = account
|
||||
init(context: AccountContext, theme: PresentationTheme, strings: PresentationStrings, controllerInteraction: ChatControllerInteraction, paneDidScroll: @escaping (ChatMediaInputPane, ChatMediaInputPaneScrollState, ContainedViewLayoutTransition) -> Void, fixPaneScroll: @escaping (ChatMediaInputPane, ChatMediaInputPaneScrollState) -> Void, openGifContextMenu: @escaping (MultiplexedVideoNodeFile, ASDisplayNode, CGRect, ContextGesture, Bool) -> Void) {
|
||||
self.context = context
|
||||
self.theme = theme
|
||||
self.strings = strings
|
||||
self.controllerInteraction = controllerInteraction
|
||||
|
|
@ -208,7 +209,7 @@ final class ChatMediaInputGifPane: ChatMediaInputPane, UIScrollViewDelegate {
|
|||
|
||||
func initializeIfNeeded() {
|
||||
if self.multiplexedNode == nil {
|
||||
self.trendingPromise.set(paneGifSearchForQuery(account: account, query: "", offset: nil, incompleteResults: true, delayRequest: false, updateActivity: nil)
|
||||
self.trendingPromise.set(paneGifSearchForQuery(context: self.context, query: "", offset: nil, incompleteResults: true, delayRequest: false, updateActivity: nil)
|
||||
|> map { items -> ChatMediaInputGifPaneTrendingState? in
|
||||
if let items = items {
|
||||
return ChatMediaInputGifPaneTrendingState(files: items.files, nextOffset: items.nextOffset)
|
||||
|
|
@ -217,7 +218,7 @@ final class ChatMediaInputGifPane: ChatMediaInputPane, UIScrollViewDelegate {
|
|||
}
|
||||
})
|
||||
|
||||
let multiplexedNode = MultiplexedVideoNode(account: self.account, theme: self.theme, strings: self.strings)
|
||||
let multiplexedNode = MultiplexedVideoNode(account: self.context.account, theme: self.theme, strings: self.strings)
|
||||
self.multiplexedNode = multiplexedNode
|
||||
if let layout = self.validLayout {
|
||||
multiplexedNode.frame = CGRect(origin: CGPoint(), size: layout.0)
|
||||
|
|
@ -289,7 +290,7 @@ final class ChatMediaInputGifPane: ChatMediaInputPane, UIScrollViewDelegate {
|
|||
let filesSignal: Signal<(MultiplexedVideoNodeFiles, String?), NoError>
|
||||
switch self.mode {
|
||||
case .recent:
|
||||
filesSignal = combineLatest(self.trendingPromise.get(), self.account.postbox.combinedView(keys: [.orderedItemList(id: Namespaces.OrderedItemList.CloudRecentGifs)]))
|
||||
filesSignal = combineLatest(self.trendingPromise.get(), self.context.account.postbox.combinedView(keys: [.orderedItemList(id: Namespaces.OrderedItemList.CloudRecentGifs)]))
|
||||
|> map { trending, view -> (MultiplexedVideoNodeFiles, String?) in
|
||||
var recentGifs: OrderedItemListView?
|
||||
if let orderedView = view.views[.orderedItemList(id: Namespaces.OrderedItemList.CloudRecentGifs)] {
|
||||
|
|
@ -311,7 +312,7 @@ final class ChatMediaInputGifPane: ChatMediaInputPane, UIScrollViewDelegate {
|
|||
}
|
||||
case .trending:
|
||||
if let searchOffset = searchOffset {
|
||||
filesSignal = paneGifSearchForQuery(account: self.account, query: "", offset: searchOffset, incompleteResults: true, delayRequest: false, updateActivity: nil)
|
||||
filesSignal = paneGifSearchForQuery(context: self.context, query: "", offset: searchOffset, incompleteResults: true, delayRequest: false, updateActivity: nil)
|
||||
|> map { result -> (MultiplexedVideoNodeFiles, String?) in
|
||||
let canLoadMore: Bool
|
||||
if let result = result {
|
||||
|
|
@ -328,7 +329,7 @@ final class ChatMediaInputGifPane: ChatMediaInputPane, UIScrollViewDelegate {
|
|||
}
|
||||
}
|
||||
case let .emojiSearch(emoji):
|
||||
filesSignal = paneGifSearchForQuery(account: self.account, query: emoji, offset: searchOffset, incompleteResults: true, staleCachedResults: searchOffset == nil, delayRequest: false, updateActivity: nil)
|
||||
filesSignal = paneGifSearchForQuery(context: self.context, query: emoji, offset: searchOffset, incompleteResults: true, staleCachedResults: searchOffset == nil, delayRequest: false, updateActivity: nil)
|
||||
|> map { result -> (MultiplexedVideoNodeFiles, String?) in
|
||||
let canLoadMore: Bool
|
||||
if let result = result {
|
||||
|
|
|
|||
|
|
@ -515,7 +515,7 @@ final class ChatMediaInputNode: ChatInputNode {
|
|||
}, fixPaneScroll: { pane, state in
|
||||
fixPaneScrollImpl?(pane, state)
|
||||
})
|
||||
self.gifPane = ChatMediaInputGifPane(account: context.account, theme: theme, strings: strings, controllerInteraction: controllerInteraction, paneDidScroll: { pane, state, transition in
|
||||
self.gifPane = ChatMediaInputGifPane(context: context, theme: theme, strings: strings, controllerInteraction: controllerInteraction, paneDidScroll: { pane, state, transition in
|
||||
paneDidScrollImpl?(pane, state, transition)
|
||||
}, fixPaneScroll: { pane, state in
|
||||
fixPaneScrollImpl?(pane, state)
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode {
|
|||
}
|
||||
let resolveSignal: Signal<Peer?, NoError>
|
||||
if let peerName = peerName {
|
||||
resolveSignal = resolvePeerByName(account: strongSelf.context.account, name: peerName)
|
||||
resolveSignal = strongSelf.context.engine.peers.resolvePeerByName(name: peerName)
|
||||
|> mapToSignal { peerId -> Signal<Peer?, NoError> in
|
||||
if let peerId = peerId {
|
||||
return context.account.postbox.loadedPeerWithId(peerId)
|
||||
|
|
@ -786,7 +786,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode {
|
|||
|
||||
private func openPeerMention(_ name: String) {
|
||||
let postbox = self.context.account.postbox
|
||||
self.navigationActionDisposable.set((resolvePeerByName(account: self.context.account, name: name, ageLimit: 10)
|
||||
self.navigationActionDisposable.set((self.context.engine.peers.resolvePeerByName(name: name, ageLimit: 10)
|
||||
|> take(1)
|
||||
|> mapToSignal { peerId -> Signal<Peer?, NoError> in
|
||||
if let peerId = peerId {
|
||||
|
|
|
|||
|
|
@ -398,7 +398,7 @@ public func createGroupControllerImpl(context: AccountContext, peerIds: [PeerId]
|
|||
})
|
||||
}
|
||||
|
||||
venuesPromise.set(nearbyVenues(account: context.account, latitude: latitude, longitude: longitude)
|
||||
venuesPromise.set(nearbyVenues(context: context, latitude: latitude, longitude: longitude)
|
||||
|> map(Optional.init))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,17 +25,17 @@ class PaneGifSearchForQueryResult {
|
|||
}
|
||||
}
|
||||
|
||||
func paneGifSearchForQuery(account: Account, query: String, offset: String?, incompleteResults: Bool = false, staleCachedResults: Bool = false, delayRequest: Bool = true, updateActivity: ((Bool) -> Void)?) -> Signal<PaneGifSearchForQueryResult?, NoError> {
|
||||
let contextBot = account.postbox.transaction { transaction -> String in
|
||||
func paneGifSearchForQuery(context: AccountContext, query: String, offset: String?, incompleteResults: Bool = false, staleCachedResults: Bool = false, delayRequest: Bool = true, updateActivity: ((Bool) -> Void)?) -> Signal<PaneGifSearchForQueryResult?, NoError> {
|
||||
let contextBot = context.account.postbox.transaction { transaction -> String in
|
||||
let configuration = currentSearchBotsConfiguration(transaction: transaction)
|
||||
return configuration.gifBotUsername ?? "gif"
|
||||
}
|
||||
|> mapToSignal { botName -> Signal<PeerId?, NoError> in
|
||||
return resolvePeerByName(account: account, name: botName)
|
||||
return context.engine.peers.resolvePeerByName(name: botName)
|
||||
}
|
||||
|> mapToSignal { peerId -> Signal<Peer?, NoError> in
|
||||
if let peerId = peerId {
|
||||
return account.postbox.loadedPeerWithId(peerId)
|
||||
return context.account.postbox.loadedPeerWithId(peerId)
|
||||
|> map { peer -> Peer? in
|
||||
return peer
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ func paneGifSearchForQuery(account: Account, query: String, offset: String?, inc
|
|||
}
|
||||
|> mapToSignal { peer -> Signal<(ChatPresentationInputQueryResult?, Bool, Bool), NoError> in
|
||||
if let user = peer as? TelegramUser, let botInfo = user.botInfo, let _ = botInfo.inlinePlaceholder {
|
||||
let results = requestContextResults(account: account, botId: user.id, query: query, peerId: account.peerId, offset: offset ?? "", incompleteResults: incompleteResults, staleCachedResults: staleCachedResults, limit: 1)
|
||||
let results = requestContextResults(account: context.account, botId: user.id, query: query, peerId: context.account.peerId, offset: offset ?? "", incompleteResults: incompleteResults, staleCachedResults: staleCachedResults, limit: 1)
|
||||
|> map { results -> (ChatPresentationInputQueryResult?, Bool, Bool) in
|
||||
return (.contextRequestResult(user, results?.results), results != nil, results?.isStale ?? false)
|
||||
}
|
||||
|
|
@ -203,7 +203,7 @@ final class GifPaneSearchContentNode: ASDisplayNode & PaneSearchContentNode {
|
|||
|
||||
let signal: Signal<([MultiplexedVideoNodeFile], String?)?, NoError>
|
||||
if !text.isEmpty {
|
||||
signal = paneGifSearchForQuery(account: self.context.account, query: text, offset: "", updateActivity: self.updateActivity)
|
||||
signal = paneGifSearchForQuery(context: self.context, query: text, offset: "", updateActivity: self.updateActivity)
|
||||
|> map { result -> ([MultiplexedVideoNodeFile], String?)? in
|
||||
if let result = result {
|
||||
return (result.files, result.nextOffset)
|
||||
|
|
@ -252,7 +252,7 @@ final class GifPaneSearchContentNode: ASDisplayNode & PaneSearchContentNode {
|
|||
self.isLoadingNextResults = true
|
||||
|
||||
let signal: Signal<([MultiplexedVideoNodeFile], String?)?, NoError>
|
||||
signal = paneGifSearchForQuery(account: self.context.account, query: text, offset: nextOffsetValue, updateActivity: self.updateActivity)
|
||||
signal = paneGifSearchForQuery(context: self.context, query: text, offset: nextOffsetValue, updateActivity: self.updateActivity)
|
||||
|> map { result -> ([MultiplexedVideoNodeFile], String?)? in
|
||||
if let result = result {
|
||||
return (result.files, result.nextOffset)
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur
|
|||
|
||||
if let to = to {
|
||||
if to.hasPrefix("@") {
|
||||
let _ = (resolvePeerByName(account: context.account, name: String(to[to.index(to.startIndex, offsetBy: 1)...]))
|
||||
let _ = (context.engine.peers.resolvePeerByName(name: String(to[to.index(to.startIndex, offsetBy: 1)...]))
|
||||
|> deliverOnMainQueue).start(next: { peerId in
|
||||
if let peerId = peerId {
|
||||
let _ = (context.account.postbox.loadedPeerWithId(peerId)
|
||||
|
|
|
|||
|
|
@ -3230,7 +3230,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
|
|||
disposable = MetaDisposable()
|
||||
self.resolvePeerByNameDisposable = disposable
|
||||
}
|
||||
var resolveSignal = resolvePeerByName(account: self.context.account, name: name, ageLimit: 10)
|
||||
var resolveSignal = self.context.engine.peers.resolvePeerByName(name: name, ageLimit: 10)
|
||||
|
||||
var cancelImpl: (() -> Void)?
|
||||
let presentationData = self.presentationData
|
||||
|
|
@ -3294,7 +3294,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
|
|||
let account = self.context.account
|
||||
var resolveSignal: Signal<Peer?, NoError>
|
||||
if let peerName = peerName {
|
||||
resolveSignal = resolvePeerByName(account: self.context.account, name: peerName)
|
||||
resolveSignal = self.context.engine.peers.resolvePeerByName(name: peerName)
|
||||
|> mapToSignal { peerId -> Signal<Peer?, NoError> in
|
||||
if let peerId = peerId {
|
||||
return account.postbox.loadedPeerWithId(peerId)
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ func handleTextLinkActionImpl(context: AccountContext, peerId: PeerId?, navigate
|
|||
}
|
||||
|
||||
let openPeerMentionImpl: (String) -> Void = { mention in
|
||||
navigateDisposable.set((resolvePeerByName(account: context.account, name: mention, ageLimit: 10) |> take(1) |> deliverOnMainQueue).start(next: { peerId in
|
||||
navigateDisposable.set((context.engine.peers.resolvePeerByName(name: mention, ageLimit: 10) |> take(1) |> deliverOnMainQueue).start(next: { peerId in
|
||||
openResolvedPeerImpl(peerId, .default)
|
||||
}))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,13 +303,13 @@ public func parseInternalUrl(query: String) -> ParsedInternalUrl? {
|
|||
return nil
|
||||
}
|
||||
|
||||
private func resolveInternalUrl(account: Account, url: ParsedInternalUrl) -> Signal<ResolvedUrl?, NoError> {
|
||||
private func resolveInternalUrl(context: AccountContext, url: ParsedInternalUrl) -> Signal<ResolvedUrl?, NoError> {
|
||||
switch url {
|
||||
case let .peerName(name, parameter):
|
||||
return resolvePeerByName(account: account, name: name)
|
||||
return context.engine.peers.resolvePeerByName(name: name)
|
||||
|> take(1)
|
||||
|> mapToSignal { peerId -> Signal<Peer?, NoError> in
|
||||
return account.postbox.transaction { transaction -> Peer? in
|
||||
return context.account.postbox.transaction { transaction -> Peer? in
|
||||
if let peerId = peerId {
|
||||
return transaction.getPeer(peerId)
|
||||
} else {
|
||||
|
|
@ -329,7 +329,7 @@ private func resolveInternalUrl(account: Account, url: ParsedInternalUrl) -> Sig
|
|||
return .single(.channelMessage(peerId: peer.id, messageId: MessageId(peerId: peer.id, namespace: Namespaces.Message.Cloud, id: id)))
|
||||
case let .replyThread(id, replyId):
|
||||
let replyThreadMessageId = MessageId(peerId: peer.id, namespace: Namespaces.Message.Cloud, id: id)
|
||||
return fetchChannelReplyThreadMessage(account: account, messageId: replyThreadMessageId, atMessageId: nil)
|
||||
return fetchChannelReplyThreadMessage(account: context.account, messageId: replyThreadMessageId, atMessageId: nil)
|
||||
|> map(Optional.init)
|
||||
|> `catch` { _ -> Signal<ChatReplyThreadMessage?, NoError> in
|
||||
return .single(nil)
|
||||
|
|
@ -355,7 +355,7 @@ private func resolveInternalUrl(account: Account, url: ParsedInternalUrl) -> Sig
|
|||
}
|
||||
}
|
||||
case let .peerId(peerId):
|
||||
return account.postbox.transaction { transaction -> Peer? in
|
||||
return context.account.postbox.transaction { transaction -> Peer? in
|
||||
return transaction.getPeer(peerId)
|
||||
}
|
||||
|> mapToSignal { peer -> Signal<ResolvedUrl?, NoError> in
|
||||
|
|
@ -366,7 +366,7 @@ private func resolveInternalUrl(account: Account, url: ParsedInternalUrl) -> Sig
|
|||
}
|
||||
}
|
||||
case let .privateMessage(messageId, threadId):
|
||||
return account.postbox.transaction { transaction -> Peer? in
|
||||
return context.account.postbox.transaction { transaction -> Peer? in
|
||||
return transaction.getPeer(messageId.peerId)
|
||||
}
|
||||
|> mapToSignal { peer -> Signal<ResolvedUrl?, NoError> in
|
||||
|
|
@ -374,14 +374,14 @@ private func resolveInternalUrl(account: Account, url: ParsedInternalUrl) -> Sig
|
|||
if let peer = peer {
|
||||
foundPeer = .single(peer)
|
||||
} else {
|
||||
foundPeer = TelegramEngine(account: account).peers.findChannelById(channelId: messageId.peerId.id._internalGetInt32Value())
|
||||
foundPeer = TelegramEngine(account: context.account).peers.findChannelById(channelId: messageId.peerId.id._internalGetInt32Value())
|
||||
}
|
||||
return foundPeer
|
||||
|> mapToSignal { foundPeer -> Signal<ResolvedUrl?, NoError> in
|
||||
if let foundPeer = foundPeer {
|
||||
if let threadId = threadId {
|
||||
let replyThreadMessageId = MessageId(peerId: foundPeer.id, namespace: Namespaces.Message.Cloud, id: threadId)
|
||||
return fetchChannelReplyThreadMessage(account: account, messageId: replyThreadMessageId, atMessageId: nil)
|
||||
return fetchChannelReplyThreadMessage(account: context.account, messageId: replyThreadMessageId, atMessageId: nil)
|
||||
|> map(Optional.init)
|
||||
|> `catch` { _ -> Signal<ChatReplyThreadMessage?, NoError> in
|
||||
return .single(nil)
|
||||
|
|
@ -409,7 +409,7 @@ private func resolveInternalUrl(account: Account, url: ParsedInternalUrl) -> Sig
|
|||
case let .proxy(host, port, username, password, secret):
|
||||
return .single(.proxy(host: host, port: port, username: username, password: password, secret: secret))
|
||||
case let .internalInstantView(url):
|
||||
return resolveInstantViewUrl(account: account, url: url)
|
||||
return resolveInstantViewUrl(account: context.account, url: url)
|
||||
|> map(Optional.init)
|
||||
case let .confirmationCode(code):
|
||||
return .single(.confirmationCode(code))
|
||||
|
|
@ -567,7 +567,7 @@ public func resolveUrlImpl(context: AccountContext, peerId: PeerId?, url: String
|
|||
let basePrefix = scheme + basePath + "/"
|
||||
if url.lowercased().hasPrefix(basePrefix) {
|
||||
if let internalUrl = parseInternalUrl(query: String(url[basePrefix.endIndex...])) {
|
||||
return resolveInternalUrl(account: context.account, url: internalUrl)
|
||||
return resolveInternalUrl(context: context, url: internalUrl)
|
||||
|> map { resolved -> ResolvedUrl in
|
||||
if let resolved = resolved {
|
||||
return resolved
|
||||
|
|
|
|||
|
|
@ -749,7 +749,7 @@ final class WatchLocationHandler: WatchRequestHandler {
|
|||
|> take(1)
|
||||
|> mapToSignal({ context -> Signal<[ChatContextResultMessage], NoError> in
|
||||
if let context = context {
|
||||
return resolvePeerByName(account: context.account, name: "foursquare")
|
||||
return context.engine.peers.resolvePeerByName(name: "foursquare")
|
||||
|> take(1)
|
||||
|> mapToSignal { peerId -> Signal<ChatContextResultCollection?, NoError> in
|
||||
guard let peerId = peerId else {
|
||||
|
|
|
|||
|
|
@ -445,7 +445,7 @@ public final class WebSearchController: ViewController {
|
|||
}
|
||||
|
||||
let account = self.context.account
|
||||
let contextBot = resolvePeerByName(account: account, name: name)
|
||||
let contextBot = self.context.engine.peers.resolvePeerByName(name: name)
|
||||
|> mapToSignal { peerId -> Signal<Peer?, NoError> in
|
||||
if let peerId = peerId {
|
||||
return account.postbox.loadedPeerWithId(peerId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue