Remove old synchronous methods

This commit is contained in:
Daniil Gentili 2019-05-11 17:55:30 +02:00
parent db2eadb217
commit fcad92d7cb
10 changed files with 24 additions and 50 deletions

View File

@ -9654,4 +9654,4 @@ class Lang
'object_emojiURL' => 'Emoji URL',
'object_emojiURL_param_url_type_string' => 'URL',
);
}
}

View File

@ -459,10 +459,6 @@ trait AuthKeyHandler
return true;
}
public function get_dh_config()
{
return $this->wait($this->get_dh_config_async());
}
public function get_dh_config_async()
{
$this->updates_state['sync_loading'] = true;
@ -564,11 +560,6 @@ trait AuthKeyHandler
}
// Creates authorization keys
public function init_authorization()
{
return $this->wait($this->init_authorization_async());
}
public function init_authorization_async()
{
if ($this->pending_auth) {

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

@ -146,7 +146,7 @@ trait Files
return $this->upload_async($file, $file_name, $cb, true);
}
public function gen_all_file($media, $regenerate)
public function gen_all_file_async($media, $regenerate)
{
$res = [$this->constructors->find_by_predicate($media['_'])['type'] => $media];
switch ($media['_']) {
@ -164,7 +164,7 @@ trait Files
throw new \danog\MadelineProto\Exception('No access hash');
}
$res['Photo'] = $media['photo'];
$res['InputPhoto'] = ['_' => 'inputPhoto', 'id' => $media['photo']['id'], 'access_hash' => $media['photo']['access_hash'], 'file_reference' => $this->wait($this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION, $media['photo']))];
$res['InputPhoto'] = ['_' => 'inputPhoto', 'id' => $media['photo']['id'], 'access_hash' => $media['photo']['access_hash'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION, $media['photo'])];
$res['InputMedia'] = ['_' => 'inputMediaPhoto', 'id' => $res['InputPhoto']];
if (isset($media['ttl_seconds'])) {
$res['InputMedia']['ttl_seconds'] = $media['ttl_seconds'];
@ -175,7 +175,7 @@ trait Files
throw new \danog\MadelineProto\Exception('No access hash');
}
$res['Document'] = $media['document'];
$res['InputDocument'] = ['_' => 'inputDocument', 'id' => $media['document']['id'], 'access_hash' => $media['document']['access_hash'], 'file_reference' => $this->wait($this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION, $media['document']))];
$res['InputDocument'] = ['_' => 'inputDocument', 'id' => $media['document']['id'], 'access_hash' => $media['document']['access_hash'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION, $media['document'])];
$res['InputMedia'] = ['_' => 'inputMediaDocument', 'id' => $res['InputDocument']];
if (isset($media['ttl_seconds'])) {
$res['InputMedia']['ttl_seconds'] = $media['ttl_seconds'];
@ -188,7 +188,7 @@ trait Files
if (!isset($media['access_hash'])) {
throw new \danog\MadelineProto\Exception('No access hash');
}
$res['InputDocument'] = ['_' => 'inputDocument', 'id' => $media['id'], 'access_hash' => $media['access_hash'], 'file_reference' => $this->wait($this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION, $media))];
$res['InputDocument'] = ['_' => 'inputDocument', 'id' => $media['id'], 'access_hash' => $media['access_hash'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION, $media)];
$res['InputMedia'] = ['_' => 'inputMediaDocument', 'id' => $res['InputDocument']];
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $media];
break;
@ -196,7 +196,7 @@ trait Files
if (!isset($media['access_hash'])) {
throw new \danog\MadelineProto\Exception('No access hash');
}
$res['InputPhoto'] = ['_' => 'inputPhoto', 'id' => $media['id'], 'access_hash' => $media['access_hash'], 'file_reference' => $this->wait($this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION, $media))];
$res['InputPhoto'] = ['_' => 'inputPhoto', 'id' => $media['id'], 'access_hash' => $media['access_hash'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION, $media)];
$res['InputMedia'] = ['_' => 'inputMediaPhoto', 'id' => $res['InputPhoto']];
$res['MessageMedia'] = ['_' => 'messageMediaPhoto', 'photo' => $media];
break;
@ -347,7 +347,7 @@ trait Files
throw new \danog\MadelineProto\Exception('File location unavailable');
case 'fileLocation':
$res['name'] = $message_media['volume_id'].'_'.$message_media['local_id'];
$res['InputFileLocation'] = ['_' => 'inputFileLocation', 'volume_id' => $message_media['volume_id'], 'local_id' => $message_media['local_id'], 'secret' => $message_media['secret'], 'dc_id' => $message_media['dc_id'], 'file_reference' => $this->wait($this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION_LOCATION, $message_media))];
$res['InputFileLocation'] = ['_' => 'inputFileLocation', 'volume_id' => $message_media['volume_id'], 'local_id' => $message_media['local_id'], 'secret' => $message_media['secret'], 'dc_id' => $message_media['dc_id'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION_LOCATION, $message_media)];
$res['ext'] = yield $this->get_extension_from_location_async($res['InputFileLocation'], '.jpg');
$res['mime'] = $this->get_mime_from_extension($res['ext'], 'image/jpeg');
@ -380,7 +380,7 @@ trait Files
$res['name'] .= ' - '.$audio['performer'];
}
}
$res['InputFileLocation'] = ['_' => 'inputDocumentFileLocation', 'id' => $message_media['document']['id'], 'access_hash' => $message_media['document']['access_hash'], 'version' => isset($message_media['document']['version']) ? $message_media['document']['version'] : 0, 'dc_id' => $message_media['document']['dc_id'], 'file_reference' => $this->wait($this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION_LOCATION, $message_media['document']))];
$res['InputFileLocation'] = ['_' => 'inputDocumentFileLocation', 'id' => $message_media['document']['id'], 'access_hash' => $message_media['document']['access_hash'], 'version' => isset($message_media['document']['version']) ? $message_media['document']['version'] : 0, 'dc_id' => $message_media['document']['dc_id'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION_LOCATION, $message_media['document'])];
if (!isset($res['ext'])) {
$res['ext'] = yield $this->get_extension_from_location_async($res['InputFileLocation'], $this->get_extension_from_mime($message_media['document']['mime_type']));
}

View File

@ -155,7 +155,7 @@ class ReferenceDatabase implements TLCallback
public function getConstructorSerializeCallbacks(): array
{
return array_fill_keys(array_keys(self::LOCATION_CONTEXT), [$this, 'populateReferenceSync']);
return array_fill_keys(array_keys(self::LOCATION_CONTEXT), [$this, 'populateReference']);
}
public function getTypeMismatchCallbacks(): array
@ -532,11 +532,6 @@ class ReferenceDatabase implements TLCallback
throw new Exception('Did not refresh reference');
}
public function populateReferenceSync(array $object): array
{
return $this->wait($this->populateReference($object));
}
public function populateReference(array $object): Promise
{
$deferred = new Deferred();

View File

@ -232,24 +232,24 @@ trait UpdateHandler
public function set_update_state_async($data)
{
if (isset($data['pts']) && $data['pts'] !== 0) {
yield $this->load_update_state_async()['pts'] = $data['pts'];
(yield $this->load_update_state_async())['pts'] = $data['pts'];
}
if (isset($data['qts']) && $data['qts'] !== 0) {
yield $this->load_update_state_async()['qts'] = $data['qts'];
(yield $this->load_update_state_async())['qts'] = $data['qts'];
}
if (isset($data['seq']) && $data['seq'] !== 0) {
yield $this->load_update_state_async()['seq'] = $data['seq'];
(yield $this->load_update_state_async())['seq'] = $data['seq'];
}
if (isset($data['date']) && $data['date'] > yield $this->load_update_state_async()['date']) {
yield $this->load_update_state_async()['date'] = $data['date'];
if (isset($data['date']) && $data['date'] > (yield $this->load_update_state_async())['date']) {
(yield $this->load_update_state_async())['date'] = $data['date'];
}
}
public function reset_update_state_async()
{
yield $this->load_update_state_async()['pts'] = 1;
yield $this->load_update_state_async()['qts'] = 0;
yield $this->load_update_state_async()['seq'] = 0;
yield $this->load_update_state_async()['date'] = 1;
(yield $this->load_update_state_async())['pts'] = 1;
(yield $this->load_update_state_async())['qts'] = 0;
(yield $this->load_update_state_async())['seq'] = 0;
(yield $this->load_update_state_async())['date'] = 1;
foreach ($this->channels_state as &$state) {
$state['pts'] = 1;
}
@ -283,7 +283,7 @@ trait UpdateHandler
$this->logger->logger('Fetching normal difference...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
while (!isset($difference)) {
try {
$difference = yield $this->method_call_async_read('updates.getDifference', ['pts' => yield $this->load_update_state_async()['pts'], 'date' => yield $this->load_update_state_async()['date'], 'qts' => yield $this->load_update_state_async()['qts']], ['datacenter' => $this->settings['connection_settings']['default_dc']]);
$difference = yield $this->method_call_async_read('updates.getDifference', ['pts' => (yield $this->load_update_state_async())['pts'], 'date' => (yield $this->load_update_state_async())['date'], 'qts' => (yield $this->load_update_state_async())['qts']], ['datacenter' => $this->settings['connection_settings']['default_dc']]);
} catch (\danog\MadelineProto\PTSException $e) {
$this->updates_state['sync_loading'] = false;
$this->got_state = false;
@ -388,7 +388,7 @@ trait UpdateHandler
}
if ($channel_id === false) {
$cur_state = &yield $this->load_update_state_async();
$cur_state = yield $this->load_update_state_async();
} else {
$cur_state = &$this->load_channel_state($channel_id, (isset($update['pts']) ? $update['pts'] : 0) - (isset($update['pts_count']) ? $update['pts_count'] : 0));
}
@ -519,7 +519,7 @@ trait UpdateHandler
return;
}
foreach ($messages as $message) {
yield $this->handle_update_async(['_' => $channel === false ? 'updateNewMessage' : 'updateNewChannelMessage', 'message' => $message, 'pts' => $channel === false ? yield $this->load_update_state_async()['pts'] : $this->load_channel_state($channel)['pts'], 'pts_count' => 0]);
yield $this->handle_update_async(['_' => $channel === false ? 'updateNewMessage' : 'updateNewChannelMessage', 'message' => $message, 'pts' => $channel === false ? (yield $this->load_update_state_async())['pts'] : $this->load_channel_state($channel)['pts'], 'pts_count' => 0]);
}
}

View File

@ -108,10 +108,6 @@ trait AuthKeyHandler
$this->logger->logger('Secret chat '.$params['id'].' completed successfully!', \danog\MadelineProto\Logger::NOTICE);
}
public function notify_layer($chat)
{
return $this->wait($this->notify_layer_async($chat));
}
public function notify_layer_async($chat)
{
yield $this->method_call_async_read('messages.sendEncryptedService', ['peer' => $chat, 'message' => ['_' => 'decryptedMessageService', 'action' => ['_' => 'decryptedMessageActionNotifyLayer', 'layer' => $this->encrypted_layer]]], ['datacenter' => $this->datacenter->curdc]);

View File

@ -405,7 +405,7 @@ trait TL
$object['_'] = $constructorData['predicate'];
}
if (isset($this->tl_callbacks[TLCallback::CONSTRUCTOR_SERIALIZE_CALLBACK][$object['_']])) {
$object = $this->tl_callbacks[TLCallback::CONSTRUCTOR_SERIALIZE_CALLBACK][$object['_']]($object);
$object = yield $this->tl_callbacks[TLCallback::CONSTRUCTOR_SERIALIZE_CALLBACK][$object['_']]($object);
}
$predicate = $object['_'];

View File

@ -21,10 +21,6 @@ namespace danog\MadelineProto\Wrappers;
trait DialogHandler
{
public function get_dialogs($force = true)
{
return $this->wait($this->get_dialogs_async($force));
}
public function get_dialogs_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'])) {

View File

@ -28,10 +28,6 @@ use function Amp\Promise\wait;
*/
trait Login
{
public function logout()
{
return $this->wait($this->logout_async());
}
public function logout_async()
{
foreach ($this->datacenter->sockets as $socket) {