diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e2446e..fce1b1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,17 +13,13 @@ jobs: strategy: max-parallel: 1 matrix: - php-versions: ['8.1', '8.2', '8.3'] + php-versions: ['8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 # gives the commit message linter access to all previous commits - - name: Commit lint - if: ${{ matrix.php-versions == '8.1' }} - uses: wagoid/commitlint-github-action@v4 - - name: Setup PHP uses: shivammathur/setup-php@v2 with: diff --git a/lib/GetStream/StreamChat/Channel.php b/lib/GetStream/StreamChat/Channel.php index f25a5f2..94da8f0 100644 --- a/lib/GetStream/StreamChat/Channel.php +++ b/lib/GetStream/StreamChat/Channel.php @@ -546,6 +546,7 @@ public function unmute(string $userId): StreamResponse } /** Pins the channel for the user. + * @link https://getstream.io/chat/docs/php/channel_update/#pinning-a-channel?language=php * @throws StreamException */ public function pin(string $userId): StreamResponse @@ -565,6 +566,7 @@ public function pin(string $userId): StreamResponse /** Unpins the channel for the user. + * @link https://getstream.io/chat/docs/php/channel_update/#pinning-a-channel?language=php * @throws StreamException */ public function unpin(string $userId): StreamResponse @@ -583,6 +585,7 @@ public function unpin(string $userId): StreamResponse } /** Archives the channel for the user. + * @link https://getstream.io/chat/docs/php/channel_update/#archiving-a-channel?language=php * @throws StreamException */ public function archive(string $userId): StreamResponse @@ -601,6 +604,7 @@ public function archive(string $userId): StreamResponse } /** Unarchives the channel for the user. + * @link https://getstream.io/chat/docs/php/channel_update/#archiving-a-channel?language=php * @throws StreamException */ public function unarchive(string $userId): StreamResponse @@ -617,4 +621,23 @@ public function unarchive(string $userId): StreamResponse return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); } + + /** Update channel member partially. + * @link https://getstream.io/chat/docs/php/channel_member/#update-channel-members?language=php + * @throws StreamException + */ + public function updateMemberPartial(string $userId, ?array $set = null, ?array $unset = null): StreamResponse + { + if (empty($userId)) { + throw new StreamException("user ID must be not empty"); + } + if ($set === null && $unset === null) { + throw new StreamException("set or unset is required"); + } + $update = [ + "set" => $set, + "unset" => $unset + ]; + return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $update); + } } diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 864b0cc..18cac47 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1300,4 +1300,87 @@ public function testUnreadCountsBatch() $this->assertNotEmpty($resp["counts_by_user"][$this->user1["id"]]["total_unread_threads_count"]); $this->assertEquals(1, $resp["counts_by_user"][$this->user1["id"]]["total_unread_threads_count"]); } + + public function testChannelPin() + { + $this->channel->addMembers([$this->user1["id"]]); + $this->channel->addMembers([$this->user2["id"]]); + + // Pin the channel + $now = new \DateTime(); + $response = $this->channel->pin($this->user1["id"]); + $this->assertNotNull($response["channel_member"]["pinned_at"]); + $this->assertGreaterThanOrEqual($now->getTimestamp(), strtotime($response["channel_member"]["pinned_at"])); + + // Query for pinned channel + $response = $this->client->queryChannels([ + "pinned" => true, + "cid" => $this->channel->getCID(), + ], null, [ + "user_id" => $this->user1["id"] + ]); + $this->assertCount(1, $response["channels"]); + $this->assertEquals($this->channel->getCID(), $response["channels"][0]["channel"]["cid"]); + + // Unpin the channel + $response = $this->channel->unpin($this->user1["id"]); + $this->assertArrayNotHasKey("pinned_at", $response["channel_member"]); + + // Query for unpinned channel + $response = $this->client->queryChannels([ + "pinned" => false, + "cid" => $this->channel->getCID(), + ], null, [ + "user_id" => $this->user1["id"] + ]); + $this->assertCount(1, $response["channels"]); + $this->assertEquals($this->channel->getCID(), $response["channels"][0]["channel"]["cid"]); + } + + public function testChannelArchive() + { + $this->channel->addMembers([$this->user1["id"]]); + $this->channel->addMembers([$this->user2["id"]]); + + // Archive the channel + $now = new \DateTime(); + $response = $this->channel->archive($this->user1["id"]); + $this->assertNotNull($response["channel_member"]["archived_at"]); + $this->assertGreaterThanOrEqual($now->getTimestamp(), strtotime($response["channel_member"]["archived_at"])); + + // Query for archived channel + $response = $this->client->queryChannels([ + "archived" => true, + "cid" => $this->channel->getCID(), + ], null, [ + "user_id" => $this->user1["id"] + ]); + $this->assertCount(1, $response["channels"]); + $this->assertEquals($this->channel->getCID(), $response["channels"][0]["channel"]["cid"]); + + // Unarchive the channel + $response = $this->channel->unarchive($this->user1["id"]); + $this->assertArrayNotHasKey("archived_at", $response["channel_member"]); + + // Query for unarchived channel + $response = $this->client->queryChannels([ + "archived" => false, + "cid" => $this->channel->getCID(), + ], null, [ + "user_id" => $this->user1["id"] + ]); + $this->assertCount(1, $response["channels"]); + $this->assertEquals($this->channel->getCID(), $response["channels"][0]["channel"]["cid"]); + } + + public function testChannelUpdateMemberPartial() + { + $this->channel->addMembers([$this->user1["id"]]); + $response = $this->channel->updateMemberPartial($this->user1["id"], ["hat" => "blue"]); + $this->assertEquals("blue", $response["channel_member"]["hat"]); + + $response = $this->channel->updateMemberPartial($this->user1["id"], ["color" => "red"], ["hat"]); + $this->assertEquals("red", $response["channel_member"]["color"]); + $this->assertArrayNotHasKey("hat", $response["channel_member"]); + } }