Fix calls
This commit is contained in:
parent
f155738b56
commit
453af1208b
@ -307,5 +307,4 @@ foreach (['my_users', 'times', 'times_messages', 'calls'] as $key) {
|
||||
}
|
||||
|
||||
$MadelineProto->setEventHandler('\EventHandler');
|
||||
|
||||
$MadelineProto->loop();
|
||||
|
@ -28,7 +28,18 @@ namespace danog\MadelineProto\VoIP;
|
||||
trait AuthKeyHandler
|
||||
{
|
||||
private $calls = [];
|
||||
|
||||
public function request_call($user)
|
||||
{
|
||||
return $this->wait($this->request_call_async($user));
|
||||
}
|
||||
public function accept_call($user)
|
||||
{
|
||||
return $this->wait($this->accept_call_async($user));
|
||||
}
|
||||
public function discard_call($user)
|
||||
{
|
||||
return $this->wait($this->discard_call_async($user));
|
||||
}
|
||||
public function request_call_async($user)
|
||||
{
|
||||
if (!class_exists('\\danog\\MadelineProto\\VoIP')) {
|
||||
|
@ -22,6 +22,14 @@ namespace danog\MadelineProto\Wrappers;
|
||||
trait DialogHandler
|
||||
{
|
||||
public function get_dialogs_async($force = true)
|
||||
{
|
||||
$res = [];
|
||||
foreach (yield $this->get_dialogs_full_async($force) as $dialog) {
|
||||
$res []= $dialog['peer'];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
public function get_dialogs_full_async($force = true)
|
||||
{
|
||||
if ($force || !isset($this->dialog_params['offset_date']) || is_null($this->dialog_params['offset_date']) || !isset($this->dialog_params['offset_id']) || is_null($this->dialog_params['offset_id']) || !isset($this->dialog_params['offset_peer']) || is_null($this->dialog_params['offset_peer']) || !isset($this->dialog_params['count']) || is_null($this->dialog_params['count'])) {
|
||||
$this->dialog_params = ['limit' => 100, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty'], 'count' => 0, 'hash' => 0];
|
||||
@ -31,30 +39,31 @@ trait DialogHandler
|
||||
}
|
||||
$res = ['dialogs' => [0], 'count' => 1];
|
||||
$datacenter = $this->datacenter->curdc;
|
||||
$peers = [];
|
||||
$dialogs = [];
|
||||
$this->postpone_updates = true;
|
||||
|
||||
try {
|
||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['getting_dialogs']);
|
||||
while ($this->dialog_params['count'] < $res['count']) {
|
||||
$res = yield $this->method_call_async_read('messages.getDialogs', $this->dialog_params, ['datacenter' => $datacenter, 'FloodWaitLimit' => 100]);
|
||||
$last_peer = [];
|
||||
$last_peer = 0;
|
||||
$last_date = 0;
|
||||
$last_id = 0;
|
||||
$res['messages'] = array_reverse($res['messages']);
|
||||
foreach (array_reverse($res['dialogs']) as $dialog) {
|
||||
if (!in_array($dialog['peer'], $peers)) {
|
||||
$peers[] = $dialog['peer'];
|
||||
$id = $this->get_id($dialog['peer']);
|
||||
if (!isset($dialogs[$id])) {
|
||||
$dialogs[$id] = $dialog;
|
||||
}
|
||||
if (!$last_date) {
|
||||
if (!$last_peer) {
|
||||
$last_peer = $dialog['peer'];
|
||||
$last_peer = $id;
|
||||
}
|
||||
if (!$last_id) {
|
||||
$last_id = $dialog['top_message'];
|
||||
}
|
||||
foreach ($res['messages'] as $message) {
|
||||
if ((yield $this->get_info_async($message))['Peer'] === $last_peer && $last_id === $message['id']) {
|
||||
if ($this->get_id($message) === $last_peer && $last_id === $message['id']) {
|
||||
$last_date = $message['date'];
|
||||
break;
|
||||
}
|
||||
@ -65,7 +74,7 @@ trait DialogHandler
|
||||
$this->dialog_params['offset_date'] = $last_date;
|
||||
$this->dialog_params['offset_peer'] = $last_peer;
|
||||
$this->dialog_params['offset_id'] = $last_id;
|
||||
$this->dialog_params['count'] = count($peers);
|
||||
$this->dialog_params['count'] = count($dialogs);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@ -75,9 +84,9 @@ trait DialogHandler
|
||||
}
|
||||
} finally {
|
||||
$this->postpone_updates = false;
|
||||
$this->handle_pending_updates_async();
|
||||
$this->callFork($this->handle_pending_updates_async());
|
||||
}
|
||||
|
||||
return $peers;
|
||||
return $dialogs;
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ $settings = json_decode(getenv('MTPROTO_SETTINGS'), true) ?: [];
|
||||
*/
|
||||
echo 'Loading MadelineProto...'.PHP_EOL;
|
||||
$MadelineProto = new \danog\MadelineProto\API(getcwd().'/testing.madeline', $settings);
|
||||
var_dump($MadelineProto->get_dialogs_full());
|
||||
|
||||
try {
|
||||
$MadelineProto->get_self();
|
||||
|
Loading…
x
Reference in New Issue
Block a user