mirror of
https://github.com/ichmagmaus111/ghostgram.git
synced 2026-11-03 06:14:14 +01:00
Ghostgram for iOS, rebuilt from scratch on Telegram iOS 13.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.6 KiB
Swift
48 lines
1.6 KiB
Swift
import Foundation
|
|
|
|
import AccountContext
|
|
import ChatPresentationInterfaceState
|
|
import SwiftSignalKit
|
|
import TelegramCore
|
|
|
|
/// The button a bot can put above its inline results: `switch_pm` or `switch_webview` in
|
|
/// `messages.botResults`, `InlineQueryResultsButton` in the Bot API. It does not depend on how the
|
|
/// results are presented, so a gallery (`.media`) answer carries it exactly like a list answer.
|
|
enum ChatContextResultsButton {
|
|
case switchPeer(ChatContextResultSwitchPeer)
|
|
case webView(ChatContextResultWebView)
|
|
|
|
init?(results: ChatContextResultCollection) {
|
|
if let switchPeer = results.switchPeer {
|
|
self = .switchPeer(switchPeer)
|
|
} else if let webView = results.webView {
|
|
self = .webView(webView)
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
var title: String {
|
|
switch self {
|
|
case let .switchPeer(switchPeer):
|
|
return switchPeer.text
|
|
case let .webView(webView):
|
|
return webView.text
|
|
}
|
|
}
|
|
|
|
func activate(context: AccountContext, interfaceInteraction: ChatPanelInterfaceInteraction, botId: EnginePeer.Id) {
|
|
switch self {
|
|
case let .switchPeer(switchPeer):
|
|
interfaceInteraction.botSwitchChatWithPayload(botId, switchPeer.startParam)
|
|
case let .webView(webView):
|
|
let _ = (context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: botId))
|
|
|> deliverOnMainQueue).startStandalone(next: { bot in
|
|
if let bot {
|
|
interfaceInteraction.openWebView(webView.text, webView.url, true, .inline(bot: bot))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|