mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Refactoring
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import Postbox
|
||||
import SwiftSignalKit
|
||||
import TelegramApi
|
||||
import MtProtoKit
|
||||
|
||||
import SyncCore
|
||||
|
||||
func _internal_supportPeerId(account: Account) -> Signal<PeerId?, NoError> {
|
||||
return account.network.request(Api.functions.help.getSupport())
|
||||
|> map(Optional.init)
|
||||
|> `catch` { _ in
|
||||
return Signal<Api.help.Support?, NoError>.single(nil)
|
||||
}
|
||||
|> mapToSignal { support -> Signal<PeerId?, NoError> in
|
||||
if let support = support {
|
||||
switch support {
|
||||
case let .support(phoneNumber: _, user: user):
|
||||
let user = TelegramUser(user: user)
|
||||
return account.postbox.transaction { transaction -> PeerId in
|
||||
updatePeers(transaction: transaction, peers: [user], update: { (previous, updated) -> Peer? in
|
||||
return updated
|
||||
})
|
||||
return user.id
|
||||
}
|
||||
}
|
||||
}
|
||||
return .single(nil)
|
||||
}
|
||||
}
|
||||
@@ -49,5 +49,13 @@ public extension TelegramEngine {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public func findChannelById(channelId: Int32) -> Signal<Peer?, NoError> {
|
||||
return _internal_findChannelById(postbox: self.account.postbox, network: self.account.network, channelId: channelId)
|
||||
}
|
||||
|
||||
public func supportPeerId() -> Signal<PeerId?, NoError> {
|
||||
return _internal_supportPeerId(account: self.account)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user