Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2017-06-06 15:47:42 +00:00 committed by StyleCI Bot
parent 0c968af317
commit 0ad8859b6e
10 changed files with 61 additions and 43 deletions

View File

@ -31,7 +31,6 @@ if (file_exists('.env')) {
echo 'Loading settings...'.PHP_EOL; echo 'Loading settings...'.PHP_EOL;
$settings = json_decode(getenv('MTPROTO_SETTINGS'), true) ?: []; $settings = json_decode(getenv('MTPROTO_SETTINGS'), true) ?: [];
if ($MadelineProto === false) { if ($MadelineProto === false) {
echo 'Loading MadelineProto...'.PHP_EOL; echo 'Loading MadelineProto...'.PHP_EOL;
$MadelineProto = new \danog\MadelineProto\API($settings); $MadelineProto = new \danog\MadelineProto\API($settings);
@ -88,11 +87,15 @@ while (true) {
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['to_id'], 'message' => $update['update']['message']['message']]); $MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['to_id'], 'message' => $update['update']['message']['message']]);
break;*/ break;*/
case 'updateNewMessage': case 'updateNewMessage':
if ($update['update']['message']['out'] || $update['update']['message']['message'] === '') continue; if ($update['update']['message']['out'] || $update['update']['message']['message'] === '') {
continue;
}
break; break;
case 'updateNewEncryptedMessage': case 'updateNewEncryptedMessage':
var_dump($MadelineProto->download_to_dir($update['update']['message'], '.')); var_dump($MadelineProto->download_to_dir($update['update']['message'], '.'));
if (isset($sent[$update['update']['message']['chat_id']])) continue; if (isset($sent[$update['update']['message']['chat_id']])) {
continue;
}
$i = 0; $i = 0;
while ($i < $argv[1]) { while ($i < $argv[1]) {
echo "SENDING MESSAGE $i TO ".$update['update']['message']['chat_id'].PHP_EOL; echo "SENDING MESSAGE $i TO ".$update['update']['message']['chat_id'].PHP_EOL;
@ -104,6 +107,8 @@ while (true) {
} }
} catch (\danog\MadelineProto\RPCErrorException $e) { } catch (\danog\MadelineProto\RPCErrorException $e) {
var_dump($e); var_dump($e);
} catch (\danog\MadelineProto\Exception $e) { var_dump($e->getMessage()); } } catch (\danog\MadelineProto\Exception $e) {
var_dump($e->getMessage());
}
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('s.madeline', $MadelineProto).' bytes'.PHP_EOL; echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('s.madeline', $MadelineProto).' bytes'.PHP_EOL;
} }

View File

@ -289,13 +289,13 @@ class MTProto extends \Volatile
if ($this->authorized === true) { if ($this->authorized === true) {
$this->authorized = self::LOGGED_IN; $this->authorized = self::LOGGED_IN;
} }
$this->updates_state["sync_loading"] = false; $this->updates_state['sync_loading'] = false;
foreach ($this->channels_state as &$state) { foreach ($this->channels_state as &$state) {
$state['sync_loading'] = false; $state['sync_loading'] = false;
} }
foreach (debug_backtrace(0) as $trace) { foreach (debug_backtrace(0) as $trace) {
if (isset($trace['function']) && isset($trace['class']) && $trace['function'] === 'deserialize' && $trace['class'] === 'danog\MadelineProto\Serialization') { if (isset($trace['function']) && isset($trace['class']) && $trace['function'] === 'deserialize' && $trace['class'] === 'danog\MadelineProto\Serialization') {
$this->updates_state["sync_loading"] = isset($trace['args'][1]) && $trace['args'][1]; $this->updates_state['sync_loading'] = isset($trace['args'][1]) && $trace['args'][1];
} }
} }
@ -321,7 +321,7 @@ class MTProto extends \Volatile
if ($this->authorized === self::LOGGED_IN && !$this->authorization['user']['bot']) { if ($this->authorized === self::LOGGED_IN && !$this->authorization['user']['bot']) {
$this->get_dialogs(); $this->get_dialogs();
} }
if ($this->authorized === self::LOGGED_IN && $this->settings['updates']['handle_updates'] && !$this->updates_state["sync_loading"]) { if ($this->authorized === self::LOGGED_IN && $this->settings['updates']['handle_updates'] && !$this->updates_state['sync_loading']) {
\danog\MadelineProto\Logger::log(['Getting updates after deserialization...'], Logger::NOTICE); \danog\MadelineProto\Logger::log(['Getting updates after deserialization...'], Logger::NOTICE);
$this->get_updates_difference(); $this->get_updates_difference();
} }
@ -508,10 +508,10 @@ class MTProto extends \Volatile
'msg_array_limit' => [ // How big should be the arrays containing the incoming and outgoing messages? 'msg_array_limit' => [ // How big should be the arrays containing the incoming and outgoing messages?
'incoming' => 200, 'incoming' => 200,
'outgoing' => 200, 'outgoing' => 200,
'call_queue' => 200 'call_queue' => 200,
], ],
'peer' => [ 'peer' => [
'full_info_cache_time' => 60 'full_info_cache_time' => 60,
], ],
'updates' => [ 'updates' => [
'handle_updates' => true, // Should I handle updates? 'handle_updates' => true, // Should I handle updates?
@ -599,7 +599,7 @@ class MTProto extends \Volatile
public function init_authorization() public function init_authorization()
{ {
$this->initing_authorization = true; $this->initing_authorization = true;
$this->updates_state["sync_loading"] = true; $this->updates_state['sync_loading'] = true;
foreach ($this->datacenter->sockets as $id => $socket) { foreach ($this->datacenter->sockets as $id => $socket) {
if (strpos($id, 'media')) { if (strpos($id, 'media')) {
continue; continue;
@ -624,12 +624,12 @@ class MTProto extends \Volatile
} }
} }
$this->initing_authorization = false; $this->initing_authorization = false;
$this->updates_state["sync_loading"] = false; $this->updates_state['sync_loading'] = false;
} }
public function sync_authorization($authorized_dc) public function sync_authorization($authorized_dc)
{ {
$this->updates_state["sync_loading"] = true; $this->updates_state['sync_loading'] = true;
foreach ($this->datacenter->sockets as $new_dc => $socket) { foreach ($this->datacenter->sockets as $new_dc => $socket) {
if (($int_dc = preg_replace('|/D+|', '', $new_dc)) == $authorized_dc) { if (($int_dc = preg_replace('|/D+|', '', $new_dc)) == $authorized_dc) {
continue; continue;
@ -646,7 +646,7 @@ class MTProto extends \Volatile
$this->method_call('auth.logOut', [], ['datacenter' => $new_dc]); $this->method_call('auth.logOut', [], ['datacenter' => $new_dc]);
$this->method_call('auth.importAuthorization', $exported_authorization, ['datacenter' => $new_dc]); $this->method_call('auth.importAuthorization', $exported_authorization, ['datacenter' => $new_dc]);
} }
$this->updates_state["sync_loading"] = false; $this->updates_state['sync_loading'] = false;
} }
public function write_client_info($method, $arguments = [], $options = []) public function write_client_info($method, $arguments = [], $options = [])

View File

@ -509,9 +509,9 @@ trait AuthKeyHandler
public function get_dh_config() public function get_dh_config()
{ {
$this->updates_state["sync_loading"] = true; $this->updates_state['sync_loading'] = true;
$dh_config = $this->method_call('messages.getDhConfig', ['version' => $this->dh_config['version'], 'random_length' => 0], ['datacenter' => $this->datacenter->curdc]); $dh_config = $this->method_call('messages.getDhConfig', ['version' => $this->dh_config['version'], 'random_length' => 0], ['datacenter' => $this->datacenter->curdc]);
$this->updates_state["sync_loading"] = false; $this->updates_state['sync_loading'] = false;
if ($dh_config['_'] === 'messages.dhConfigNotModified') { if ($dh_config['_'] === 'messages.dhConfigNotModified') {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Logger::VERBOSE, ['DH configuration not modified']); \danog\MadelineProto\Logger::log(\danog\MadelineProto\Logger::VERBOSE, ['DH configuration not modified']);

View File

@ -50,10 +50,14 @@ trait CallHandler
} }
$args['chat_id'] = $res['chat_id']; $args['chat_id'] = $res['chat_id'];
} }
if (in_array($method, ['messages.setEncryptedTyping', 'messages.readEncryptedHistory', 'messages.sendEncrypted', 'messages.sendEncryptedFile', 'messages.sendEncryptedService', 'messages.receivedQueue'])) $aargs['queue'] = 'secret'; if (in_array($method, ['messages.setEncryptedTyping', 'messages.readEncryptedHistory', 'messages.sendEncrypted', 'messages.sendEncryptedFile', 'messages.sendEncryptedService', 'messages.receivedQueue'])) {
$aargs['queue'] = 'secret';
}
if (isset($aargs['queue'])) { if (isset($aargs['queue'])) {
$queue = $aargs['queue']; $queue = $aargs['queue'];
if (!isset($this->datacenter->sockets[$aargs['datacenter']]->call_queue[$queue])) $this->datacenter->sockets[$aargs['datacenter']]->call_queue[$queue] = []; if (!isset($this->datacenter->sockets[$aargs['datacenter']]->call_queue[$queue])) {
$this->datacenter->sockets[$aargs['datacenter']]->call_queue[$queue] = [];
}
unset($aargs['queue']); unset($aargs['queue']);
} }
@ -65,8 +69,8 @@ trait CallHandler
} }
$last_recv = $this->last_recv; $last_recv = $this->last_recv;
if ($canunset = !$this->updates_state["sync_loading"] && !$this->threads && !$this->run_workers) { if ($canunset = !$this->updates_state['sync_loading'] && !$this->threads && !$this->run_workers) {
$this->updates_state["sync_loading"] = true; $this->updates_state['sync_loading'] = true;
} }
for ($count = 1; $count <= $this->settings['max_tries']['query']; $count++) { for ($count = 1; $count <= $this->settings['max_tries']['query']; $count++) {
try { try {
@ -150,7 +154,7 @@ trait CallHandler
} }
if ($canunset) { if ($canunset) {
$this->updates_state["sync_loading"] = false; $this->updates_state['sync_loading'] = false;
$this->handle_pending_updates(); $this->handle_pending_updates();
} }
if ($server_answer === null) { if ($server_answer === null) {
@ -220,7 +224,7 @@ trait CallHandler
unset($this->datacenter->sockets[$aargs['datacenter']]->new_outgoing[$message_id]); unset($this->datacenter->sockets[$aargs['datacenter']]->new_outgoing[$message_id]);
} }
if ($canunset) { if ($canunset) {
$this->updates_state["sync_loading"] = false; $this->updates_state['sync_loading'] = false;
$this->handle_pending_updates(); $this->handle_pending_updates();
} }
} }
@ -263,7 +267,9 @@ trait CallHandler
} }
for ($count = 1; $count <= $this->settings['max_tries']['query']; $count++) { for ($count = 1; $count <= $this->settings['max_tries']['query']; $count++) {
try { try {
if ($object !== 'msgs_ack') \danog\MadelineProto\Logger::log(['Sending object (try number '.$count.' for '.$object.')...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE); if ($object !== 'msgs_ack') {
\danog\MadelineProto\Logger::log(['Sending object (try number '.$count.' for '.$object.')...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
}
$message_id = $this->send_message($this->serialize_object(['type' => $object], $args), $this->content_related($object), $aargs); $message_id = $this->send_message($this->serialize_object(['type' => $object], $args), $this->content_related($object), $aargs);
if ($object !== 'msgs_ack') { if ($object !== 'msgs_ack') {
$this->datacenter->sockets[$aargs['datacenter']]->outgoing_messages[$message_id]['content'] = ['method' => $object, 'args' => $args]; $this->datacenter->sockets[$aargs['datacenter']]->outgoing_messages[$message_id]['content'] = ['method' => $object, 'args' => $args];

View File

@ -112,7 +112,7 @@ trait Files
} }
if (isset($message_media['decrypted_message']['media']['mime_type'])) { if (isset($message_media['decrypted_message']['media']['mime_type'])) {
$res['mime'] = $message_media['decrypted_message']['media']['mime_type']; $res['mime'] = $message_media['decrypted_message']['media']['mime_type'];
} else if ($message_media['decrypted_message']['media']['_'] === 'decryptedMessageMediaPhoto') { } elseif ($message_media['decrypted_message']['media']['_'] === 'decryptedMessageMediaPhoto') {
$res['mime'] = 'image/jpeg'; $res['mime'] = 'image/jpeg';
} }

View File

@ -351,7 +351,9 @@ trait ResponseHandler
public function handle_pending_updates() public function handle_pending_updates()
{ {
if ($this->updates_state["sync_loading"]) return false; if ($this->updates_state['sync_loading']) {
return false;
}
if (count($this->pending_updates)) { if (count($this->pending_updates)) {
\danog\MadelineProto\Logger::log(['Parsing pending updates...'], \danog\MadelineProto\Logger::VERBOSE); \danog\MadelineProto\Logger::log(['Parsing pending updates...'], \danog\MadelineProto\Logger::VERBOSE);
foreach ($this->pending_updates as $key => $updates) { foreach ($this->pending_updates as $key => $updates) {

View File

@ -136,6 +136,7 @@ trait UpdateHandler
} }
if ($this->load_channel_state($channel)['sync_loading']) { if ($this->load_channel_state($channel)['sync_loading']) {
\danog\MadelineProto\Logger::log(['Not fetching '.$channel.' difference, I am already fetching it']); \danog\MadelineProto\Logger::log(['Not fetching '.$channel.' difference, I am already fetching it']);
return; return;
} }
$this->load_channel_state($channel)['sync_loading'] = true; $this->load_channel_state($channel)['sync_loading'] = true;
@ -147,9 +148,11 @@ trait UpdateHandler
$input = $input['InputChannel']; $input = $input['InputChannel'];
} catch (\danog\MadelineProto\Exception $e) { } catch (\danog\MadelineProto\Exception $e) {
$this->load_channel_state($channel)['sync_loading'] = false; $this->load_channel_state($channel)['sync_loading'] = false;
return false; return false;
} catch (\danog\MadelineProto\RPCErrorException $e) { } catch (\danog\MadelineProto\RPCErrorException $e) {
$this->load_channel_state($channel)['sync_loading'] = false; $this->load_channel_state($channel)['sync_loading'] = false;
return false; return false;
} }
\danog\MadelineProto\Logger::log(['Fetching '.$channel.' difference...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE); \danog\MadelineProto\Logger::log(['Fetching '.$channel.' difference...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
@ -226,11 +229,12 @@ trait UpdateHandler
if (!$this->settings['updates']['handle_updates']) { if (!$this->settings['updates']['handle_updates']) {
return; return;
} }
if ($this->updates_state["sync_loading"]) { if ($this->updates_state['sync_loading']) {
\danog\MadelineProto\Logger::log(['Not fetching normal difference, I am already fetching it']); \danog\MadelineProto\Logger::log(['Not fetching normal difference, I am already fetching it']);
return false; return false;
} }
$this->updates_state["sync_loading"] = true; $this->updates_state['sync_loading'] = true;
\danog\MadelineProto\Logger::log(['Fetching normal difference...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE); \danog\MadelineProto\Logger::log(['Fetching normal difference...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
@ -238,7 +242,7 @@ trait UpdateHandler
try { try {
$difference = $this->method_call('updates.getDifference', ['pts' => $this->load_update_state()['pts'], 'date' => $this->load_update_state()['date'], 'qts' => $this->load_update_state()['qts']], ['datacenter' => $this->datacenter->curdc]); $difference = $this->method_call('updates.getDifference', ['pts' => $this->load_update_state()['pts'], 'date' => $this->load_update_state()['date'], 'qts' => $this->load_update_state()['qts']], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\PTSException $e) { } catch (\danog\MadelineProto\PTSException $e) {
$this->updates_state["sync_loading"] = false; $this->updates_state['sync_loading'] = false;
$this->got_state = false; $this->got_state = false;
} }
} }
@ -262,14 +266,14 @@ trait UpdateHandler
$this->handle_update_messages($difference['new_messages']); $this->handle_update_messages($difference['new_messages']);
$this->set_update_state($difference['intermediate_state']); $this->set_update_state($difference['intermediate_state']);
unset($difference); unset($difference);
$this->updates_state["sync_loading"] = false; $this->updates_state['sync_loading'] = false;
$this->get_updates_difference(); $this->get_updates_difference();
break; break;
default: default:
throw new \danog\MadelineProto\Exception('Unrecognized update difference received: '.var_export($difference, true)); throw new \danog\MadelineProto\Exception('Unrecognized update difference received: '.var_export($difference, true));
break; break;
} }
$this->updates_state["sync_loading"] = false; $this->updates_state['sync_loading'] = false;
} }
public function get_updates_state() public function get_updates_state()
@ -389,6 +393,7 @@ trait UpdateHandler
if ($seq_start != $cur_state['seq'] + 1 && $seq_start > $cur_state['seq']) { if ($seq_start != $cur_state['seq'] + 1 && $seq_start > $cur_state['seq']) {
\danog\MadelineProto\Logger::log(['Seq hole. seq_start: '.$seq_start.' != cur seq: '.$cur_state['seq'].' + 1'], \danog\MadelineProto\Logger::ERROR); \danog\MadelineProto\Logger::log(['Seq hole. seq_start: '.$seq_start.' != cur seq: '.$cur_state['seq'].' + 1'], \danog\MadelineProto\Logger::ERROR);
$this->get_updates_difference(); $this->get_updates_difference();
return false; return false;
} }
@ -400,10 +405,8 @@ trait UpdateHandler
} }
} }
$this->save_update($update); $this->save_update($update);
} }
public function handle_multiple_update($updates, $options = [], $channel = false) public function handle_multiple_update($updates, $options = [], $channel = false)
{ {
if (!$this->settings['updates']['handle_updates']) { if (!$this->settings['updates']['handle_updates']) {
@ -568,5 +571,4 @@ trait UpdateHandler
} }
} }
} }
} }

View File

@ -22,7 +22,8 @@ trait AuthKeyHandler
protected $temp_requested_secret_chats = []; protected $temp_requested_secret_chats = [];
protected $secret_chats = []; protected $secret_chats = [];
public function accept_secret_chat($params) { public function accept_secret_chat($params)
{
//var_dump($params['id'],$this->secret_chat_status($params['id'])); //var_dump($params['id'],$this->secret_chat_status($params['id']));
if ($this->secret_chat_status($params['id']) !== 0) { if ($this->secret_chat_status($params['id']) !== 0) {
//var_dump($this->secret_chat_status($params['id'])); //var_dump($this->secret_chat_status($params['id']));
@ -140,6 +141,7 @@ trait AuthKeyHandler
} }
if ($my_exchange_id === $other_exchange_id) { if ($my_exchange_id === $other_exchange_id) {
$this->secret_chats[$chat]['rekeying'] = [0]; $this->secret_chats[$chat]['rekeying'] = [0];
return; return;
} }
} }
@ -231,7 +233,8 @@ trait AuthKeyHandler
return $this->secret_chats[$chat]; return $this->secret_chats[$chat];
} }
public function discard_secret_chat($chat) { public function discard_secret_chat($chat)
{
\danog\MadelineProto\Logger::log(['Discarding secret chat '.$chat.'...'], \danog\MadelineProto\Logger::VERBOSE); \danog\MadelineProto\Logger::log(['Discarding secret chat '.$chat.'...'], \danog\MadelineProto\Logger::VERBOSE);
//var_dump(debug_backtrace(0)[0]); //var_dump(debug_backtrace(0)[0]);
if (isset($this->secret_chats[$chat])) { if (isset($this->secret_chats[$chat])) {
@ -246,8 +249,9 @@ trait AuthKeyHandler
try { try {
$this->method_call('messages.discardEncryption', ['chat_id' => $chat], ['datacenter' => $this->datacenter->curdc]); $this->method_call('messages.discardEncryption', ['chat_id' => $chat], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\RPCErrorException $e) { } catch (\danog\MadelineProto\RPCErrorException $e) {
if ($e->rpc !== "ENCRYPTION_ALREADY_DECLINED") throw $e; if ($e->rpc !== 'ENCRYPTION_ALREADY_DECLINED') {
throw $e;
}
} }
} }
} }

View File

@ -19,7 +19,7 @@ trait DialogHandler
if (!isset($this->dialog_params['offset_date']) || $force) { if (!isset($this->dialog_params['offset_date']) || $force) {
$this->dialog_params = ['limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty']]; $this->dialog_params = ['limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty']];
} }
$this->updates_state["sync_loading"] = true; $this->updates_state['sync_loading'] = true;
$res = ['dialogs' => [0]]; $res = ['dialogs' => [0]];
$datacenter = $this->datacenter->curdc; $datacenter = $this->datacenter->curdc;
$count = 0; $count = 0;
@ -36,6 +36,6 @@ trait DialogHandler
} }
} }
$this->updates_state["sync_loading"] = false; $this->updates_state['sync_loading'] = false;
} }
} }

View File

@ -32,7 +32,6 @@ trait Login
\danog\MadelineProto\Logger::log(['Logged out successfully!'], \danog\MadelineProto\Logger::NOTICE); \danog\MadelineProto\Logger::log(['Logged out successfully!'], \danog\MadelineProto\Logger::NOTICE);
return true; return true;
} }