Fix inline bot geo queries

This commit is contained in:
Peter 2019-10-24 01:01:37 +04:00
parent 6f8759c501
commit 9754e564ab
2 changed files with 16 additions and 5 deletions

View File

@ -21,13 +21,24 @@ public enum RequestChatContextResultsError {
}
public func requestChatContextResults(account: Account, botId: PeerId, peerId: PeerId, query: String, location: Signal<(Double, Double)?, NoError> = .single(nil), offset: String) -> Signal<ChatContextResultCollection?, RequestChatContextResultsError> {
return combineLatest(account.postbox.transaction { transaction -> (bot: Peer, peer: Peer)? in
return account.postbox.transaction { transaction -> (bot: Peer, peer: Peer)? in
if let bot = transaction.getPeer(botId), let peer = transaction.getPeer(peerId) {
return (bot, peer)
} else {
return nil
}
}, location)
}
|> mapToSignal { botAndPeer -> Signal<((bot: Peer, peer: Peer)?, (Double, Double)?), NoError> in
if let (bot, _) = botAndPeer, let botUser = bot as? TelegramUser, let botInfo = botUser.botInfo, botInfo.flags.contains(.requiresGeolocationForInlineRequests) {
return location
|> take(1)
|> map { location -> ((bot: Peer, peer: Peer)?, (Double, Double)?) in
return (botAndPeer, location)
}
} else {
return .single((botAndPeer, nil))
}
}
|> castError(RequestChatContextResultsError.self)
|> mapToSignal { botAndPeer, location -> Signal<ChatContextResultCollection?, RequestChatContextResultsError> in
if let (bot, peer) = botAndPeer, let inputBot = apiInputUser(bot) {

View File

@ -37,7 +37,7 @@ public struct BotUserInfoFlags: OptionSet {
public static let hasAccessToChatHistory = BotUserInfoFlags(rawValue: (1 << 0))
public static let worksWithGroups = BotUserInfoFlags(rawValue: (1 << 1))
public static let requiresGeolocationForInlineRequests = BotUserInfoFlags(rawValue: (1 << 2))
public static let requiresGeolocationForInlineRequests = BotUserInfoFlags(rawValue: (1 << 3))
}
public struct BotUserInfo: PostboxCoding, Equatable {
@ -319,7 +319,7 @@ extension TelegramUser {
if (flags & (1 << 16)) == 0 {
botFlags.insert(.worksWithGroups)
}
if (flags & (1 << 21)) == 0 {
if (flags & (1 << 21)) != 0 {
botFlags.insert(.requiresGeolocationForInlineRequests)
}
botInfo = BotUserInfo(flags: botFlags, inlinePlaceholder: botInlinePlaceholder)
@ -362,7 +362,7 @@ extension TelegramUser {
if (flags & (1 << 16)) == 0 {
botFlags.insert(.worksWithGroups)
}
if (flags & (1 << 21)) == 0 {
if (flags & (1 << 21)) != 0 {
botFlags.insert(.requiresGeolocationForInlineRequests)
}
botInfo = BotUserInfo(flags: botFlags, inlinePlaceholder: botInlinePlaceholder)