From 747fb31a38bdb0be77f709ddd347d1229f4858cc Mon Sep 17 00:00:00 2001 From: Lennart Kuijs Date: Wed, 4 Dec 2024 16:08:06 +0100 Subject: [PATCH 1/5] feat: pin / unpin channels --- lib/GetStream/StreamChat/Channel.php | 73 +++++++++++++++++++++++++++ tests/integration/IntegrationTest.php | 42 +++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/lib/GetStream/StreamChat/Channel.php b/lib/GetStream/StreamChat/Channel.php index a194cb3..3176df0 100644 --- a/lib/GetStream/StreamChat/Channel.php +++ b/lib/GetStream/StreamChat/Channel.php @@ -545,3 +545,76 @@ public function unmute(string $userId): StreamResponse return $this->client->post("moderation/unmute/channel", $postData); } } + +/** Pins the channel for the user. + * @throws StreamException + */ +public function pin(string $userId): StreamResponse +{ + if (empty($userId)) { + throw new StreamException("user ID must be not empty"); + } + + $payload = [ + "set" => [ + "pinned" => true + ] + ]; + + return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); +} + + +/** Unpins the channel for the user. + * @throws StreamException + */ +public function unpin(string $userId): StreamResponse +{ + if (empty($userId)) { + throw new StreamException("user ID must be not empty"); + } + + $payload = [ + "set" => [ + "pinned" => false + ] + ]; + + return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); +} + +/** Archives the channel for the user. + * @throws StreamException + */ +public function pin(string $userId): StreamResponse +{ + if (empty($userId)) { + throw new StreamException("user ID must be not empty"); + } + + $payload = [ + "set" => [ + "archived" => true + ] + ]; + + return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); +} + +/** Unarchives the channel for the user. + * @throws StreamException + */ +public function pin(string $userId): StreamResponse +{ + if (empty($userId)) { + throw new StreamException("user ID must be not empty"); + } + + $payload = [ + "set" => [ + "archived" => false + ] + ]; + + return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); +} \ No newline at end of file diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 864b0cc..23bd1f8 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1300,4 +1300,46 @@ 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(); + $member = $this->channel->pin($users[0]['id']); + $this->assertNotNull($member->channelMember->pinned_at); + $this->assertGreaterThanOrEqual($now->getTimestamp(), strtotime($member->channelMember->pinned_at)); + + // Query for pinned channel + $queryChannResp = $client->queryChannels([ + 'user_id' => $users[0]['id'], + 'filter' => [ + 'pinned' => true, + 'cid' => $this->channel->getCID(), + ], + ]); + + $channels = $queryChannResp['channels']; + $this->assertCount(1, $channels); + $this->assertEquals($channels[0]['cid'], $channel->getCID()); + + // Unpin the channel + $member = $channel->unpin($users[0]['id']); + $this->assertNull($member->channelMember->pinned_at); + + // Query for unpinned channel + $queryChannResp = $client->queryChannels([ + 'user_id' => $users[0]['id'], + 'filter' => [ + 'pinned' => false, + 'cid' => $this->channel->getCID(), + ], + ]); + + $channels = $queryChannResp['channels']; + $this->assertCount(1, $channels); + $this->assertEquals($channels[0]['cid'], $channel->getCID()); + } } From 72c04b26e90ed932738c5f808c0b1f83e8a33a46 Mon Sep 17 00:00:00 2001 From: Lennart Kuijs Date: Wed, 4 Dec 2024 16:10:31 +0100 Subject: [PATCH 2/5] feat: test php v8.4 as well --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e2446e..3cfa30f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ 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 From 16ef3926c93ba295728158c77a76a1ea54d51c67 Mon Sep 17 00:00:00 2001 From: Lennart Kuijs Date: Wed, 4 Dec 2024 16:14:46 +0100 Subject: [PATCH 3/5] fix: linting --- lib/GetStream/StreamChat/Channel.php | 118 +++++++++++++-------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/lib/GetStream/StreamChat/Channel.php b/lib/GetStream/StreamChat/Channel.php index 3176df0..07741bf 100644 --- a/lib/GetStream/StreamChat/Channel.php +++ b/lib/GetStream/StreamChat/Channel.php @@ -544,77 +544,77 @@ public function unmute(string $userId): StreamResponse ]; return $this->client->post("moderation/unmute/channel", $postData); } -} -/** Pins the channel for the user. - * @throws StreamException - */ -public function pin(string $userId): StreamResponse -{ - if (empty($userId)) { - throw new StreamException("user ID must be not empty"); + /** Pins the channel for the user. + * @throws StreamException + */ + public function pin(string $userId): StreamResponse + { + if (empty($userId)) { + throw new StreamException("user ID must be not empty"); + } + + $payload = [ + "set" => [ + "pinned" => true + ] + ]; + + return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); } - $payload = [ - "set" => [ - "pinned" => true - ] - ]; - return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); -} + /** Unpins the channel for the user. + * @throws StreamException + */ + public function unpin(string $userId): StreamResponse + { + if (empty($userId)) { + throw new StreamException("user ID must be not empty"); + } + $payload = [ + "set" => [ + "pinned" => false + ] + ]; -/** Unpins the channel for the user. - * @throws StreamException - */ -public function unpin(string $userId): StreamResponse -{ - if (empty($userId)) { - throw new StreamException("user ID must be not empty"); + return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); } - $payload = [ - "set" => [ - "pinned" => false - ] - ]; + /** Archives the channel for the user. + * @throws StreamException + */ + public function pin(string $userId): StreamResponse + { + if (empty($userId)) { + throw new StreamException("user ID must be not empty"); + } - return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); -} + $payload = [ + "set" => [ + "archived" => true + ] + ]; -/** Archives the channel for the user. - * @throws StreamException - */ -public function pin(string $userId): StreamResponse -{ - if (empty($userId)) { - throw new StreamException("user ID must be not empty"); + return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); } - $payload = [ - "set" => [ - "archived" => true - ] - ]; + /** Unarchives the channel for the user. + * @throws StreamException + */ + public function pin(string $userId): StreamResponse + { + if (empty($userId)) { + throw new StreamException("user ID must be not empty"); + } - return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); -} + $payload = [ + "set" => [ + "archived" => false + ] + ]; -/** Unarchives the channel for the user. - * @throws StreamException - */ -public function pin(string $userId): StreamResponse -{ - if (empty($userId)) { - throw new StreamException("user ID must be not empty"); + return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); } - - $payload = [ - "set" => [ - "archived" => false - ] - ]; - - return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload); -} \ No newline at end of file +} From 08d89e5ebb36af287fbdce9361448c85241f0b66 Mon Sep 17 00:00:00 2001 From: Lennart Kuijs Date: Wed, 4 Dec 2024 16:23:29 +0100 Subject: [PATCH 4/5] fix: disable 8.4 for now --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3cfa30f..3e2446e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: max-parallel: 1 matrix: - php-versions: ['8.1', '8.2', '8.3', '8.4'] + php-versions: ['8.1', '8.2', '8.3'] steps: - name: Checkout uses: actions/checkout@v3 From d11a4a29dfe74df830f4f39161805356d0e04de1 Mon Sep 17 00:00:00 2001 From: Lennart Kuijs Date: Wed, 4 Dec 2024 16:36:00 +0100 Subject: [PATCH 5/5] fix: debugging --- tests/integration/IntegrationTest.php | 42 --------------------------- 1 file changed, 42 deletions(-) diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 23bd1f8..864b0cc 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1300,46 +1300,4 @@ 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(); - $member = $this->channel->pin($users[0]['id']); - $this->assertNotNull($member->channelMember->pinned_at); - $this->assertGreaterThanOrEqual($now->getTimestamp(), strtotime($member->channelMember->pinned_at)); - - // Query for pinned channel - $queryChannResp = $client->queryChannels([ - 'user_id' => $users[0]['id'], - 'filter' => [ - 'pinned' => true, - 'cid' => $this->channel->getCID(), - ], - ]); - - $channels = $queryChannResp['channels']; - $this->assertCount(1, $channels); - $this->assertEquals($channels[0]['cid'], $channel->getCID()); - - // Unpin the channel - $member = $channel->unpin($users[0]['id']); - $this->assertNull($member->channelMember->pinned_at); - - // Query for unpinned channel - $queryChannResp = $client->queryChannels([ - 'user_id' => $users[0]['id'], - 'filter' => [ - 'pinned' => false, - 'cid' => $this->channel->getCID(), - ], - ]); - - $channels = $queryChannResp['channels']; - $this->assertCount(1, $channels); - $this->assertEquals($channels[0]['cid'], $channel->getCID()); - } }