Improvements to update and peer handling.

This commit is contained in:
Daniil Gentili 2018-03-14 12:36:50 +00:00
parent f2a3f460a6
commit 3c16430b06
3 changed files with 32 additions and 13 deletions

View File

@ -146,18 +146,18 @@ trait PeerHandler
if (!isset($this->chats[$bot_api_id]) || $this->chats[$bot_api_id] !== $chat) {
$this->chats[$bot_api_id] = $chat;
if (!isset($this->full_chats[$bot_api_id]) || $this->full_chats[$bot_api_id]['full']['participants_count'] !== $this->get_full_info($bot_api_id)['full']['participants_count']) {
if ($this->postpone_pwrchat) {
$this->pending_pwrchat[$this->to_supergroup($chat['id'])] = [$this->settings['peer']['full_fetch'], true];
} else {
try {
try {
if (!isset($this->full_chats[$bot_api_id]) || $this->full_chats[$bot_api_id]['full']['participants_count'] !== $this->get_full_info($bot_api_id)['full']['participants_count']) {
if ($this->postpone_pwrchat) {
$this->pending_pwrchat[$this->to_supergroup($chat['id'])] = [$this->settings['peer']['full_fetch'], true];
} else {
$this->get_pwr_chat($this->to_supergroup($chat['id']), $this->settings['peer']['full_fetch'], true);
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
}
}
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
}
}
break;

View File

@ -407,9 +407,12 @@ trait ResponseHandler
}
if (count($this->pending_updates)) {
\danog\MadelineProto\Logger::log('Parsing pending updates...');
foreach ($this->pending_updates as $key => $updates) {
unset($this->pending_updates[$key]);
$this->handle_updates($updates);
foreach (array_keys($this->pending_updates) as $key) {
if (isset($this->pending_updates[$key])) {
$updates = $this->pending_updates[$key];
unset($this->pending_updates[$key]);
$this->handle_updates($updates);
}
}
}
}

View File

@ -184,6 +184,7 @@ trait UpdateHandler
return;
}
$this->load_channel_state($channel)['sync_loading'] = true;
$this->postpone_updates = true;
try {
$input = $this->get_info('channel#'.$channel);
@ -196,10 +197,12 @@ trait UpdateHandler
} catch (\danog\MadelineProto\RPCErrorException $e) {
return false;
} finally {
$this->postpone_updates = false;
$this->load_channel_state($channel)['sync_loading'] = false;
}
$this->load_channel_state($channel)['sync_loading'] = true;
\danog\MadelineProto\Logger::log('Fetching '.$channel.' difference...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->load_channel_state($channel)['sync_loading'] = true;
$this->postpone_updates = true;
try {
$difference = $this->method_call('updates.getChannelDifference', ['channel' => $input, 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $this->load_channel_state($channel)['pts'], 'limit' => 30], ['datacenter' => $this->datacenter->curdc]);
@ -215,21 +218,25 @@ trait UpdateHandler
return $this->get_channel_difference($channel);
} finally {
$this->postpone_updates = false;
$this->load_channel_state($channel)['sync_loading'] = false;
}
unset($input);
switch ($difference['_']) {
case 'updates.channelDifferenceEmpty':
$this->set_channel_state($channel, $difference);
break;
case 'updates.channelDifference':
$this->load_channel_state($channel)['sync_loading'] = true;
$this->postpone_updates = true;
try {
$this->set_channel_state($channel, $difference);
$this->handle_update_messages($difference['new_messages'], $channel);
$this->handle_multiple_update($difference['other_updates'], [], $channel);
} finally {
$this->postpone_updates = false;
$this->load_channel_state($channel)['sync_loading'] = false;
}
if (!$difference['final']) {
@ -240,12 +247,14 @@ trait UpdateHandler
case 'updates.channelDifferenceTooLong':
\danog\MadelineProto\Logger::log('Got '.$difference['_'], \danog\MadelineProto\Logger::VERBOSE);
$this->load_channel_state($channel)['sync_loading'] = true;
$this->postpone_updates = true;
try {
$this->set_channel_state($channel, $difference);
$this->handle_update_messages($difference['messages'], $channel);
unset($difference);
} finally {
$this->postpone_updates = false;
$this->load_channel_state($channel)['sync_loading'] = false;
}
$this->get_channel_difference($channel);
@ -254,6 +263,7 @@ trait UpdateHandler
throw new \danog\MadelineProto\Exception('Unrecognized update difference received: '.var_export($difference, true));
break;
}
$this->handle_pending_updates();
}
public function set_update_state($data)
@ -296,6 +306,7 @@ trait UpdateHandler
return false;
}
$this->updates_state['sync_loading'] = true;
$this->postpone_updates = true;
\danog\MadelineProto\Logger::log('Fetching normal difference...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
while (!isset($difference)) {
try {
@ -304,10 +315,13 @@ trait UpdateHandler
$this->updates_state['sync_loading'] = false;
$this->got_state = false;
} finally {
$this->postpone_updates = false;
$this->updates_state['sync_loading'] = false;
}
}
\danog\MadelineProto\Logger::log('Got '.$difference['_'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->postpone_updates = true;
$this->updates_state['sync_loading'] = true;
try {
switch ($difference['_']) {
@ -337,8 +351,10 @@ trait UpdateHandler
break;
}
} finally {
$this->postpone_updates = false;
$this->updates_state['sync_loading'] = false;
}
$this->handle_pending_updates();
}
public function get_updates_state()