Skip to content

Commit

Permalink
Fix onReady detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadyita committed Sep 14, 2024
1 parent 63630ad commit 86f29f5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Client/SingleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Amp\DeferredFuture;
use AO\Internal\SendQueue;
use AO\Package\Out\Pong;
use AO\{
AccountUnfreezer,
Connection,
Expand Down Expand Up @@ -390,6 +391,8 @@ protected function handleIncomingPackage(Package\InPackage $package): void {
$this->handleBuddyRemoved($package);
} elseif ($package instanceof In\GroupJoined) {
$this->handleGroupJoined($package);
} elseif ($package instanceof In\Ping) {
$this->handlePing($package);
} elseif ($package instanceof In\GroupLeft) {
$this->handleGroupLeft($package);
}
Expand Down Expand Up @@ -433,8 +436,8 @@ protected function handleBuddyRemoved(In\BuddyRemoved $package): void {
}

protected function handleGroupJoined(In\GroupJoined $package): void {
if (!$this->isReady) {
EventLoop::defer($this->triggerOnReady(...));
if (!$this->isReady && $this->lastPong < 1) {
$this->write(new Pong('ready'));
}
$group = new Group(
id: $package->groupId,
Expand All @@ -447,6 +450,12 @@ protected function handleGroupJoined(In\GroupJoined $package): void {
$this->publicGroups[$package->groupName] = $group;
}

protected function handlePing(In\Ping $package): void {
if (!$this->isReady && $package->extra === 'ready') {
EventLoop::defer($this->triggerOnReady(...));
}
}

protected function handleGroupLeft(In\GroupLeft $package): void {
foreach ($this->publicGroups as $name => $group) {
if ($package->groupId->sameAs($group->id)) {
Expand Down

0 comments on commit 86f29f5

Please sign in to comment.