Refactoring

This commit is contained in:
Ali
2021-04-18 03:10:18 +04:00
parent 4637ed672e
commit 60d959bff8
93 changed files with 221 additions and 191 deletions

View File

@@ -0,0 +1,37 @@
import Foundation
import SwiftSignalKit
import Postbox
import TelegramApi
func _internal_findChannelById(postbox: Postbox, network: Network, channelId: Int32) -> Signal<Peer?, NoError> {
return network.request(Api.functions.channels.getChannels(id: [.inputChannel(channelId: channelId, accessHash: 0)]))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.messages.Chats?, NoError> in
return .single(nil)
}
|> mapToSignal { result -> Signal<Peer?, NoError> in
guard let result = result else {
return .single(nil)
}
let chats: [Api.Chat]
switch result {
case let .chats(apiChats):
chats = apiChats
case let .chatsSlice(_, apiChats):
chats = apiChats
}
guard let chat = chats.first else {
return .single(nil)
}
guard let peer = parseTelegramGroupOrChannel(chat: chat) else {
return .single(nil)
}
return postbox.transaction { transaction -> Peer? in
updatePeers(transaction: transaction, peers: [peer], update: { _, updated in
return updated
})
return peer
}
}
}