From 36136d42bb220f6205880d0c693b3697b9f96522 Mon Sep 17 00:00:00 2001 From: Jimmy Pettersson Date: Tue, 31 Oct 2023 13:43:36 +0100 Subject: [PATCH 1/4] add support for soft deleting reactions --- lib/GetStream/Stream/Reactions.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/GetStream/Stream/Reactions.php b/lib/GetStream/Stream/Reactions.php index abde8a8..9350500 100644 --- a/lib/GetStream/Stream/Reactions.php +++ b/lib/GetStream/Stream/Reactions.php @@ -139,12 +139,25 @@ public function createReference($reactionId) /** * @param string $reactionId + * @param bool $soft // soft delete the reaction so it can be restored afterwards * * @return array */ - public function delete($reactionId) + public function delete($reactionId, bool $soft=false) { - $response = $this->doRequest('DELETE', 'reaction/' . $reactionId . '/'); + $response = $this->doRequest('DELETE', 'reaction/' . $reactionId . '/?soft=' . ($soft ? 'true' : 'false')); + $body = $response->getBody()->getContents(); + return json_decode($body, true); + } + + /** + * @param string $reactionId + * + * @return array + */ + public function restore($reactionId) + { + $response = $this->doRequest('PUT', 'reaction/' . $reactionId . '/restore/'); $body = $response->getBody()->getContents(); return json_decode($body, true); } From ee2ec5ae9f6c086f65d31d771f576d9b18e59c4d Mon Sep 17 00:00:00 2001 From: Jimmy Pettersson Date: Tue, 31 Oct 2023 13:43:52 +0100 Subject: [PATCH 2/4] add tests --- tests/integration/ReactionTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/integration/ReactionTest.php b/tests/integration/ReactionTest.php index a604cab..a830eff 100644 --- a/tests/integration/ReactionTest.php +++ b/tests/integration/ReactionTest.php @@ -144,6 +144,25 @@ public function testDeleteReaction() $retrieved_reaction = $this->reactions->get($created_reaction['id']); } + public function testSoftDeleteAndRestoreReaction() + { + $created_reaction = $this->reactions->add('like', $this->activity_id, 'bob'); + $retrieved_reaction = $this->reactions->get($created_reaction['id']); + $this->assertFalse(array_key_exists('deleted_at', $retrieved_reaction)); + $this->reactions->delete($created_reaction['id'], true); + $retrieved_reaction = $this->reactions->get($created_reaction['id']); + $this->assertTrue(array_key_exists('deleted_at', $retrieved_reaction)); + $this->reactions->restore($created_reaction['id']); + $retrieved_reaction = $this->reactions->get($created_reaction['id']); + $this->assertFalse(array_key_exists('deleted_at', $retrieved_reaction)); + } + + public function testRestoreNonexistantReaction() + { + $this->expectException(\GetStream\Stream\StreamFeedException::class); + $this->reactions->restore('non-existant-reaction-id'); + } + public function testUpdateReaction() { $data = ['client' => 'php']; From f37eb7b18bee344bdc444866f5619561a4b10f73 Mon Sep 17 00:00:00 2001 From: Jimmy Pettersson Date: Tue, 31 Oct 2023 13:44:10 +0100 Subject: [PATCH 3/4] update CODEOWNERS --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 10fd19e..5e8b594 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @JimmyPettersson85 @xernobyl @yaziine +* @JimmyPettersson85 @xernobyl From 932995987d395a7e70311796ab89acb913cb03d8 Mon Sep 17 00:00:00 2001 From: Jimmy Pettersson Date: Tue, 31 Oct 2023 14:22:29 +0100 Subject: [PATCH 4/4] update CODEOWNERS --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 5e8b594..c10b908 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @JimmyPettersson85 @xernobyl +* @JimmyPettersson85 @xernobyl @vagruchi @itsmeadi