FInal improvements to channels

This commit is contained in:
Daniil Gentili 2019-09-14 13:31:52 +00:00
parent 5570f9ddc9
commit 38c29240ad
5 changed files with 56 additions and 24 deletions

2
docs

@ -1 +1 @@
Subproject commit 042cc04351a461f551a9de7bf704290040910b37
Subproject commit fe346258733323e5173e674f15059dea1a1eb880

View File

@ -266,7 +266,9 @@ class FeedLoop extends ResumableSignalLoop
continue;
}
$this->API->logger->logger('Getdiff fed me message of type '.$message['_']." in $this...", \danog\MadelineProto\Logger::VERBOSE);
if ($message['_'] !== 'messageEmpty') {
$this->API->logger->logger('Getdiff fed me message of type '.$message['_']." in $this...", \danog\MadelineProto\Logger::VERBOSE);
}
$this->parsedUpdates[] = ['_' => $this->channelId === false ? 'updateNewMessage' : 'updateNewChannelMessage', 'message' => $message, 'pts' => -1, 'pts_count' => -1];
}

View File

@ -191,10 +191,13 @@ class UpdateLoop extends ResumableSignalLoop
}
}
}
$API->logger->logger("Finished parsing updates in $this, now resuming feeders");
foreach ($result as $channelId => $boh) {
$API->feeders[$channelId]->resumeDefer();
}
$API->logger->logger("Finished resuming feeders in $this, signaling updates");
$API->signalUpdate();
$API->logger->logger("Finished signaling updates in $this, pausing");
$first = false;
if (yield $this->waitSignal($this->pause($timeout))) {

View File

@ -87,6 +87,11 @@ class MinDatabase implements TLCallback
public function init()
{
foreach ($this->db as $id => $origin) {
if ($origin['peer'] === $id) {
unset($this->db[$id]);
}
}
}
public function getMethodCallbacks(): array
@ -225,6 +230,7 @@ class MinDatabase implements TLCallback
throw new \danog\MadelineProto\Exception("Unknown origin type provided: {$data['_']}");
}
foreach ($cache as $id) {
if ($origin['peer'] === $id) continue;
$this->db[$id] = $origin;
}
$this->API->logger->logger("Added origin ({$data['_']}) to ".\count($cache).' peer locations', \danog\MadelineProto\Logger::ULTRA_VERBOSE);

View File

@ -54,15 +54,12 @@ trait PeerHandler
public function add_user($user)
{
if (!isset($user['access_hash'])) {
/*if (isset($this->chats[$user['id']]['access_hash']) && $this->chats[$user['id']]['access_hash']) {
$this->logger->logger("No access hash with user {$user['id']}, using backup");
$user['access_hash'] = $this->chats[$user['id']]['access_hash'];
} else {
$this->logger->logger("No access hash with user {$user['id']}, not trying to fetch it");
$user['access_hash'] = 0;
}*/
if (!isset($this->caching_simple[$user['id']]) && !(isset($user['username']) && isset($this->caching_simple_username[$user['username']]))) {
if (!isset($user['access_hash']) && !($user['min'] ?? false)) {
if (isset($this->chats[$user['id']]['access_hash']) && $this->chats[$user['id']]['access_hash']) {
$this->logger->logger("No access hash with user {$user['id']}, using backup");
$user['access_hash'] = $this->chats[$user['id']]['access_hash'];
} else if (!isset($this->caching_simple[$user['id']]) && !(isset($user['username']) && isset($this->caching_simple_username[$user['username']]))) {
$this->logger->logger("No access hash with user {$user['id']}, trying to fetch by ID...");
if (isset($user['username']) && !isset($this->caching_simple_username[$user['username']])) {
$this->caching_possible_username[$user['id']] = $user['username'];
@ -81,7 +78,19 @@ trait PeerHandler
case 'user':
if (!isset($this->chats[$user['id']]) || $this->chats[$user['id']] !== $user) {
$this->logger->logger("Updated user {$user['id']}", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->chats[$user['id']] = $user;
if (($user['min'] ?? false) && isset($this->chats[$user['id']]) && !($this->chats[$user['id']]['min'] ?? false)) {
$this->logger->logger("{$user['id']} is min, filling missing fields", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$newuser = $this->chats[$user['id']];
foreach (['title', 'username', 'photo', 'banned_rights', 'megagroup', 'verified'] as $field) {
if (isset($user[$field])) {
$newuser[$field] = $user[$field];
}
}
$user = $newuser;
}
$this->users[$user['id']] = $user;
$this->cache_pwr_chat($user['id'], false, true);
}
break;
@ -130,6 +139,17 @@ trait PeerHandler
if (!isset($this->chats[$bot_api_id]) || $this->chats[$bot_api_id] !== $chat) {
$this->logger->logger("Updated chat $bot_api_id", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
if (($chat['min'] ?? false) && isset($this->chats[$bot_api_id]) && !($this->chats[$bot_api_id]['min'] ?? false)) {
$this->logger->logger("$bot_api_id is min, filling missing fields", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$newchat = $this->chats[$bot_api_id];
foreach (['title', 'username', 'photo', 'banned_rights', 'megagroup', 'verified'] as $field) {
if (isset($chat[$field])) {
$newchat[$field] = $chat[$field];
}
}
$chat = $newchat;
}
$this->chats[$bot_api_id] = $chat;
if ($this->settings['peer']['full_fetch'] && (!isset($this->full_chats[$bot_api_id]) || $this->full_chats[$bot_api_id]['full']['participants_count'] !== (yield $this->get_full_info_async($bot_api_id))['full']['participants_count'])) {
@ -415,13 +435,13 @@ trait PeerHandler
}
}
if (isset($this->chats[$id])) {
if ($this->chats[$id]['min'] ?? false && $this->minDatabase->hasPeer($id)) {
if (($this->chats[$id]['min'] ?? false) && $this->minDatabase->hasPeer($id)) {
$this->logger->logger("Only have min peer for $id in database, trying to fetch full info");
try {
if ($id < 0) {
yield $this->method_call_async_read('channels.getChannels', ['id' => [$this->from_supergroup($id)]], ['datacenter' => $this->datacenter->curdc]);
yield $this->method_call_async_read('channels.getChannels', ['id' => [$this->gen_all($this->chats[$id], $folder_id)['InputChannel']]], ['datacenter' => $this->datacenter->curdc]);
} else {
yield $this->method_call_async_read('users.getUsers', ['id' => [$id]], ['datacenter' => $this->datacenter->curdc]);
yield $this->method_call_async_read('users.getUsers', ['id' => [$this->gen_all($this->chats[$id], $folder_id)['InputUser']]], ['datacenter' => $this->datacenter->curdc]);
}
} catch (\danog\MadelineProto\Exception $e) {
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
@ -487,19 +507,20 @@ trait PeerHandler
return yield $this->get_info_async($this->supportUser);
}
foreach ($this->chats as $chat) {
foreach ($this->chats as $bot_api_id => $chat) {
if (isset($chat['username']) && \strtolower($chat['username']) === $id) {
if ($this->chats[$id]['min'] ?? false) {
if ($id < 0) {
if ($this->is_supergroup($id)) {
yield $this->method_call_async_read('channels.getChannels', ['id' => [['access_hash' => 0, 'channel_id' => $this->from_supergroup($id), '_' => 'inputChannel']]], ['datacenter' => $this->datacenter->curdc]);
$this->logger->logger("Only have min peer for $bot_api_id in database, trying to fetch full info");
try {
if ($bot_api_id < 0) {
yield $this->method_call_async_read('channels.getChannels', ['id' => [$this->gen_all($this->chats[$bot_api_id], $folder_id)['InputChannel']]], ['datacenter' => $this->datacenter->curdc]);
} else {
yield $this->method_call_async_read('messages.getFullChat', ['chat_id' => -$id], ['datacenter' => $this->datacenter->curdc]);
yield $this->method_call_async_read('users.getUsers', ['id' => [$this->gen_all($this->chats[$bot_api_id], $folder_id)['InputUser']]], ['datacenter' => $this->datacenter->curdc]);
}
} else {
yield $this->method_call_async_read('users.getUsers', ['id' => [['access_hash' => 0, 'user_id' => $id, '_' => 'inputUser']]], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\Exception $e) {
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
} catch (\danog\MadelineProto\RPCErrorException $e) {
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
}
}
return $this->gen_all($chat, $folder_id);
}