mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-30 06:47:53 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
72 lines
2.9 KiB
Swift
72 lines
2.9 KiB
Swift
import Foundation
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
import TelegramApi
|
|
import MtProtoKit
|
|
|
|
public struct PreparedInlineMessage: Equatable {
|
|
public let botId: EnginePeer.Id
|
|
public let queryId: Int64
|
|
public let result: ChatContextResult
|
|
public let peerTypes: ReplyMarkupButtonAction.PeerTypes
|
|
}
|
|
|
|
func _internal_getPreparedInlineMessage(account: Account, botId: EnginePeer.Id, id: String) -> Signal<PreparedInlineMessage?, NoError> {
|
|
return account.postbox.transaction { transaction -> Api.InputUser? in
|
|
return transaction.getPeer(botId).flatMap(apiInputUser)
|
|
}
|
|
|> mapToSignal { inputBot -> Signal<PreparedInlineMessage?, NoError> in
|
|
guard let inputBot else {
|
|
return .single(nil)
|
|
}
|
|
return account.network.request(Api.functions.messages.getPreparedInlineMessage(bot: inputBot, id: id))
|
|
|> map(Optional.init)
|
|
|> `catch` { _ -> Signal<Api.messages.PreparedInlineMessage?, NoError> in
|
|
return .single(nil)
|
|
}
|
|
|> mapToSignal { result -> Signal<PreparedInlineMessage?, NoError> in
|
|
guard let result else {
|
|
return .single(nil)
|
|
}
|
|
return account.postbox.transaction { transaction -> PreparedInlineMessage? in
|
|
switch result {
|
|
case let .preparedInlineMessage(preparedInlineMessageData):
|
|
let (queryId, result, apiPeerTypes, cacheTime, users) = (preparedInlineMessageData.queryId, preparedInlineMessageData.result, preparedInlineMessageData.peerTypes, preparedInlineMessageData.cacheTime, preparedInlineMessageData.users)
|
|
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
|
|
let _ = cacheTime
|
|
return PreparedInlineMessage(
|
|
botId: botId,
|
|
queryId: queryId,
|
|
result: ChatContextResult(apiResult: result, queryId: queryId),
|
|
peerTypes: ReplyMarkupButtonAction.PeerTypes(apiType: apiPeerTypes)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func _internal_checkBotDownload(account: Account, botId: EnginePeer.Id, fileName: String, url: String) -> Signal<Bool, NoError> {
|
|
return account.postbox.transaction { transaction -> Api.InputUser? in
|
|
return transaction.getPeer(botId).flatMap(apiInputUser)
|
|
}
|
|
|> mapToSignal { inputBot -> Signal<Bool, NoError> in
|
|
guard let inputBot else {
|
|
return .single(false)
|
|
}
|
|
return account.network.request(Api.functions.bots.checkDownloadFileParams(bot: inputBot, fileName: fileName, url: url))
|
|
|> `catch` { _ -> Signal<Api.Bool, NoError> in
|
|
return .single(.boolFalse)
|
|
}
|
|
|> map { value in
|
|
switch value {
|
|
case .boolTrue:
|
|
return true
|
|
case .boolFalse:
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|