Skip to content

Commit

Permalink
add socket id to batch trigger if present (#370)
Browse files Browse the repository at this point in the history
* add socket id to batch trigger if present

* Fix tests on PHP 10+

* Bump to version 7.2.3

---------

Co-authored-by: fbenevides <me@benevides.pro>
Co-authored-by: Pusher CI <pusher-ci@pusher.com>
  • Loading branch information
3 people committed May 17, 2023
1 parent bcae44e commit 416e68d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 7.2.3

* [Fixed] Include socket_id in batch trigger if included.

## 7.2.2

* [FIXED] composer.phar file removed from package
Expand Down
25 changes: 13 additions & 12 deletions src/Pusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Pusher implements LoggerAwareInterface, PusherInterface
/**
* @var string Version
*/
public static $VERSION = '7.2.2';
public static $VERSION = '7.2.3';

/**
* @var null|PusherCrypto
Expand Down Expand Up @@ -475,8 +475,8 @@ public function triggerAsync($channels, string $event, $data, array $params = []
*/
public function sendToUser(string $user_id, string $event, $data, bool $already_encoded = false): object
{
$this->validate_user_id($user_id);
return $this->trigger(["#server-to-user-$user_id"], $event, $data, [], $already_encoded);
$this->validate_user_id($user_id);
return $this->trigger(["#server-to-user-$user_id"], $event, $data, [], $already_encoded);
}

/**
Expand All @@ -492,8 +492,8 @@ public function sendToUser(string $user_id, string $event, $data, bool $already_
*/
public function sendToUserAsync(string $user_id, string $event, $data, bool $already_encoded = false): PromiseInterface
{
$this->validate_user_id($user_id);
return $this->triggerAsync(["#server-to-user-$user_id"], $event, $data, [], $already_encoded);
$this->validate_user_id($user_id);
return $this->triggerAsync(["#server-to-user-$user_id"], $event, $data, [], $already_encoded);
}


Expand Down Expand Up @@ -914,7 +914,7 @@ public function authorizeChannel(string $channel, string $socket_id, string $cus
return $response;
}

/**
/**
* Convenience function for presence channel authorization.
*
* Equivalent to authorizeChannel($channel, $socket_id, json_encode(['user_id' => $user_id, 'user_info' => $user_info], JSON_THROW_ON_ERROR))
Expand Down Expand Up @@ -1061,7 +1061,7 @@ public function ensure_valid_signature(array $headers, string $body): void
*/
private function make_event(array $channels, string $event, $data, array $params = [], ?string $info = null, bool $already_encoded = false): array
{
$has_encrypted_channel = false;
$has_encrypted_channel = false;
foreach ($channels as $chan) {
if (PusherCrypto::is_encrypted_channel($chan)) {
$has_encrypted_channel = true;
Expand Down Expand Up @@ -1102,12 +1102,12 @@ private function make_event(array $channels, string $event, $data, array $params
$post_params['data'] = $data_encoded;
$channel_values = array_values($channels);
if (count($channel_values) == 1) {
$post_params['channel'] = $channel_values[0];
$post_params['channel'] = $channel_values[0];
} else {
$post_params['channels'] = $channel_values;
$post_params['channels'] = $channel_values;
}
if (!is_null($info)) {
$post_params['info'] = $info;
$post_params['info'] = $info;
}

return array_merge($post_params, $params);
Expand Down Expand Up @@ -1166,9 +1166,10 @@ private function make_trigger_batch_body(array $batch = [], bool $already_encode
$this->validate_channel($event['channel']);
if (isset($event['socket_id'])) {
$this->validate_socket_id($event['socket_id']);
$batch[$key] = $this->make_event([$event['channel']], $event['name'], $event['data'], ['socket_id' => $event['socket_id']], $event['info'] ?? null, $already_encoded);
} else {
$batch[$key] = $this->make_event([$event['channel']], $event['name'], $event['data'], [], $event['info'] ?? null, $already_encoded);
}

$batch[$key] = $this->make_event([$event['channel']], $event['name'], $event['data'], [], $event['info'] ?? null, $already_encoded);
}

try {
Expand Down
9 changes: 3 additions & 6 deletions tests/acceptance/ChannelQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ protected function setUp(): void
public function testChannelInfo(): void
{
$result = $this->pusher->get_channel_info('channel-test');

self::assertObjectHasAttribute('occupied', $result, 'class has occupied attribute');
self::assertNotNull($result->occupied, 'class has occupied attribute');
}

public function testChannelList(): void
Expand Down Expand Up @@ -68,8 +67,7 @@ public function testFilterByPrefixOneChannel(): void
public function testUsersInfo(): void
{
$result = $this->pusher->get_users_info('presence-channel-test');

$this->assertObjectHasAttribute('users', $result, 'class has users attribute');
self::assertNotNull($result->users, 'class has users attribute');
}

public function testProvidingInfoParameterWithPrefixQueryFailsForPublicChannel(): void
Expand Down Expand Up @@ -115,7 +113,6 @@ public function testChannelListUsingGenericGetAndPrefixParam(): void
public function testSingleChannelInfoUsingGenericGet(): void
{
$result = $this->pusher->get('/channels/channel-test');

self::assertObjectHasAttribute('occupied', $result, 'class has occupied attribute');
self::assertNotNull($result->occupied, 'class has occupied attribute');
}
}

0 comments on commit 416e68d

Please sign in to comment.