Fixed update handling (closes #156)

This commit is contained in:
Daniil Gentili 2017-08-16 11:58:24 +02:00
parent d3724a43f2
commit 4c62140c53

View File

@ -127,20 +127,21 @@ trait UpdateHandler
}
}
/*
public function get_msg_id($peer)
public function check_msg_id($message)
{
$id = $this->get_info($peer)['bot_api_id'];
$peer_id = $this->get_info($message['to_id'])['bot_api_id'];
$message_id = $message['id'];
return isset($this->msg_ids[$id]) ? $this->msg_ids[$id] : false;
if (!isset($this->msg_ids[$peer_id]) || $message_id > $this->msg_ids[$peer_id]) {
$this->msg_ids[$peer_id] = $message_id;
return true;
}
return false;
}
public function set_msg_id($peer, $msg_id)
{
$id = $this->get_info($peer)['bot_api_id'];
$this->msg_ids[$id] = $msg_id;
}
*/
public function get_channel_difference($channel)
{
if (!$this->settings['updates']['handle_updates']) {
@ -381,7 +382,7 @@ trait UpdateHandler
}
if (isset($update['pts'])) {
if ($update['pts'] <= $cur_state['pts']) {
if ($update['pts'] < $cur_state['pts']) {
\danog\MadelineProto\Logger::log(['Duplicate update, channel id: '.$channel_id], \danog\MadelineProto\Logger::ERROR);
return false;
@ -396,10 +397,15 @@ trait UpdateHandler
return false;
}
// if ($cur_state['pts'] < $update['pts']) {
if (isset($update['message']['id'], $update['message']['to_id'])) {
if (!$this->check_msg_id($update['message'])) {
\danog\MadelineProto\Logger::log(['Duplicate update by message id, channel id: '.$channel_id], \danog\MadelineProto\Logger::ERROR);
return false;
}
}
\danog\MadelineProto\Logger::log(['Applying pts. current pts: '.$cur_state['pts'].', new pts: '.$update['pts'].', channel id: '.$channel_id], \danog\MadelineProto\Logger::VERBOSE);
$cur_state['pts'] = $update['pts'];
// }
if ($channel_id === false && isset($options['date']) && $cur_state['date'] < $options['date']) {
$cur_state['date'] = $options['date'];