Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dismiss keyboard when button pressed #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 46 additions & 44 deletions TelegramUI/ChatButtonKeyboardInputNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,54 +157,56 @@ final class ChatButtonKeyboardInputNode: ChatInputNode {
}

@objc func buttonPressed(_ button: ASButtonNode) {
if let button = button as? ChatButtonKeyboardInputButtonNode, let markupButton = button.button {
switch markupButton.action {
case .text:
self.controllerInteraction.sendMessage(markupButton.title)
case let .url(url):
self.controllerInteraction.openUrl(url, true, nil)
case .requestMap:
self.controllerInteraction.shareCurrentLocation()
case .requestPhone:
self.controllerInteraction.shareAccountContact()
case .openWebApp:
if let message = self.message {
self.controllerInteraction.requestMessageActionCallback(message.id, nil, true)
guard let markupButton = (button as? ChatButtonKeyboardInputButtonNode)?.button else { return }

self.controllerInteraction.updateInputMode({ _ in ChatInputMode.none })

switch markupButton.action {
case .text:
self.controllerInteraction.sendMessage(markupButton.title)
case let .url(url):
self.controllerInteraction.openUrl(url, true, nil)
case .requestMap:
self.controllerInteraction.shareCurrentLocation()
case .requestPhone:
self.controllerInteraction.shareAccountContact()
case .openWebApp:
if let message = self.message {
self.controllerInteraction.requestMessageActionCallback(message.id, nil, true)
}
case let .callback(data):
if let message = self.message {
self.controllerInteraction.requestMessageActionCallback(message.id, data, false)
}
case let .switchInline(samePeer, query):
if let message = message {
var botPeer: Peer?

var found = false
for attribute in message.attributes {
if let attribute = attribute as? InlineBotMessageAttribute, let peerId = attribute.peerId {
botPeer = message.peers[peerId]
found = true
}
}
case let .callback(data):
if let message = self.message {
self.controllerInteraction.requestMessageActionCallback(message.id, data, false)
if !found {
botPeer = message.author
}
case let .switchInline(samePeer, query):
if let message = message {
var botPeer: Peer?

var found = false
for attribute in message.attributes {
if let attribute = attribute as? InlineBotMessageAttribute, let peerId = attribute.peerId {
botPeer = message.peers[peerId]
found = true
}
}
if !found {
botPeer = message.author
}

var peerId: PeerId?
if samePeer {
peerId = message.id.peerId
}
if let botPeer = botPeer, let addressName = botPeer.addressName {
self.controllerInteraction.openPeer(peerId, .chat(textInputState: ChatTextInputState(inputText: NSAttributedString(string: "@\(addressName) \(query)")), messageId: nil), nil)
}

var peerId: PeerId?
if samePeer {
peerId = message.id.peerId
}
case .payment:
break
case let .urlAuth(url, buttonId):
if let message = self.message {
self.controllerInteraction.requestMessageActionUrlAuth(url, message.id, buttonId)
if let botPeer = botPeer, let addressName = botPeer.addressName {
self.controllerInteraction.openPeer(peerId, .chat(textInputState: ChatTextInputState(inputText: NSAttributedString(string: "@\(addressName) \(query)")), messageId: nil), nil)
}
}
}
case .payment:
break
case let .urlAuth(url, buttonId):
if let message = self.message {
self.controllerInteraction.requestMessageActionUrlAuth(url, message.id, buttonId)
}
}
}
}