1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 01:34:40 +01:00
This commit is contained in:
Daniil Gentili 2023-08-14 21:49:08 +02:00
parent fb077f380b
commit d3fa21feb6
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 37 additions and 17 deletions

@ -1 +1 @@
Subproject commit 538081f6ccfcc94a80144427a627da96b0d14408
Subproject commit 25f83d460a9269b778435395935d9417530bcdf5

View File

@ -293,6 +293,13 @@ final class PeerDatabase implements TLCallback
public function getIdFromUsername(string $username): ?int
{
foreach ($this->pendingDb as $key => $_) {
if ($key < 0) {
$this->processChat($key);
} else {
$this->processUser($key);
}
}
return $this->usernames[$username];
}
@ -326,6 +333,13 @@ final class PeerDatabase implements TLCallback
} finally {
unset($this->caching_simple_username[$username]);
}
foreach ($this->pendingDb as $key => $_) {
if ($key < 0) {
$this->processChat($key);
} else {
$this->processUser($key);
}
}
return $result;
}
/**
@ -407,17 +421,29 @@ final class PeerDatabase implements TLCallback
}
}
}
public function addChatBlocking(array $chat): void
public function addChatBlocking(int $chat): void
{
$id = $this->API->getIdInternal($chat);
$this->pendingDb[$id] = $chat;
$this->processChat($id);
if (isset($this->pendingDb[$chat])) {
$this->processChat($chat);
} else {
$this->pendingDb[$chat] = [
'_' => 'channel',
'id' => MTProto::fromSupergroup($chat),
];
$this->processChat($chat);
}
}
public function addUserBlocking(array $user): void
public function addUserBlocking(int $user): void
{
$id = $this->API->getIdInternal($user);
$this->pendingDb[$id] = $user;
$this->processUser($id);
if (isset($this->pendingDb[$user])) {
$this->processChat($user);
} else {
$this->pendingDb[$user] = [
'_' => 'user',
'id' => $user,
];
$this->processUser($user);
}
}
/**
* Add chat to database.

View File

@ -430,17 +430,11 @@ trait PeerHandler
try {
$this->logger->logger("Try fetching {$id} with access hash 0");
if ($this->isSupergroup($id)) {
$this->peerDatabase->addChatBlocking([
'_' => 'channel',
'id' => $this->fromSupergroup($id),
]);
$this->peerDatabase->addChatBlocking($id);
} elseif ($id < 0) {
$this->methodCallAsyncRead('messages.getChats', ['id' => [-$id]]);
} else {
$this->peerDatabase->addUserBlocking([
'_' => 'user',
'id' => $id,
]);
$this->peerDatabase->addUserBlocking($id);
}
} catch (Exception $e) {
$this->logger->logger($e->getMessage(), Logger::WARNING);