Improve update handling logic

This commit is contained in:
Daniil Gentili 2018-12-27 21:57:28 +01:00
parent 0e69468a5a
commit 1e259ae6c8
3 changed files with 12 additions and 9 deletions

View File

@ -351,6 +351,7 @@ trait PeerHandler
if (is_string($id)) { if (is_string($id)) {
$id = \danog\MadelineProto\Magic::$bigint ? (float) $id : (int) $id; $id = \danog\MadelineProto\Magic::$bigint ? (float) $id : (int) $id;
} }
if (!isset($this->chats[$id])) { if (!isset($this->chats[$id])) {
try { try {
if ($id < 0) { if ($id < 0) {

View File

@ -63,7 +63,6 @@ trait ResponseHandler
//$n = $this->n++; //$n = $this->n++;
$only_updates = true; $only_updates = true;
foreach ($this->datacenter->sockets[$datacenter]->new_incoming as $current_msg_id) { foreach ($this->datacenter->sockets[$datacenter]->new_incoming as $current_msg_id) {
//var_dump($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]);
$this->logger->logger((isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['from_container']) ? 'Inside of container, received ' : 'Received ').$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].' from DC '.$datacenter, \danog\MadelineProto\Logger::ULTRA_VERBOSE); $this->logger->logger((isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['from_container']) ? 'Inside of container, received ' : 'Received ').$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].' from DC '.$datacenter, \danog\MadelineProto\Logger::ULTRA_VERBOSE);
switch ($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_']) { switch ($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_']) {
@ -305,7 +304,6 @@ trait ResponseHandler
public function handle_response($request_id, $response_id, $datacenter) public function handle_response($request_id, $response_id, $datacenter)
{ {
//var_dumP("Response ".bin2hex($request_id));
$response = &$this->datacenter->sockets[$datacenter]->incoming_messages[$response_id]['content']; $response = &$this->datacenter->sockets[$datacenter]->incoming_messages[$response_id]['content'];
unset($this->datacenter->sockets[$datacenter]->incoming_messages[$response_id]['content']); unset($this->datacenter->sockets[$datacenter]->incoming_messages[$response_id]['content']);
$request = &$this->datacenter->sockets[$datacenter]->outgoing_messages[$request_id]; $request = &$this->datacenter->sockets[$datacenter]->outgoing_messages[$request_id];
@ -542,12 +540,10 @@ trait ResponseHandler
} }
if (count($this->pending_updates)) { if (count($this->pending_updates)) {
$this->logger->logger('Parsing pending updates...'); $this->logger->logger('Parsing pending updates...');
foreach (array_keys($this->pending_updates) as $key) { $updates = $this->pending_updates;
if (isset($this->pending_updates[$key])) { $this->pending_updates = [];
$updates = $this->pending_updates[$key]; foreach ($updates as $update) {
unset($this->pending_updates[$key]); $this->handle_updates($update);
$this->handle_updates($updates);
}
} }
} }
} }
@ -579,6 +575,7 @@ trait ResponseHandler
$opts[$key] = $updates[$key]; $opts[$key] = $updates[$key];
} }
} }
switch ($updates['_']) { switch ($updates['_']) {
case 'updates': case 'updates':
case 'updatesCombined': case 'updatesCombined':

View File

@ -405,7 +405,12 @@ trait UpdateHandler
case 'updateEditMessage': case 'updateEditMessage':
case 'updateNewChannelMessage': case 'updateNewChannelMessage':
case 'updateEditChannelMessage': case 'updateEditChannelMessage':
if (isset($update['message']['from_id']) && !$this->peer_isset($update['message']['from_id']) || !$this->peer_isset($update['message']['to_id']) || isset($update['message']['via_bot_id']) && !$this->peer_isset($update['message']['via_bot_id']) || isset($update['message']['entities']) && !$this->entities_peer_isset($update['message']['entities']) || isset($update['message']['fwd_from']) && !$this->fwd_peer_isset($update['message']['fwd_from'])) { if ((isset($update['message']['from_id']) && !$this->peer_isset($update['message']['from_id'])) ||
!$this->peer_isset($update['message']['to_id']) ||
isset($update['message']['via_bot_id']) && !$this->peer_isset($update['message']['via_bot_id']) ||
isset($update['message']['entities']) && !$this->entities_peer_isset($update['message']['entities']) // ||
//isset($update['message']['fwd_from']) && !$this->fwd_peer_isset($update['message']['fwd_from'])
) {
$this->logger->logger('Not enough data for message update, getting difference...', \danog\MadelineProto\Logger::VERBOSE); $this->logger->logger('Not enough data for message update, getting difference...', \danog\MadelineProto\Logger::VERBOSE);
if ($channel_id !== false && $this->peer_isset($this->to_supergroup($channel_id))) { if ($channel_id !== false && $this->peer_isset($this->to_supergroup($channel_id))) {
$this->get_channel_difference($channel_id); $this->get_channel_difference($channel_id);