Skip to content

fix: honor explicit state/watch/presence options in queryChannels - #181

Open
pcbeingused333 wants to merge 1 commit into
GetStream:mainfrom
pcbeingused333:fix/query-channels-options-keys
Open

pcbeingused333 wants to merge 1 commit into
GetStream:mainfrom
pcbeingused333:fix/query-channels-options-keys

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes Client::queryChannels ignoring an explicit state => false and dropping the state/watch/presence defaults depending on the other options passed.

Cause

The defaults were filled in with in_array("state", $options), which searches the option values, not the keys, with PHP's loose comparison (a non-empty string such as "watch" equals true). As a result:

  • ["state" => false] did not count as "state set", so it was overwritten with true and the full channel state was returned, although docs/channels/query_channels.md recommends state=false to reduce the response.
  • ["watch" => true] or ["presence" => true] made the state check succeed by accident, so state was never sent.
  • With no options, state was set to true and that value then satisfied the watch/presence checks, so those defaults were never sent either.

Fix

Use array_key_exists() for the three checks, so only missing options get defaults.

Test

New tests/unit/QueryChannelsOptionsTest.php injects a mock Guzzle handler (no API or credentials) and asserts the request body: defaults when no options, state=false respected, watch/presence=true respected. All 3 tests fail without the change (state=false overwritten, missing watch/state keys) and pass with it; the full unit suite passes (51 tests).

Disclosure: this change was prepared with the assistance of an AI coding tool (Claude Code); the tests above were run.

The defaults were applied with in_array(), which searches option values, not keys. An explicit state=false was overwritten with true, and watch/presence=true were reset to false.
@pcbeingused333

Copy link
Copy Markdown
Author

Friendly ping: could someone take a look at this when there's time? I'm happy to adjust anything. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant