From ad9591c71bc2559d0680fb3ee787ec153e2cc518 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 31 Dec 2016 12:32:02 +0100 Subject: [PATCH] Fixed some bugs --- .../MTProtoTools/PeerHandler.php | 21 ++++++++++++------- .../MTProtoTools/ResponseHandler.php | 4 ++-- .../MTProtoTools/UpdateHandler.php | 8 +++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index d4e4ab80..e8541a88 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -24,7 +24,7 @@ trait PeerHandler foreach ($users as $key => $user) { switch ($user['_']) { case 'user': - if (!isset($this->chats[$user['id']])) { + if (!isset($this->chats[$user['id']]) || $this->chats[$user['id']] !== $user) { $this->chats[$user['id']] = $user; $this->should_serialize = true; } @@ -43,7 +43,7 @@ trait PeerHandler switch ($chat['_']) { case 'chat': case 'chatEmpty': - if (!isset($this->chats[-$chat['id']])) { + if (!isset($this->chats[-$chat['id']]) || $this->chats[-$chat['id']] !== $chat) { $this->should_serialize = true; $this->chats[-$chat['id']] = $chat; } @@ -52,7 +52,7 @@ trait PeerHandler case 'channelEmpty': break; case 'channel': - if (!isset($this->chats[(int) ('-100'.$chat['id'])])) { + if (!isset($this->chats[(int) ('-100'.$chat['id'])]) || $this->chats[(int) ('-100'.$chat['id'])] !== $chat) { $this->should_serialize = true; $this->chats[(int) ('-100'.$chat['id'])] = $chat; } @@ -184,8 +184,13 @@ trait PeerHandler $res = [$this->constructors->find_by_predicate($constructor['_'])['type'] => $constructor]; switch ($constructor['_']) { case 'user': - $res['InputPeer'] = $constructor['self'] ? ['_' => 'inputPeerSelf'] : ['_' => 'inputPeerUser', 'user_id' => $constructor['id'], 'access_hash' => $constructor['access_hash']]; - $res['InputUser'] = $constructor['self'] ? ['_' => 'inputUserSelf'] : ['_' => 'inputUser', 'user_id' => $constructor['id'], 'access_hash' => $constructor['access_hash']]; + if ($constructor['self']) { + $res['InputPeer'] = ['_' => 'inputPeerSelf']; + $res['InputUser'] = ['_' => 'inputUserSelf']; + } else if (isset($constructor['access_hash'])) { + $res['InputPeer'] = ['_' => 'inputPeerUser', 'user_id' => $constructor['id'], 'access_hash' => $constructor['access_hash']]; + $res['InputUser'] = ['_' => 'inputUser', 'user_id' => $constructor['id'], 'access_hash' => $constructor['access_hash']]; + } $res['Peer'] = ['_' => 'peerUser', 'user_id' => $constructor['id']]; $res['user_id'] = $constructor['id']; $res['bot_api_id'] = $constructor['id']; @@ -197,8 +202,10 @@ trait PeerHandler $res['bot_api_id'] = -$constructor['id']; break; case 'channel': - $res['InputPeer'] = ['_' => 'inputPeerChannel', 'channel_id' => $constructor['id'], 'access_hash' => $constructor['access_hash']]; - $res['InputChannel'] = ['_' => 'inputChannel', 'channel_id' => $constructor['id'], 'access_hash' => $constructor['access_hash']]; + if (isset($constructor['access_hash'])) { + $res['InputPeer'] = ['_' => 'inputPeerChannel', 'channel_id' => $constructor['id'], 'access_hash' => $constructor['access_hash']]; + $res['InputChannel'] = ['_' => 'inputChannel', 'channel_id' => $constructor['id'], 'access_hash' => $constructor['access_hash']]; + } $res['Peer'] = ['_' => 'peerChannel', 'channel_id' => $constructor['id']]; $res['channel_id'] = $constructor['id']; $res['bot_api_id'] = (int) ('-100'.$constructor['id']); diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php index 15b5d395..10a73f32 100644 --- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php @@ -287,8 +287,8 @@ trait ResponseHandler if (!$this->peer_isset($from_id) || !$this->peer_isset($to_id) || - (isset($updates['via_bot_id']) && !$this->peer_isset($updates['via_bot_id'])) - (isset($updates['entities']) && !$this->entities_peer_isset($updates['entites'])) + (isset($updates['via_bot_id']) && !$this->peer_isset($updates['via_bot_id'])) || + (isset($updates['entities']) && !$this->entities_peer_isset($updates['entites'])) || (isset($updates['fwd_from']) && !$this->fwd_peer_isset($updates['fwd_from']))) { \danog\MadelineProto\Logger::log('getDifference: good - getting user for updateShortMessage'); diff --git a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php index fe53e9d5..9e14c624 100644 --- a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php @@ -92,9 +92,9 @@ trait UpdateHandler } break; case 'updates.channelDifferenceTooLong': - unset($this->channels_state[$channel]); + //unset($this->channels_state[$channel]); //unset($this->chats[$this->get_info('channel#'.$channel)['bot_api_id']]); - //$this->handle_update_messages($difference['messages'], $channel); + $this->handle_update_messages($difference['messages'], $channel); break; default: throw new \danog\MadelineProto\Exception('Unrecognized update difference received: '.var_export($difference, true)); @@ -200,12 +200,12 @@ trait UpdateHandler } else { $cur_state = &$this->get_channel_state($channel_id, (isset($update['pts']) ? $update['pts'] : 0) - (isset($update['pts_count']) ? $update['pts_count'] : 0)); } -/* + if ($cur_state['sync_loading']) { \danog\MadelineProto\Logger::log('Sync loading, not handling update'); return false; } -*/ + switch ($update['_']) { case 'updateChannelTooLong': \danog\MadelineProto\Logger::log('Got channel too long update, getting difference...');