From b2e9930d160a934b4541c1d89cbd45eb8c4442e1 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 30 Jul 2017 23:16:05 +0200 Subject: [PATCH] Secret chat fixes --- src/danog/MadelineProto/MTProto.php | 4 ++-- src/danog/MadelineProto/SecretChats/MessageHandler.php | 2 +- src/danog/MadelineProto/TL/TLConstructor.php | 6 +++++- tests/testing.php | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 21b98581..b20dfecc 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -44,7 +44,7 @@ class MTProto extends \Volatile use \danog\MadelineProto\Wrappers\DialogHandler; use \danog\MadelineProto\Wrappers\Login; - const V = 66; + const V = 67; const NOT_LOGGED_IN = 0; const WAITING_CODE = 1; @@ -263,7 +263,7 @@ class MTProto extends \Volatile public function __sleep() { - return ['encrypted_layer', 'settings', 'config', 'authorization', 'authorized', 'rsa_keys', 'last_recv', 'dh_config', 'chats', 'last_stored', 'qres', 'pending_updates', 'updates_state', 'got_state', 'channels_state', 'updates', 'updates_key', 'full_chats', 'msg_ids', 'dialog_params', 'datacenter', 'v', 'constructors', 'td_constructors', 'methods', 'td_methods', 'td_descriptions', 'twoe1984', 'twoe2047', 'twoe2048', 'zero', 'one', 'two', 'three', 'four', 'temp_requested_secret_chats', 'temp_rekeyed_secret_chats', 'secret_chats', 'calls', 'hook_url', 'storage', 'emojis']; + return ['encrypted_layer', 'settings', 'config', 'authorization', 'authorized', 'rsa_keys', 'last_recv', 'dh_config', 'chats', 'last_stored', 'qres', 'pending_updates', 'updates_state', 'got_state', 'channels_state', 'updates', 'updates_key', 'full_chats', 'msg_ids', 'dialog_params', 'datacenter', 'v', 'constructors', 'td_constructors', 'methods', 'td_methods', 'td_descriptions', 'twoe1984', 'twoe2047', 'twoe2048', 'zero', 'one', 'two', 'three', 'four', 'temp_requested_secret_chats', 'temp_rekeyed_secret_chats', 'secret_chats', 'hook_url', 'storage', 'emojis']; } public function __wakeup() diff --git a/src/danog/MadelineProto/SecretChats/MessageHandler.php b/src/danog/MadelineProto/SecretChats/MessageHandler.php index 0a34012b..802b6210 100644 --- a/src/danog/MadelineProto/SecretChats/MessageHandler.php +++ b/src/danog/MadelineProto/SecretChats/MessageHandler.php @@ -34,7 +34,7 @@ trait MessageHandler $this->secret_chats[$chat_id]['out_seq_no']++; } $this->secret_chats[$chat_id]['outgoing'][$this->secret_chats[$chat_id]['out_seq_no']] = $message; - $message = $this->serialize_object(['type' => $this->secret_chats[$chat_id]['layer'] === 8 ? 'DecryptedMessage' : 'DecryptedMessageLayer'], $message, 'decryptedMessage', $this->secret_chats[$chat_id]['layer']); + $message = $this->serialize_object(['type' => $constructor = $this->secret_chats[$chat_id]['layer'] === 8 ? 'DecryptedMessage' : 'DecryptedMessageLayer'], $message, $constructor, $this->secret_chats[$chat_id]['layer']); $message = $this->pack_unsigned_int(strlen($message)).$message; $message_key = substr(sha1($message, true), -16); diff --git a/src/danog/MadelineProto/TL/TLConstructor.php b/src/danog/MadelineProto/TL/TLConstructor.php index 6be0b8ad..b5c8d39d 100644 --- a/src/danog/MadelineProto/TL/TLConstructor.php +++ b/src/danog/MadelineProto/TL/TLConstructor.php @@ -64,7 +64,11 @@ class TLConstructor extends \Volatile { if ($layer !== -1) { foreach ($this->layers as $alayer) { - if ($alayer <= $layer && isset($this->by_predicate_and_layer[$predicate.$alayer])) { + if ($alayer <= $layer) { + if (isset($this->by_predicate_and_layer[$predicate.$alayer])) { + $chosenid = $this->by_predicate_and_layer[$predicate.$alayer]; + } + } else if (!isset($chosenid)) { $chosenid = $this->by_predicate_and_layer[$predicate.$alayer]; } } diff --git a/tests/testing.php b/tests/testing.php index 9ab9e080..e36d76dd 100755 --- a/tests/testing.php +++ b/tests/testing.php @@ -111,7 +111,7 @@ if (stripos(readline('Do you want to handle incoming calls? (y/n): '), 'y') !== } } } - echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL; + //echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL; } } if (stripos(readline('Do you want to make the secret chat tests? (y/n): '), 'y') !== false) {