Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft deletes reactions #123

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @JimmyPettersson85 @xernobyl @yaziine
* @JimmyPettersson85 @xernobyl @vagruchi @itsmeadi
17 changes: 15 additions & 2 deletions lib/GetStream/Stream/Reactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/ReactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down