diff --git a/src/MTProto.php b/src/MTProto.php index 7838ec6fd..e66fbf8dd 100644 --- a/src/MTProto.php +++ b/src/MTProto.php @@ -928,10 +928,6 @@ final class MTProto implements TLCallback, LoggerGetter */ private function upgradeMadelineProto(): void { - if (isset($this->hook_url) && \is_string($this->hook_url)) { - $this->webhookUrl = $this->hook_url; - } - $this->logger->logger(Lang::$current_lang['serialization_ofd'], Logger::WARNING); foreach ($this->datacenter->getDataCenterConnections() as $dc_id => $socket) { if ($this->authorized === API::LOGGED_IN && \is_int($dc_id) && $socket->hasPermAuthKey() && $socket->hasTempAuthKey()) { @@ -956,21 +952,6 @@ final class MTProto implements TLCallback, LoggerGetter } catch (RPCErrorException $e) { } } - - async(function (): void { - $counter = 0; - foreach ($this->chats as $id => $chat) { - $id = (int) $id; - $counter ++; - if ($counter % 1000 === 0) { - $this->logger->logger("Upgrading chats: $counter", Logger::WARNING); - } - - if (!($chat['min'] ?? false)) { - $this->minDatabase->clearPeer($id); - } - } - }); } /** * Post-deserialization initialization function. diff --git a/src/MTProtoTools/MinDatabase.php b/src/MTProtoTools/MinDatabase.php index 62520f7b4..a369f01a2 100644 --- a/src/MTProtoTools/MinDatabase.php +++ b/src/MTProtoTools/MinDatabase.php @@ -61,6 +61,11 @@ final class MinDatabase implements TLCallback * */ private bool $clean = false; + /** + * Whether we synced ourselves with the peer database. + * + */ + private bool $synced = false; /** * List of properties stored in database (memory or external). @@ -77,7 +82,7 @@ final class MinDatabase implements TLCallback } public function __sleep() { - return ['db', 'API', 'clean']; + return ['db', 'API', 'clean', 'synced']; } public function init(): void { @@ -85,17 +90,33 @@ final class MinDatabase implements TLCallback if (!$this->API->getSettings()->getDb()->getEnableMinDb()) { $this->db->clear(); } - if ($this->clean) { - return; - } - EventLoop::queue(function (): void { - foreach ($this->db as $id => $origin) { - if (!isset($origin['peer']) || $origin['peer'] === $id) { - unset($this->db[$id]); + if (!$this->clean) { + EventLoop::queue(function (): void { + foreach ($this->db as $id => $origin) { + if (!isset($origin['peer']) || $origin['peer'] === $id) { + unset($this->db[$id]); + } } - } - $this->clean = true; - }); + $this->clean = true; + }); + } + if (!$this->synced) { + EventLoop::queue(function (): void { + $counter = 0; + foreach ($this->API->chats as $id => $chat) { + $id = (int) $id; + $counter++; + if ($counter % 1000 === 0) { + $this->API->logger->logger("Upgrading chats: $counter", Logger::WARNING); + } + + if (!($chat['min'] ?? false)) { + $this->clearPeer($id); + } + } + $this->synced = true; + }); + } } public function getMethodAfterResponseDeserializationCallbacks(): array {