Async button click

This commit is contained in:
Daniil Gentili 2019-05-11 21:04:01 +02:00
parent fc5f2920a1
commit d44e35f514
2 changed files with 17 additions and 6 deletions

View File

@ -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
{

View File

@ -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()