Asyncify (4th pass)
This commit is contained in:
parent
d17daf902a
commit
bea156f064
@ -619,7 +619,7 @@ trait AuthKeyHandler
|
||||
$this->postpone_updates = false;
|
||||
$this->initing_authorization = $initing;
|
||||
$this->updates_state['sync_loading'] = false;
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -600,7 +600,7 @@ trait ResponseHandler
|
||||
|
||||
return false;
|
||||
}
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
$this->logger->logger('Parsing updates received via the socket...', \danog\MadelineProto\Logger::VERBOSE);
|
||||
|
||||
try {
|
||||
@ -627,7 +627,7 @@ trait ResponseHandler
|
||||
case 'updateShortChatMessage':
|
||||
$from_id = isset($updates['from_id']) ? $updates['from_id'] : ($updates['out'] ? $this->authorization['user']['id'] : $updates['user_id']);
|
||||
$to_id = isset($updates['chat_id']) ? -$updates['chat_id'] : ($updates['out'] ? $updates['user_id'] : $this->authorization['user']['id']);
|
||||
if (!yield $this->peer_isset_async($from_id) || !yield $this->peer_isset_async($to_id) || isset($updates['via_bot_id']) && !yield $this->peer_isset_async($updates['via_bot_id']) || isset($updates['entities']) && !$this->entities_peer_isset($updates['entities']) || isset($updates['fwd_from']) && !$this->fwd_peer_isset($updates['fwd_from'])) {
|
||||
if (!yield $this->peer_isset_async($from_id) || !yield $this->peer_isset_async($to_id) || isset($updates['via_bot_id']) && !yield $this->peer_isset_async($updates['via_bot_id']) || isset($updates['entities']) && !yield $this->entities_peer_isset_async($updates['entities']) || isset($updates['fwd_from']) && !yield $this->fwd_peer_isset_async($updates['fwd_from'])) {
|
||||
$this->logger->logger('getDifference: good - getting user for updateShortMessage', \danog\MadelineProto\Logger::VERBOSE);
|
||||
yield $this->get_updates_difference_async();
|
||||
}
|
||||
|
@ -196,8 +196,8 @@ trait UpdateHandler
|
||||
|
||||
try {
|
||||
$this->set_channel_state($channel, $difference);
|
||||
$this->handle_update_messages($difference['new_messages'], $channel);
|
||||
$this->handle_multiple_update($difference['other_updates'], [], $channel);
|
||||
yield $this->handle_update_messages_async($difference['new_messages'], $channel);
|
||||
yield $this->handle_multiple_update_async($difference['other_updates'], [], $channel);
|
||||
} finally {
|
||||
$this->postpone_updates = false;
|
||||
$this->load_channel_state($channel)['sync_loading'] = false;
|
||||
@ -214,7 +214,7 @@ trait UpdateHandler
|
||||
|
||||
try {
|
||||
$this->set_channel_state($channel, $difference);
|
||||
$this->handle_update_messages($difference['messages'], $channel);
|
||||
yield $this->handle_update_messages_async($difference['messages'], $channel);
|
||||
unset($difference);
|
||||
} finally {
|
||||
$this->postpone_updates = false;
|
||||
@ -226,7 +226,7 @@ trait UpdateHandler
|
||||
throw new \danog\MadelineProto\Exception('Unrecognized update difference received: '.var_export($difference, true));
|
||||
break;
|
||||
}
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
}
|
||||
|
||||
public function set_update_state_async($data)
|
||||
@ -305,17 +305,17 @@ trait UpdateHandler
|
||||
break;
|
||||
case 'updates.difference':
|
||||
$this->updates_state['sync_loading'] = true;
|
||||
$this->handle_multiple_update($difference['other_updates']);
|
||||
yield $this->handle_multiple_update_async($difference['other_updates']);
|
||||
foreach ($difference['new_encrypted_messages'] as $encrypted) {
|
||||
yield $this->handle_encrypted_update_async(['_' => 'updateNewEncryptedMessage', 'message' => $encrypted], true);
|
||||
}
|
||||
$this->handle_update_messages($difference['new_messages']);
|
||||
yield $this->handle_update_messages_async($difference['new_messages']);
|
||||
yield $this->set_update_state_async($difference['state']);
|
||||
break;
|
||||
case 'updates.differenceSlice':
|
||||
$this->updates_state['sync_loading'] = true;
|
||||
$this->handle_multiple_update($difference['other_updates']);
|
||||
$this->handle_update_messages($difference['new_messages']);
|
||||
yield $this->handle_multiple_update_async($difference['other_updates']);
|
||||
yield $this->handle_update_messages_async($difference['new_messages']);
|
||||
yield $this->set_update_state_async($difference['intermediate_state']);
|
||||
unset($difference);
|
||||
$this->updates_state['sync_loading'] = false;
|
||||
@ -329,7 +329,7 @@ trait UpdateHandler
|
||||
$this->postpone_updates = false;
|
||||
$this->updates_state['sync_loading'] = false;
|
||||
}
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
|
||||
if ($this->updates && $this->update_deferred) {
|
||||
$d = $this->update_deferred;
|
||||
@ -414,8 +414,8 @@ trait UpdateHandler
|
||||
if (($from = isset($update['message']['from_id']) && !yield $this->peer_isset_async($update['message']['from_id'])) ||
|
||||
($to = !yield $this->peer_isset_async($update['message']['to_id'])) ||
|
||||
($via_bot = isset($update['message']['via_bot_id']) && !yield $this->peer_isset_async($update['message']['via_bot_id'])) ||
|
||||
($entities = isset($update['message']['entities']) && !$this->entities_peer_isset($update['message']['entities'])) // ||
|
||||
//isset($update['message']['fwd_from']) && !$this->fwd_peer_isset($update['message']['fwd_from'])
|
||||
($entities = isset($update['message']['entities']) && !yield $this->entities_peer_isset_async($update['message']['entities'])) // ||
|
||||
//isset($update['message']['fwd_from']) && !yield $this->fwd_peer_isset_async($update['message']['fwd_from'])
|
||||
) {
|
||||
$log = '';
|
||||
if ($from) $log .= "from_id {$update['message']['from_id']}, ";
|
||||
|
@ -53,7 +53,7 @@ trait AuthKeyHandler
|
||||
$this->check_G($g_b, $dh_config['p']);
|
||||
yield $this->method_call_async_read('messages.acceptEncryption', ['peer' => $params['id'], 'g_b' => $g_b->toBytes(), 'key_fingerprint' => $key['fingerprint']], ['datacenter' => $this->datacenter->curdc]);
|
||||
yield $this->notify_layer_async($params['id']);
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
$this->logger->logger('Secret chat '.$params['id'].' accepted successfully!', \danog\MadelineProto\Logger::NOTICE);
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ trait AuthKeyHandler
|
||||
$this->check_G($g_a, $dh_config['p']);
|
||||
$res = yield $this->method_call_async_read('messages.requestEncryption', ['user_id' => $user, 'g_a' => $g_a->toBytes()], ['datacenter' => $this->datacenter->curdc]);
|
||||
$this->temp_requested_secret_chats[$res['id']] = $a;
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
yield $this->get_updates_difference_async();
|
||||
$this->logger->logger('Secret chat '.$res['id'].' requested successfully!', \danog\MadelineProto\Logger::NOTICE);
|
||||
|
||||
@ -104,7 +104,7 @@ trait AuthKeyHandler
|
||||
$key['visualization_46'] = substr(hash('sha256', $key['auth_key'], true), 20);
|
||||
$this->secret_chats[$params['id']] = ['key' => $key, 'admin' => true, 'user_id' => $params['participant_id'], 'InputEncryptedChat' => ['chat_id' => $params['id'], 'access_hash' => $params['access_hash'], '_' => 'inputEncryptedChat'], 'in_seq_no_x' => 0, 'out_seq_no_x' => 1, 'in_seq_no' => 0, 'out_seq_no' => 0, 'layer' => 8, 'ttl' => 0, 'ttr' => 100, 'updated' => time(), 'incoming' => [], 'outgoing' => [], 'created' => time(), 'rekeying' => [0], 'key_x' => 'to server', 'mtproto' => 1];
|
||||
yield $this->notify_layer_async($params['id']);
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
$this->logger->logger('Secret chat '.$params['id'].' completed successfully!', \danog\MadelineProto\Logger::NOTICE);
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ trait AuthKeyHandler
|
||||
$this->temp_rekeyed_secret_chats[$e] = $a;
|
||||
$this->secret_chats[$chat]['rekeying'] = [1, $e];
|
||||
yield $this->method_call_async_read('messages.sendEncryptedService', ['peer' => $chat, 'message' => ['_' => 'decryptedMessageService', 'action' => ['_' => 'decryptedMessageActionRequestKey', 'g_a' => $g_a->toBytes(), 'exchange_id' => $e]]], ['datacenter' => $this->datacenter->curdc]);
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
yield $this->get_updates_difference_async();
|
||||
|
||||
return $e;
|
||||
@ -171,7 +171,7 @@ trait AuthKeyHandler
|
||||
$g_b = $dh_config['g']->powMod($b, $dh_config['p']);
|
||||
$this->check_G($g_b, $dh_config['p']);
|
||||
yield $this->method_call_async_read('messages.sendEncryptedService', ['peer' => $chat, 'message' => ['_' => 'decryptedMessageService', 'action' => ['_' => 'decryptedMessageActionAcceptKey', 'g_b' => $g_b->toBytes(), 'exchange_id' => $params['exchange_id'], 'key_fingerprint' => $key['fingerprint']]]], ['datacenter' => $this->datacenter->curdc]);
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
yield $this->get_updates_difference_async();
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ trait AuthKeyHandler
|
||||
$this->secret_chats[$chat]['key'] = $key;
|
||||
$this->secret_chats[$chat]['ttr'] = 100;
|
||||
$this->secret_chats[$chat]['updated'] = time();
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
yield $this->get_updates_difference_async();
|
||||
}
|
||||
|
||||
|
@ -378,7 +378,7 @@ trait BotAPI
|
||||
}
|
||||
}
|
||||
|
||||
public function botAPI_to_MTProto($arguments)
|
||||
public function botAPI_to_MTProto_async($arguments)
|
||||
{
|
||||
foreach (self::BOTAPI_PARAMS_CONVERSION as $bot => $mtproto) {
|
||||
if (isset($arguments[$bot]) && !isset($arguments[$mtproto])) {
|
||||
@ -390,7 +390,7 @@ trait BotAPI
|
||||
$arguments['reply_markup'] = $this->parse_reply_markup($arguments['reply_markup']);
|
||||
}
|
||||
if (isset($arguments['parse_mode'])) {
|
||||
$arguments = $this->parse_mode($arguments);
|
||||
$arguments = yield $this->parse_mode_async($arguments);
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
@ -524,9 +524,9 @@ trait BotAPI
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
public function split_to_chunks($args)
|
||||
public function split_to_chunks_async($args)
|
||||
{
|
||||
$args = $this->parse_mode($args);
|
||||
$args = yield $this->parse_mode_async($args);
|
||||
if (!isset($args['entities'])) {
|
||||
$args['entities'] = [];
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ trait AuthKeyHandler
|
||||
$res = yield $this->method_call_async_read('phone.requestCall', ['user_id' => $user, 'g_a_hash' => hash('sha256', $g_a->toBytes(), true), 'protocol' => ['_' => 'phoneCallProtocol', 'udp_p2p' => true, 'udp_reflector' => true, 'min_layer' => 65, 'max_layer' => \danog\MadelineProto\VoIP::getConnectionMaxLayer()]], ['datacenter' => $this->datacenter->curdc]);
|
||||
$controller->setCall($res['phone_call']);
|
||||
$this->calls[$res['phone_call']['id']] = $controller;
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
yield $this->get_updates_difference_async();
|
||||
|
||||
return $controller;
|
||||
@ -102,7 +102,7 @@ trait AuthKeyHandler
|
||||
throw $e;
|
||||
}
|
||||
$this->calls[$res['phone_call']['id']]->storage['b'] = $b;
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
yield $this->get_updates_difference_async();
|
||||
|
||||
return true;
|
||||
@ -141,7 +141,7 @@ trait AuthKeyHandler
|
||||
$this->calls[$params['id']]->configuration = array_merge(['recv_timeout' => $this->config['call_receive_timeout_ms'] / 1000, 'init_timeout' => $this->config['call_connect_timeout_ms'] / 1000, 'data_saving' => \danog\MadelineProto\VoIP::DATA_SAVING_NEVER, 'enable_NS' => true, 'enable_AEC' => true, 'enable_AGC' => true, 'auth_key' => $key, 'auth_key_id' => substr(sha1($key, true), -8), 'call_id' => substr(hash('sha256', $key, true), -16), 'network_type' => \danog\MadelineProto\VoIP::NET_TYPE_ETHERNET], $this->calls[$params['id']]->configuration);
|
||||
$this->calls[$params['id']]->parseConfig();
|
||||
$res = $this->calls[$params['id']]->startTheMagic();
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ trait DialogHandler
|
||||
} finally {
|
||||
$this->postpone_updates = false;
|
||||
$this->updates_state['sync_loading'] = false;
|
||||
$this->handle_pending_updates();
|
||||
yield $this->handle_pending_updates_async();
|
||||
}
|
||||
|
||||
return $peers;
|
||||
|
Loading…
x
Reference in New Issue
Block a user