Bugfixes to update and peer handling

This commit is contained in:
Daniil Gentili 2017-02-05 02:02:39 +01:00
parent cd0ca879e7
commit 46acfb5812
2 changed files with 16 additions and 17 deletions

View File

@ -430,6 +430,7 @@ trait PeerHandler
$res['participants'][$key] = $newres; $res['participants'][$key] = $newres;
} }
$gres = $this->method_call('channels.getParticipants', ['channel' => $full['InputChannel'], 'filter' => ['_' => 'channelParticipantsRecent'], 'offset' => $offset += $limit, 'limit' => $limit]); $gres = $this->method_call('channels.getParticipants', ['channel' => $full['InputChannel'], 'filter' => ['_' => 'channelParticipantsRecent'], 'offset' => $offset += $limit, 'limit' => $limit]);
if (empty($gres['participants'])) break;
} }
} }
if ($fullfetch || $send) { if ($fullfetch || $send) {

View File

@ -143,9 +143,9 @@ trait UpdateHandler
$this->set_channel_state($channel, $difference); $this->set_channel_state($channel, $difference);
break; break;
case 'updates.channelDifference': case 'updates.channelDifference':
$this->set_channel_state($channel, $difference);
$this->handle_update_messages($difference['new_messages'], $channel); $this->handle_update_messages($difference['new_messages'], $channel);
$this->handle_multiple_update($difference['other_updates'], [], $channel); $this->handle_multiple_update($difference['other_updates'], [], $channel);
$this->set_channel_state($channel, $difference);
if (!$difference['final']) { if (!$difference['final']) {
unset($difference); unset($difference);
unset($input); unset($input);
@ -153,8 +153,8 @@ trait UpdateHandler
} }
break; break;
case 'updates.channelDifferenceTooLong': case 'updates.channelDifferenceTooLong':
$this->handle_update_messages($difference['messages'], $channel);
$this->set_channel_state($channel, $difference); $this->set_channel_state($channel, $difference);
$this->handle_update_messages($difference['messages'], $channel);
unset($difference); unset($difference);
unset($input); unset($input);
$this->get_channel_difference($channel); $this->get_channel_difference($channel);
@ -212,14 +212,14 @@ trait UpdateHandler
$this->set_update_state($difference); $this->set_update_state($difference);
break; break;
case 'updates.difference': case 'updates.difference':
$this->set_update_state($difference['state']);
$this->handle_multiple_update($difference['other_updates']); $this->handle_multiple_update($difference['other_updates']);
$this->handle_update_messages($difference['new_messages']); $this->handle_update_messages($difference['new_messages']);
$this->set_update_state($difference['state']);
break; break;
case 'updates.differenceSlice': case 'updates.differenceSlice':
$this->set_update_state($difference['intermediate_state']);
$this->handle_multiple_update($difference['other_updates']); $this->handle_multiple_update($difference['other_updates']);
$this->handle_update_messages($difference['new_messages']); $this->handle_update_messages($difference['new_messages']);
$this->set_update_state($difference['intermediate_state']);
unset($difference); unset($difference);
$this->get_updates_difference(); $this->get_updates_difference();
break; break;
@ -276,13 +276,13 @@ trait UpdateHandler
} else { } else {
$cur_state = &$this->get_channel_state($channel_id, (isset($update['pts']) ? $update['pts'] : 0) - (isset($update['pts_count']) ? $update['pts_count'] : 0)); $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']) { if ($cur_state['sync_loading']) {
\danog\MadelineProto\Logger::log(['Sync loading, not handling update'], \danog\MadelineProto\Logger::NOTICE); \danog\MadelineProto\Logger::log(['Sync loading, not handling update'], \danog\MadelineProto\Logger::NOTICE);
return false; // return false;
} }
*/
switch ($update['_']) { switch ($update['_']) {
case 'updateChannelTooLong': case 'updateChannelTooLong':
$this->get_channel_difference($channel_id); $this->get_channel_difference($channel_id);
@ -321,7 +321,12 @@ trait UpdateHandler
if (isset($update['pts'])) { if (isset($update['pts'])) {
$new_pts = $cur_state['pts'] + (isset($update['pts_count']) ? $update['pts_count'] : 0); $new_pts = $cur_state['pts'] + (isset($update['pts_count']) ? $update['pts_count'] : 0);
if ($new_pts < $update['pts']) { if ($update['pts'] < $new_pts) {
\danog\MadelineProto\Logger::log(['Duplicate update. current pts: '.$cur_state['pts'].' + pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).' = new pts: '.$new_pts.'. update pts: '.$update['pts'].' < new pts '.$new_pts.', channel id: '.$channel_id], \danog\MadelineProto\Logger::ERROR);
return false;
}
if ($update['pts'] > $new_pts) {
\danog\MadelineProto\Logger::log(['Pts hole. current pts: '.$cur_state['pts'].', pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).', new pts: '.$new_pts.' < update pts: '.$update['pts'].', channel id: '.$channel_id], \danog\MadelineProto\Logger::ERROR); \danog\MadelineProto\Logger::log(['Pts hole. current pts: '.$cur_state['pts'].', pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).', new pts: '.$new_pts.' < update pts: '.$update['pts'].', channel id: '.$channel_id], \danog\MadelineProto\Logger::ERROR);
$this->cur_state['pending_pts_updates'][] = $update; $this->cur_state['pending_pts_updates'][] = $update;
@ -446,18 +451,11 @@ trait UpdateHandler
} }
if ($channel === false) { if ($channel === false) {
foreach ($updates as $update) { foreach ($updates as $update) {
switch ($update['_']) {
case 'updateChannelTooLong':
case 'updateNewChannelMessage':
case 'updateEditChannelMessage':
$this->handle_update($update, $options); $this->handle_update($update, $options);
continue 2;
}
$this->save_update($update);
} }
} else { } else {
foreach ($updates as $update) { foreach ($updates as $update) {
$this->save_update($update); $this->handle_update($update);
} }
} }
} }
@ -468,7 +466,7 @@ trait UpdateHandler
return; return;
} }
foreach ($messages as $message) { foreach ($messages as $message) {
$this->save_update(['_' => $channel === false ? 'updateNewMessage' : 'updateNewChannelMessage', 'message' => $message, 'pts' => $channel === false ? $this->get_update_state()['pts'] : $this->get_channel_state($channel)['pts'], 'pts_count' => 0]); $this->handle_update(['_' => $channel === false ? 'updateNewMessage' : 'updateNewChannelMessage', 'message' => $message, 'pts' => $channel === false ? $this->get_update_state()['pts'] : $this->get_channel_state($channel)['pts'], 'pts_count' => 0]);
} }
} }