diff --git a/src/danog/MadelineProto/MTProtoTools/CallHandler.php b/src/danog/MadelineProto/MTProtoTools/CallHandler.php index f0b46941..0f7da221 100644 --- a/src/danog/MadelineProto/MTProtoTools/CallHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/CallHandler.php @@ -60,13 +60,13 @@ trait CallHandler $this->datacenter->sockets[$new_datacenter]->writer->resume(); } } - /* + public function method_call($method, $args = [], $aargs = ['msg_id' => null, 'heavy' => false]) { $promise = $this->method_call_async_read($method, $args, $aargs); return $this->wait($promise); - }*/ + } public function method_call_async_read($method, $args = [], $aargs = ['msg_id' => null, 'heavy' => false]): Promise { diff --git a/src/danog/MadelineProto/TL/Types/Button.php b/src/danog/MadelineProto/TL/Types/Button.php index 14bbba51..cd718ac4 100644 --- a/src/danog/MadelineProto/TL/Types/Button.php +++ b/src/danog/MadelineProto/TL/Types/Button.php @@ -22,6 +22,7 @@ namespace danog\MadelineProto\TL\Types; class Button implements \JsonSerializable, \ArrayAccess { use \danog\Serializable; + use \danog\MadelineProto\Tools; private $info = []; private $data = []; @@ -38,20 +39,30 @@ class Button implements \JsonSerializable, \ArrayAccess return ['data', 'info']; } - public function click($donotwait = false) + public function click($donotwait = false, $params = []) { + if (is_array($donotwait)) { + $async = $donotwait; + } else { + $async = $params; + } + $async = isset($async['async']) ? $async['async'] : (isset($this->info['API']->wrapper) ? $this->info['API']->wrapper->async : true); switch ($this->data['_']) { default: return false; case 'keyboardButtonUrl': return $this->data['url']; case 'keyboardButton': - return $this->info['API']->method_call('messages.sendMessage', ['peer' => $this->info['peer'], 'message' => $this->data['text'], 'reply_to_msg_id' => $this->info['id']], ['datacenter' => $this->info['API']->datacenter->curdc]); + $res = $this->info['API']->method_call_async_read('messages.sendMessage', ['peer' => $this->info['peer'], 'message' => $this->data['text'], 'reply_to_msg_id' => $this->info['id']], ['datacenter' => $this->info['API']->datacenter->curdc]); + break; case 'keyboardButtonCallback': - return $this->info['API']->method_call('messages.getBotCallbackAnswer', ['peer' => $this->info['peer'], 'msg_id' => $this->info['id'], 'data' => $this->data['data']], ['noResponse' => $donotwait, 'datacenter' => $this->info['API']->datacenter->curdc]); + $res = $this->info['API']->method_call_async_read('messages.getBotCallbackAnswer', ['peer' => $this->info['peer'], 'msg_id' => $this->info['id'], 'data' => $this->data['data']], ['noResponse' => $donotwait, 'datacenter' => $this->info['API']->datacenter->curdc]); + break; case 'keyboardButtonGame': - return $this->info['API']->method_call('messages.getBotCallbackAnswer', ['peer' => $this->info['peer'], 'msg_id' => $this->info['id'], 'game' => true], ['noResponse' => $donotwait, 'datacenter' => $this->info['API']->datacenter->curdc]); + $res = $this->info['API']->method_call_async_read('messages.getBotCallbackAnswer', ['peer' => $this->info['peer'], 'msg_id' => $this->info['id'], 'game' => true], ['noResponse' => $donotwait, 'datacenter' => $this->info['API']->datacenter->curdc]); + break; } + return $async ? $res : $this->wait($res); } public function __debugInfo()