From 7da83952345cbf079d9d4880c3fa2886ec4d9a35 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 28 May 2017 03:32:42 +0100 Subject: [PATCH] More constants and a regression to fix bugs --- src/danog/MadelineProto/MTProto.php | 431 +++++++++++++++++- .../MTProtoTools/ResponseHandler.php | 1 + .../MadelineProto/TL/Conversion/Extension.php | 386 +--------------- src/danog/MadelineProto/TL/Conversion/TD.php | 50 +- src/danog/MadelineProto/TL/TL.php | 4 +- src/danog/MadelineProto/TL/TLConstructor.php | 84 ++-- src/danog/MadelineProto/TL/TLMethod.php | 47 +- 7 files changed, 499 insertions(+), 504 deletions(-) diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 992fed17..597ab24d 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -109,6 +109,48 @@ class MTProto extends \Volatile const CONFIRMED = 2; const READY = 3; const EMOJIS = ['😉', '😍', '😛', '😭', '😱', '😡', '😎', '😴', '😵', '😈', '😬', '😇', '😏', '👮', '👷', '💂', '👶', '👨', '👩', '👴', '👵', '😻', '😽', '🙀', '👺', '🙈', '🙉', '🙊', '💀', '👽', '💩', '🔥', '💥', '💤', '👂', '👀', '👃', '👅', '👄', '👍', '👎', '👌', '👊', '✌', '✋', '👐', '👆', '👇', '👉', '👈', '🙏', '👏', '💪', '🚶', '🏃', '💃', '👫', '👪', '👬', '👭', '💅', '🎩', '👑', '👒', '👟', '👞', '👠', '👕', '👗', '👖', '👙', '👜', '👓', '🎀', '💄', '💛', '💙', '💜', '💚', '💍', '💎', '🐶', '🐺', '🐱', '🐭', '🐹', '🐰', '🐸', '🐯', '🐨', '🐻', '🐷', '🐮', '🐗', '🐴', '🐑', '🐘', '🐼', '🐧', '🐥', '🐔', '🐍', '🐢', '🐛', '🐝', '🐜', '🐞', '🐌', '🐙', '🐚', '🐟', '🐬', '🐋', '🐐', '🐊', '🐫', '🍀', '🌹', '🌻', '🍁', '🌾', '🍄', '🌵', '🌴', '🌳', '🌞', '🌚', '🌙', '🌎', '🌋', '⚡', '☔', '❄', '⛄', '🌀', '🌈', '🌊', '🎓', '🎆', '🎃', '👻', '🎅', '🎄', '🎁', '🎈', '🔮', '🎥', '📷', '💿', '💻', '☎', '📡', '📺', '📻', '🔉', '🔔', '⏳', '⏰', '⌚', '🔒', '🔑', '🔎', '💡', '🔦', '🔌', '🔋', '🚿', '🚽', '🔧', '🔨', '🚪', '🚬', '💣', '🔫', '🔪', '💊', '💉', '💰', '💵', '💳', '✉', '📫', '📦', '📅', '📁', '✂', '📌', '📎', '✒', '✏', '📐', '📚', '🔬', '🔭', '🎨', '🎬', '🎤', '🎧', '🎵', '🎹', '🎻', '🎺', '🎸', '👾', '🎮', '🃏', '🎲', '🎯', '🏈', '🏀', '⚽', '⚾', '🎾', '🎱', '🏉', '🎳', '🏁', '🏇', '🏆', '🏊', '🏄', '☕', '🍼', '🍺', '🍷', '🍴', '🍕', '🍔', '🍟', '🍗', '🍱', '🍚', '🍜', '🍡', '🍳', '🍞', '🍩', '🍦', '🎂', '🍰', '🍪', '🍫', '🍭', '🍯', '🍎', '🍏', '🍊', '🍋', '🍒', '🍇', '🍉', '🍓', '🍑', '🍌', '🍐', '🍍', '🍆', '🍅', '🌽', '🏡', '🏥', '🏦', '⛪', '🏰', '⛺', '🏭', '🗻', '🗽', '🎠', '🎡', '⛲', '🎢', '🚢', '🚤', '⚓', '🚀', '✈', '🚁', '🚂', '🚋', '🚎', '🚌', '🚙', '🚗', '🚕', '🚛', '🚨', '🚔', '🚒', '🚑', '🚲', '🚠', '🚜', '🚦', '⚠', '🚧', '⛽', '🎰', '🗿', '🎪', '🎭', '🇯🇵', '🇰🇷', '🇩🇪', '🇨🇳', '🇺🇸', '🇫🇷', '🇪🇸', '🇮🇹', '🇷🇺', '🇬🇧', '1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣', '8⃣', '9⃣', '0⃣', '🔟', '❗', '❓', '♥', '♦', '💯', '🔗', '🔱', '🔴', '🔵', '🔶', '🔷']; + const TD_PARAMS_CONVERSION = [ + 'updateNewMessage' => [ + '_' => 'updateNewMessage', + 'disable_notification' => ['message', 'silent'], + 'message' => ['message'], + ], + 'message' => [ + '_' => 'message', + 'id' => ['id'], + 'sender_user_id' => ['from_id'], + 'chat_id' => ['to_id', 'choose_chat_id_from_botapi'], + 'send_state' => ['choose_incoming_or_sent'], + 'can_be_edited' => ['choose_can_edit'], + 'can_be_deleted' => ['choose_can_delete'], + 'is_post' => ['post'], + 'date' => ['date'], + 'edit_date' => ['edit_date'], + 'forward_info' => ['fwd_info', 'choose_forward_info'], + 'reply_to_message_id' => ['reply_to_msg_id'], + 'ttl' => ['choose_ttl'], + 'ttl_expires_in' => ['choose_ttl_expires_in'], + 'via_bot_user_id' => ['via_bot_id'], + 'views' => ['views'], + 'content' => ['choose_message_content'], + 'reply_markup' => ['reply_markup'], + ], + + 'messages.sendMessage' => [ + 'chat_id' => ['peer'], + 'reply_to_message_id' => ['reply_to_msg_id'], + 'disable_notification' => ['silent'], + 'from_background' => ['background'], + 'input_message_content' => ['choose_message_content'], + 'reply_markup' => ['reply_markup'], + ], + + ]; + const TD_REVERSE = [ + 'sendMessage'=> 'messages.sendMessage', + ]; + const TD_IGNORE = ['updateMessageID']; + public $settings = []; private $config = ['expires' => -1]; @@ -132,7 +174,7 @@ class MTProto extends \Volatile private $msg_ids = []; private $v = 0; - private $dialog_params = ['_' => 'MadelineProto.DialogParams', 'limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty']]; + private $dialog_params = ['_' => 'MadelineProto.dialogParams', 'limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty']]; private $zero; private $one; private $two; @@ -246,6 +288,7 @@ class MTProto extends \Volatile } unset($this->data); } + if ($this->authorized === true) $this->authorized = self::LOGGED_IN; $this->getting_state = false; $this->reset_session(); if (!isset($this->v) || $this->v !== $this->getV()) { @@ -652,11 +695,395 @@ class MTProto extends \Volatile public function getV() { - return 35; + return 36; } public function get_self() { return $this->authorization['user']; } + const ALL_MIMES = [ + 'png' => [ + 0 => 'image/png', + 1 => 'image/x-png', + ], + 'bmp' => [ + 0 => 'image/bmp', + 1 => 'image/x-bmp', + 2 => 'image/x-bitmap', + 3 => 'image/x-xbitmap', + 4 => 'image/x-win-bitmap', + 5 => 'image/x-windows-bmp', + 6 => 'image/ms-bmp', + 7 => 'image/x-ms-bmp', + 8 => 'application/bmp', + 9 => 'application/x-bmp', + 10 => 'application/x-win-bitmap', + ], + 'gif' => [ + 0 => 'image/gif', + ], + 'jpeg' => [ + 0 => 'image/jpeg', + 1 => 'image/pjpeg', + ], + 'xspf' => [ + 0 => 'application/xspf+xml', + ], + 'vlc' => [ + 0 => 'application/videolan', + ], + 'wmv' => [ + 0 => 'video/x-ms-wmv', + 1 => 'video/x-ms-asf', + ], + 'au' => [ + 0 => 'audio/x-au', + ], + 'ac3' => [ + 0 => 'audio/ac3', + ], + 'flac' => [ + 0 => 'audio/x-flac', + ], + 'ogg' => [ + 0 => 'audio/ogg', + 1 => 'video/ogg', + 2 => 'application/ogg', + ], + 'kmz' => [ + 0 => 'application/vnd.google-earth.kmz', + ], + 'kml' => [ + 0 => 'application/vnd.google-earth.kml+xml', + ], + 'rtx' => [ + 0 => 'text/richtext', + ], + 'rtf' => [ + 0 => 'text/rtf', + ], + 'jar' => [ + 0 => 'application/java-archive', + 1 => 'application/x-java-application', + 2 => 'application/x-jar', + ], + 'zip' => [ + 0 => 'application/x-zip', + 1 => 'application/zip', + 2 => 'application/x-zip-compressed', + 3 => 'application/s-compressed', + 4 => 'multipart/x-zip', + ], + '7zip' => [ + 0 => 'application/x-compressed', + ], + 'xml' => [ + 0 => 'application/xml', + 1 => 'text/xml', + ], + 'svg' => [ + 0 => 'image/svg+xml', + ], + '3g2' => [ + 0 => 'video/3gpp2', + ], + '3gp' => [ + 0 => 'video/3gp', + 1 => 'video/3gpp', + ], + 'mp4' => [ + 0 => 'video/mp4', + ], + 'm4a' => [ + 0 => 'audio/x-m4a', + ], + 'f4v' => [ + 0 => 'video/x-f4v', + ], + 'flv' => [ + 0 => 'video/x-flv', + ], + 'webm' => [ + 0 => 'video/webm', + ], + 'aac' => [ + 0 => 'audio/x-acc', + ], + 'm4u' => [ + 0 => 'application/vnd.mpegurl', + ], + 'pdf' => [ + 0 => 'application/pdf', + 1 => 'application/octet-stream', + ], + 'pptx' => [ + 0 => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + ], + 'ppt' => [ + 0 => 'application/powerpoint', + 1 => 'application/vnd.ms-powerpoint', + 2 => 'application/vnd.ms-office', + 3 => 'application/msword', + ], + 'docx' => [ + 0 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + ], + 'xlsx' => [ + 0 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 1 => 'application/vnd.ms-excel', + ], + 'xl' => [ + 0 => 'application/excel', + ], + 'xls' => [ + 0 => 'application/msexcel', + 1 => 'application/x-msexcel', + 2 => 'application/x-ms-excel', + 3 => 'application/x-excel', + 4 => 'application/x-dos_ms_excel', + 5 => 'application/xls', + 6 => 'application/x-xls', + ], + 'xsl' => [ + 0 => 'text/xsl', + ], + 'mpeg' => [ + 0 => 'video/mpeg', + ], + 'mov' => [ + 0 => 'video/quicktime', + ], + 'avi' => [ + 0 => 'video/x-msvideo', + 1 => 'video/msvideo', + 2 => 'video/avi', + 3 => 'application/x-troff-msvideo', + ], + 'movie' => [ + 0 => 'video/x-sgi-movie', + ], + 'log' => [ + 0 => 'text/x-log', + ], + 'txt' => [ + 0 => 'text/plain', + ], + 'css' => [ + 0 => 'text/css', + ], + 'html' => [ + 0 => 'text/html', + ], + 'wav' => [ + 0 => 'audio/x-wav', + 1 => 'audio/wave', + 2 => 'audio/wav', + ], + 'xhtml' => [ + 0 => 'application/xhtml+xml', + ], + 'tar' => [ + 0 => 'application/x-tar', + ], + 'tgz' => [ + 0 => 'application/x-gzip-compressed', + ], + 'psd' => [ + 0 => 'application/x-photoshop', + 1 => 'image/vnd.adobe.photoshop', + ], + 'exe' => [ + 0 => 'application/x-msdownload', + ], + 'js' => [ + 0 => 'application/x-javascript', + ], + 'mp3' => [ + 0 => 'audio/mpeg', + 1 => 'audio/mpg', + 2 => 'audio/mpeg3', + 3 => 'audio/mp3', + ], + 'rar' => [ + 0 => 'application/x-rar', + 1 => 'application/rar', + 2 => 'application/x-rar-compressed', + ], + 'gzip' => [ + 0 => 'application/x-gzip', + ], + 'hqx' => [ + 0 => 'application/mac-binhex40', + 1 => 'application/mac-binhex', + 2 => 'application/x-binhex40', + 3 => 'application/x-mac-binhex40', + ], + 'cpt' => [ + 0 => 'application/mac-compactpro', + ], + 'bin' => [ + 0 => 'application/macbinary', + 1 => 'application/mac-binary', + 2 => 'application/x-binary', + 3 => 'application/x-macbinary', + ], + 'oda' => [ + 0 => 'application/oda', + ], + 'ai' => [ + 0 => 'application/postscript', + ], + 'smil' => [ + 0 => 'application/smil', + ], + 'mif' => [ + 0 => 'application/vnd.mif', + ], + 'wbxml' => [ + 0 => 'application/wbxml', + ], + 'wmlc' => [ + 0 => 'application/wmlc', + ], + 'dcr' => [ + 0 => 'application/x-director', + ], + 'dvi' => [ + 0 => 'application/x-dvi', + ], + 'gtar' => [ + 0 => 'application/x-gtar', + ], + 'php' => [ + 0 => 'application/x-httpd-php', + 1 => 'application/php', + 2 => 'application/x-php', + 3 => 'text/php', + 4 => 'text/x-php', + 5 => 'application/x-httpd-php-source', + ], + 'swf' => [ + 0 => 'application/x-shockwave-flash', + ], + 'sit' => [ + 0 => 'application/x-stuffit', + ], + 'z' => [ + 0 => 'application/x-compress', + ], + 'mid' => [ + 0 => 'audio/midi', + ], + 'aif' => [ + 0 => 'audio/x-aiff', + 1 => 'audio/aiff', + ], + 'ram' => [ + 0 => 'audio/x-pn-realaudio', + ], + 'rpm' => [ + 0 => 'audio/x-pn-realaudio-plugin', + ], + 'ra' => [ + 0 => 'audio/x-realaudio', + ], + 'rv' => [ + 0 => 'video/vnd.rn-realvideo', + ], + 'jp2' => [ + 0 => 'image/jp2', + 1 => 'video/mj2', + 2 => 'image/jpx', + 3 => 'image/jpm', + ], + 'tiff' => [ + 0 => 'image/tiff', + ], + 'eml' => [ + 0 => 'message/rfc822', + ], + 'pem' => [ + 0 => 'application/x-x509-user-cert', + 1 => 'application/x-pem-file', + ], + 'p10' => [ + 0 => 'application/x-pkcs10', + 1 => 'application/pkcs10', + ], + 'p12' => [ + 0 => 'application/x-pkcs12', + ], + 'p7a' => [ + 0 => 'application/x-pkcs7-signature', + ], + 'p7c' => [ + 0 => 'application/pkcs7-mime', + 1 => 'application/x-pkcs7-mime', + ], + 'p7r' => [ + 0 => 'application/x-pkcs7-certreqresp', + ], + 'p7s' => [ + 0 => 'application/pkcs7-signature', + ], + 'crt' => [ + 0 => 'application/x-x509-ca-cert', + 1 => 'application/pkix-cert', + ], + 'crl' => [ + 0 => 'application/pkix-crl', + 1 => 'application/pkcs-crl', + ], + 'pgp' => [ + 0 => 'application/pgp', + ], + 'gpg' => [ + 0 => 'application/gpg-keys', + ], + 'rsa' => [ + 0 => 'application/x-pkcs7', + ], + 'ics' => [ + 0 => 'text/calendar', + ], + 'zsh' => [ + 0 => 'text/x-scriptzsh', + ], + 'cdr' => [ + 0 => 'application/cdr', + 1 => 'application/coreldraw', + 2 => 'application/x-cdr', + 3 => 'application/x-coreldraw', + 4 => 'image/cdr', + 5 => 'image/x-cdr', + 6 => 'zz-application/zz-winassoc-cdr', + ], + 'wma' => [ + 0 => 'audio/x-ms-wma', + ], + 'vcf' => [ + 0 => 'text/x-vcard', + ], + 'srt' => [ + 0 => 'text/srt', + ], + 'vtt' => [ + 0 => 'text/vtt', + ], + 'ico' => [ + 0 => 'image/x-icon', + 1 => 'image/x-ico', + 2 => 'image/vnd.microsoft.icon', + ], + 'csv' => [ + 0 => 'text/x-comma-separated-values', + 1 => 'text/comma-separated-values', + 2 => 'application/vnd.msexcel', + ], + 'json' => [ + 0 => 'application/json', + 1 => 'text/json', + ], + ]; } diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php index 3c987ae3..5f0b4a9a 100644 --- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php @@ -48,6 +48,7 @@ trait ResponseHandler foreach ($this->datacenter->sockets[$datacenter]->new_incoming as $current_msg_id) { $unset = false; \danog\MadelineProto\Logger::log(['Received '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].'.'], \danog\MadelineProto\Logger::ULTRA_VERBOSE); + \danog\MadelineProto\Logger::log([$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']], \danog\MadelineProto\Logger::ULTRA_VERBOSE); if (\danog\MadelineProto\Logger::$has_thread && is_object(\Thread::getCurrentThread())) { if (!$this->synchronized(function ($zis, $datacenter, $current_msg_id) { if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['handling'])) { diff --git a/src/danog/MadelineProto/TL/Conversion/Extension.php b/src/danog/MadelineProto/TL/Conversion/Extension.php index 2f5ab033..5a5f0c13 100644 --- a/src/danog/MadelineProto/TL/Conversion/Extension.php +++ b/src/danog/MadelineProto/TL/Conversion/Extension.php @@ -19,394 +19,10 @@ namespace danog\MadelineProto\TL\Conversion; */ trait Extension { - public $all_mimes = [ - 'png' => [ - 0 => 'image/png', - 1 => 'image/x-png', - ], - 'bmp' => [ - 0 => 'image/bmp', - 1 => 'image/x-bmp', - 2 => 'image/x-bitmap', - 3 => 'image/x-xbitmap', - 4 => 'image/x-win-bitmap', - 5 => 'image/x-windows-bmp', - 6 => 'image/ms-bmp', - 7 => 'image/x-ms-bmp', - 8 => 'application/bmp', - 9 => 'application/x-bmp', - 10 => 'application/x-win-bitmap', - ], - 'gif' => [ - 0 => 'image/gif', - ], - 'jpeg' => [ - 0 => 'image/jpeg', - 1 => 'image/pjpeg', - ], - 'xspf' => [ - 0 => 'application/xspf+xml', - ], - 'vlc' => [ - 0 => 'application/videolan', - ], - 'wmv' => [ - 0 => 'video/x-ms-wmv', - 1 => 'video/x-ms-asf', - ], - 'au' => [ - 0 => 'audio/x-au', - ], - 'ac3' => [ - 0 => 'audio/ac3', - ], - 'flac' => [ - 0 => 'audio/x-flac', - ], - 'ogg' => [ - 0 => 'audio/ogg', - 1 => 'video/ogg', - 2 => 'application/ogg', - ], - 'kmz' => [ - 0 => 'application/vnd.google-earth.kmz', - ], - 'kml' => [ - 0 => 'application/vnd.google-earth.kml+xml', - ], - 'rtx' => [ - 0 => 'text/richtext', - ], - 'rtf' => [ - 0 => 'text/rtf', - ], - 'jar' => [ - 0 => 'application/java-archive', - 1 => 'application/x-java-application', - 2 => 'application/x-jar', - ], - 'zip' => [ - 0 => 'application/x-zip', - 1 => 'application/zip', - 2 => 'application/x-zip-compressed', - 3 => 'application/s-compressed', - 4 => 'multipart/x-zip', - ], - '7zip' => [ - 0 => 'application/x-compressed', - ], - 'xml' => [ - 0 => 'application/xml', - 1 => 'text/xml', - ], - 'svg' => [ - 0 => 'image/svg+xml', - ], - '3g2' => [ - 0 => 'video/3gpp2', - ], - '3gp' => [ - 0 => 'video/3gp', - 1 => 'video/3gpp', - ], - 'mp4' => [ - 0 => 'video/mp4', - ], - 'm4a' => [ - 0 => 'audio/x-m4a', - ], - 'f4v' => [ - 0 => 'video/x-f4v', - ], - 'flv' => [ - 0 => 'video/x-flv', - ], - 'webm' => [ - 0 => 'video/webm', - ], - 'aac' => [ - 0 => 'audio/x-acc', - ], - 'm4u' => [ - 0 => 'application/vnd.mpegurl', - ], - 'pdf' => [ - 0 => 'application/pdf', - 1 => 'application/octet-stream', - ], - 'pptx' => [ - 0 => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - ], - 'ppt' => [ - 0 => 'application/powerpoint', - 1 => 'application/vnd.ms-powerpoint', - 2 => 'application/vnd.ms-office', - 3 => 'application/msword', - ], - 'docx' => [ - 0 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - ], - 'xlsx' => [ - 0 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 1 => 'application/vnd.ms-excel', - ], - 'xl' => [ - 0 => 'application/excel', - ], - 'xls' => [ - 0 => 'application/msexcel', - 1 => 'application/x-msexcel', - 2 => 'application/x-ms-excel', - 3 => 'application/x-excel', - 4 => 'application/x-dos_ms_excel', - 5 => 'application/xls', - 6 => 'application/x-xls', - ], - 'xsl' => [ - 0 => 'text/xsl', - ], - 'mpeg' => [ - 0 => 'video/mpeg', - ], - 'mov' => [ - 0 => 'video/quicktime', - ], - 'avi' => [ - 0 => 'video/x-msvideo', - 1 => 'video/msvideo', - 2 => 'video/avi', - 3 => 'application/x-troff-msvideo', - ], - 'movie' => [ - 0 => 'video/x-sgi-movie', - ], - 'log' => [ - 0 => 'text/x-log', - ], - 'txt' => [ - 0 => 'text/plain', - ], - 'css' => [ - 0 => 'text/css', - ], - 'html' => [ - 0 => 'text/html', - ], - 'wav' => [ - 0 => 'audio/x-wav', - 1 => 'audio/wave', - 2 => 'audio/wav', - ], - 'xhtml' => [ - 0 => 'application/xhtml+xml', - ], - 'tar' => [ - 0 => 'application/x-tar', - ], - 'tgz' => [ - 0 => 'application/x-gzip-compressed', - ], - 'psd' => [ - 0 => 'application/x-photoshop', - 1 => 'image/vnd.adobe.photoshop', - ], - 'exe' => [ - 0 => 'application/x-msdownload', - ], - 'js' => [ - 0 => 'application/x-javascript', - ], - 'mp3' => [ - 0 => 'audio/mpeg', - 1 => 'audio/mpg', - 2 => 'audio/mpeg3', - 3 => 'audio/mp3', - ], - 'rar' => [ - 0 => 'application/x-rar', - 1 => 'application/rar', - 2 => 'application/x-rar-compressed', - ], - 'gzip' => [ - 0 => 'application/x-gzip', - ], - 'hqx' => [ - 0 => 'application/mac-binhex40', - 1 => 'application/mac-binhex', - 2 => 'application/x-binhex40', - 3 => 'application/x-mac-binhex40', - ], - 'cpt' => [ - 0 => 'application/mac-compactpro', - ], - 'bin' => [ - 0 => 'application/macbinary', - 1 => 'application/mac-binary', - 2 => 'application/x-binary', - 3 => 'application/x-macbinary', - ], - 'oda' => [ - 0 => 'application/oda', - ], - 'ai' => [ - 0 => 'application/postscript', - ], - 'smil' => [ - 0 => 'application/smil', - ], - 'mif' => [ - 0 => 'application/vnd.mif', - ], - 'wbxml' => [ - 0 => 'application/wbxml', - ], - 'wmlc' => [ - 0 => 'application/wmlc', - ], - 'dcr' => [ - 0 => 'application/x-director', - ], - 'dvi' => [ - 0 => 'application/x-dvi', - ], - 'gtar' => [ - 0 => 'application/x-gtar', - ], - 'php' => [ - 0 => 'application/x-httpd-php', - 1 => 'application/php', - 2 => 'application/x-php', - 3 => 'text/php', - 4 => 'text/x-php', - 5 => 'application/x-httpd-php-source', - ], - 'swf' => [ - 0 => 'application/x-shockwave-flash', - ], - 'sit' => [ - 0 => 'application/x-stuffit', - ], - 'z' => [ - 0 => 'application/x-compress', - ], - 'mid' => [ - 0 => 'audio/midi', - ], - 'aif' => [ - 0 => 'audio/x-aiff', - 1 => 'audio/aiff', - ], - 'ram' => [ - 0 => 'audio/x-pn-realaudio', - ], - 'rpm' => [ - 0 => 'audio/x-pn-realaudio-plugin', - ], - 'ra' => [ - 0 => 'audio/x-realaudio', - ], - 'rv' => [ - 0 => 'video/vnd.rn-realvideo', - ], - 'jp2' => [ - 0 => 'image/jp2', - 1 => 'video/mj2', - 2 => 'image/jpx', - 3 => 'image/jpm', - ], - 'tiff' => [ - 0 => 'image/tiff', - ], - 'eml' => [ - 0 => 'message/rfc822', - ], - 'pem' => [ - 0 => 'application/x-x509-user-cert', - 1 => 'application/x-pem-file', - ], - 'p10' => [ - 0 => 'application/x-pkcs10', - 1 => 'application/pkcs10', - ], - 'p12' => [ - 0 => 'application/x-pkcs12', - ], - 'p7a' => [ - 0 => 'application/x-pkcs7-signature', - ], - 'p7c' => [ - 0 => 'application/pkcs7-mime', - 1 => 'application/x-pkcs7-mime', - ], - 'p7r' => [ - 0 => 'application/x-pkcs7-certreqresp', - ], - 'p7s' => [ - 0 => 'application/pkcs7-signature', - ], - 'crt' => [ - 0 => 'application/x-x509-ca-cert', - 1 => 'application/pkix-cert', - ], - 'crl' => [ - 0 => 'application/pkix-crl', - 1 => 'application/pkcs-crl', - ], - 'pgp' => [ - 0 => 'application/pgp', - ], - 'gpg' => [ - 0 => 'application/gpg-keys', - ], - 'rsa' => [ - 0 => 'application/x-pkcs7', - ], - 'ics' => [ - 0 => 'text/calendar', - ], - 'zsh' => [ - 0 => 'text/x-scriptzsh', - ], - 'cdr' => [ - 0 => 'application/cdr', - 1 => 'application/coreldraw', - 2 => 'application/x-cdr', - 3 => 'application/x-coreldraw', - 4 => 'image/cdr', - 5 => 'image/x-cdr', - 6 => 'zz-application/zz-winassoc-cdr', - ], - 'wma' => [ - 0 => 'audio/x-ms-wma', - ], - 'vcf' => [ - 0 => 'text/x-vcard', - ], - 'srt' => [ - 0 => 'text/srt', - ], - 'vtt' => [ - 0 => 'text/vtt', - ], - 'ico' => [ - 0 => 'image/x-icon', - 1 => 'image/x-ico', - 2 => 'image/vnd.microsoft.icon', - ], - 'csv' => [ - 0 => 'text/x-comma-separated-values', - 1 => 'text/comma-separated-values', - 2 => 'application/vnd.msexcel', - ], - 'json' => [ - 0 => 'application/json', - 1 => 'text/json', - ], - ]; public function get_extension_from_mime($mime) { - foreach ($this->all_mimes as $key => $value) { + foreach (self::ALL_MIMES as $key => $value) { if (array_search($mime, (array) $value) !== false) { return '.'.$key; } diff --git a/src/danog/MadelineProto/TL/Conversion/TD.php b/src/danog/MadelineProto/TL/Conversion/TD.php index fe64bb33..e2152cba 100644 --- a/src/danog/MadelineProto/TL/Conversion/TD.php +++ b/src/danog/MadelineProto/TL/Conversion/TD.php @@ -14,48 +14,6 @@ namespace danog\MadelineProto\TL\Conversion; trait TD { - protected $td_params_conversion = [ - 'updateNewMessage' => [ - '_' => 'updateNewMessage', - 'disable_notification' => ['message', 'silent'], - 'message' => ['message'], - ], - 'message' => [ - '_' => 'message', - 'id' => ['id'], - 'sender_user_id' => ['from_id'], - 'chat_id' => ['to_id', 'choose_chat_id_from_botapi'], - 'send_state' => ['choose_incoming_or_sent'], - 'can_be_edited' => ['choose_can_edit'], - 'can_be_deleted' => ['choose_can_delete'], - 'is_post' => ['post'], - 'date' => ['date'], - 'edit_date' => ['edit_date'], - 'forward_info' => ['fwd_info', 'choose_forward_info'], - 'reply_to_message_id' => ['reply_to_msg_id'], - 'ttl' => ['choose_ttl'], - 'ttl_expires_in' => ['choose_ttl_expires_in'], - 'via_bot_user_id' => ['via_bot_id'], - 'views' => ['views'], - 'content' => ['choose_message_content'], - 'reply_markup' => ['reply_markup'], - ], - - 'messages.sendMessage' => [ - 'chat_id' => ['peer'], - 'reply_to_message_id' => ['reply_to_msg_id'], - 'disable_notification' => ['silent'], - 'from_background' => ['background'], - 'input_message_content' => ['choose_message_content'], - 'reply_markup' => ['reply_markup'], - ], - - ]; - protected $reverse = [ - 'sendMessage'=> 'messages.sendMessage', - ]; - protected $ignore = ['updateMessageID']; - public function tdcli_to_td(&$params, $key = null) { if (!$this->is_array($params)) { @@ -81,9 +39,9 @@ trait TD public function td_to_mtproto($params) { - $newparams = ['_' => $this->reverse[$params['_']]]; + $newparams = ['_' => self::REVERSE[$params['_']]]; - foreach ($this->td_params_conversion[$newparams['_']] as $td => $mtproto) { + foreach (self::TD_PARAMS_CONVERSION[$newparams['_']] as $td => $mtproto) { if ($this->is_array($mtproto)) { switch (end($mtproto)) { case 'choose_message_content': @@ -126,10 +84,10 @@ trait TD return $params; } $newparams = ['_' => $params['_']]; - if ($this->in_array($params['_'], $this->ignore)) { + if ($this->in_array($params['_'], self::TD_IGNORE)) { return $params; } - foreach ($this->td_params_conversion[$params['_']] as $td => $mtproto) { + foreach (self::TD_PARAMS_CONVERSION[$params['_']] as $td => $mtproto) { if (is_string($mtproto)) { $newparams[$td] = $mtproto; } else { diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index 80add788..df1d1f35 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -235,7 +235,7 @@ trait TL return $tl_elem['predicate'] === 'boolTrue'; } - public function serialize_object($type, $object, $layer = '') + public function serialize_object($type, $object, $layer = -1) { switch ($type['type']) { case 'int': @@ -390,7 +390,7 @@ trait TL return $tl['id'].$this->serialize_params($tl, $arguments); } - public function serialize_params($tl, $arguments, $layer = '') + public function serialize_params($tl, $arguments, $layer = -1) { $serialized = ''; diff --git a/src/danog/MadelineProto/TL/TLConstructor.php b/src/danog/MadelineProto/TL/TLConstructor.php index 0a8f7f94..1c8bfbe1 100644 --- a/src/danog/MadelineProto/TL/TLConstructor.php +++ b/src/danog/MadelineProto/TL/TLConstructor.php @@ -22,76 +22,74 @@ class TLConstructor extends \Volatile public $predicate = []; public $type = []; public $params = []; - public $layers = []; + public $layer = []; + public $key = 0; public function __sleep() { - return ['id', 'predicate', 'type', 'params', 'layers']; + return ['id', 'predicate', 'type', 'params', 'layer', 'key']; } public function add($json_dict, $scheme_type) { - $json_dict['id'] = 'a'.$json_dict['id']; - $json_dict['predicate'] = (string) ((($scheme_type === 'mtproto' && $json_dict['predicate'] === 'message') ? 'MT' : '').$json_dict['predicate']); - $json_dict['predicate'] .= $scheme_type === 'secret' ? $json_dict['layer'] : ''; - $this->id[$json_dict['predicate']] = $json_dict['id']; - $this->predicate[$json_dict['id']] = $json_dict['predicate']; - $this->type[$json_dict['id']] = (($scheme_type === 'mtproto' && $json_dict['type'] === 'Message') ? 'MT' : '').$json_dict['type']; - $this->params[$json_dict['id']] = $json_dict['params']; - $this->parse_params($json_dict['id'], $scheme_type === 'mtproto'); + $this->id[$this->key] = $json_dict['id']; + $this->predicate[$this->key] = (string) ((($scheme_type === 'mtproto' && $json_dict['predicate'] === 'message') ? 'MT' : '').$json_dict['predicate']); + $this->type[$this->key] = (($scheme_type === 'mtproto' && $json_dict['type'] === 'Message') ? 'MT' : '').$json_dict['type']; + $this->params[$this->key] = $json_dict['params']; if ($scheme_type === 'secret') { - $this->layers[$json_dict['layer']] = $json_dict['layer']; + $this->layer[$this->key] = $json_dict['layer']; } + $this->parse_params($this->key, $scheme_type === 'mtproto'); + $this->key++; } public function find_by_type($type) { - $id = array_search($type, (array) $this->type, true); + $key = array_search($type, (array) $this->type, true); - return ($id === false) ? false : [ - 'id' => substr($id, 1), - 'predicate' => $this->predicate[$id], - 'type' => $this->type[$id], - 'params' => $this->array_cast_recursive($this->params[$id]), + return ($key === false) ? false : [ + 'id' => $this->id[$key], + 'predicate' => $this->predicate[$key], + 'type' => $this->type[$key], + 'params' => $this->array_cast_recursive($this->params[$key]), ]; } - public function find_by_predicate($predicate, $layer = '') + public function find_by_predicate($predicate, $layer = -1) { - if ($layer !== '' && !isset($this->id[$predicate.$layer])) { - foreach ($this->layers as $newlayer) { - if (isset($this->id[$predicate.$newlayer]) || $newlayer > $layer) { - break; + if ($layer !== -1) { + $newlayer = -1; + $keys = array_keys((array) $this->predicate, $predicate); + foreach ($keys as $k) { + if ($this->layer[$k] <= $layer && $this->layer[$k] > $newlayer) { + $key = $k; + $newlayer = $this->layer[$k]; + } + if (!isset($key)) { + $key = $keys[0]; } - $nlayer = $newlayer; } - $layer = $nlayer; + } else { + $key = array_search($predicate, (array) $this->predicate, true); } - if (!isset($this->id[$predicate.$layer])) { - return false; - } - $id = $this->id[$predicate.$layer]; - return [ - 'id' => substr($id, 1), - 'predicate' => $this->predicate[$id], - 'type' => $this->type[$id], - 'params' => $this->array_cast_recursive($this->params[$id]), + return ($key === false) ? false : [ + 'id' => $this->id[$key], + 'predicate' => $this->predicate[$key], + 'type' => $this->type[$key], + 'params' => $this->array_cast_recursive($this->params[$key]), ]; } - public function find_by_id($oid) + public function find_by_id($id) { - $id = 'a'.$oid; - if (!isset($this->predicate[$id])) { - return false; - } + $key = array_search($id, (array) $this->id, true); - return [ - 'id' => $oid, - 'predicate' => $this->predicate[$id], - 'type' => $this->type[$id], - 'params' => $this->array_cast_recursive($this->params[$id]), + return ($key === false) ? false : [ + 'id' => $this->id[$key], + 'predicate' => $this->predicate[$key], + 'type' => $this->type[$key], + 'params' => $this->array_cast_recursive($this->params[$key]), ]; } } diff --git a/src/danog/MadelineProto/TL/TLMethod.php b/src/danog/MadelineProto/TL/TLMethod.php index 97dbfe15..925d5a12 100644 --- a/src/danog/MadelineProto/TL/TLMethod.php +++ b/src/danog/MadelineProto/TL/TLMethod.php @@ -22,54 +22,49 @@ class TLMethod extends \Volatile public $type = []; public $params = []; public $method_namespace = []; + public $key = 0; public function __sleep() { - return ['id', 'method', 'type', 'params', 'method_namespace']; + return ['id', 'method', 'type', 'params', 'method_namespace', 'key']; } public function add($json_dict) { - $json_dict['id'] = 'a'.$json_dict['id']; - $this->id[$json_dict['method']] = $json_dict['id']; - $this->method[$json_dict['id']] = $json_dict['method']; - $this->type[$json_dict['id']] = $json_dict['type']; - $this->params[$json_dict['id']] = $json_dict['params']; + $this->id[$this->key] = $json_dict['id']; + $this->method[$this->key] = $json_dict['method']; + $this->type[$this->key] = $json_dict['type']; + $this->params[$this->key] = $json_dict['params']; $namespace = explode('.', $json_dict['method']); if (isset($namespace[1])) { $this->method_namespace[$namespace[1]] = $namespace[0]; } - $this->parse_params($json_dict['id']); + $this->parse_params($this->key); + $this->key++; } public function find_by_method($method) { - if (!isset($this->id[$method])) { - return false; - } - $id = $this->id[$method]; + $key = array_search($method, (array) $this->method, true); - return [ - 'id' => substr($id, 1), - 'method' => $this->method[$id], - 'type' => $this->type[$id], - 'params' => $this->array_cast_recursive($this->params[$id]), + return ($key === false) ? false : [ + 'id' => $this->id[$key], + 'method' => $this->method[$key], + 'type' => $this->type[$key], + 'params' => $this->array_cast_recursive($this->params[$key]), ]; } - public function find_by_id($oid) + public function find_by_id($id) { - $id = 'a'.$oid; - if (!isset($this->method[$id])) { - return false; - } + $key = array_search($id, (array) $this->id, true); - return [ - 'id' => $oid, - 'method' => $this->method[$id], - 'type' => $this->type[$id], - 'params' => $this->array_cast_recursive($this->params[$id]), + return ($key === false) ? false : [ + 'id' => $this->id[$key], + 'method' => $this->method[$key], + 'type' => $this->type[$key], + 'params' => $this->array_cast_recursive($this->params[$key]), ]; } }