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

feat: commit message endpoint #110

Merged
merged 4 commits into from
Jun 30, 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
9 changes: 9 additions & 0 deletions lib/GetStream/StreamChat/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,15 @@ public function updateMessage(array $message): StreamResponse
return $this->post("messages/" . $messageId, $options);
}

/**
* commits a pending message, making it visible in the channel and for other users
* @link https://getstream.io/chat/docs/javascript/pending_messages/?language=php
*/
public function commitMessage(string $id)
{
return $this->post("messages/" . $id . "/commit", []);
}

/** Deletes a message.
* @link https://getstream.io/chat/docs/php/send_message/?language=php
* @throws StreamException
Expand Down
47 changes: 33 additions & 14 deletions tests/integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,23 @@ public function testHttpClientSet()
$this->assertTrue(array_key_exists("app", (array)$response));
}

public function testStreamResponse()
{
$response = $this->client->getAppSettings();
$rateLimits = $response->getRateLimits();

$this->assertEquals(200, $response->getStatusCode());
$this->assertGreaterThan(0, $rateLimits->getLimit());
$this->assertGreaterThan(0, $rateLimits->getRemaining());
$this->assertNotNull($rateLimits->getReset());

$serialized = json_encode($response);
$this->assertFalse(str_contains($serialized, "rate"));
$this->assertTrue(str_starts_with($serialized, '{"app"'));
}
// Disabling following test sincewe don't add rate limits from backend anymore
// for non-limited api calls
//
// public function testStreamResponse()
// {
// $response = $this->client->getAppSettings();
// $rateLimits = $response->getRateLimits();

// $this->assertEquals(200, $response->getStatusCode());
// $this->assertGreaterThan(0, $rateLimits->getLimit());
// $this->assertGreaterThan(0, $rateLimits->getRemaining());
// $this->assertNotNull($rateLimits->getReset());

// $serialized = json_encode($response);
// $this->assertFalse(str_contains($serialized, "rate"));
// $this->assertTrue(str_starts_with($serialized, '{"app"'));
// }

public function testAuth()
{
Expand Down Expand Up @@ -524,6 +527,22 @@ public function testUpdateMessage()
$this->client->updateMessage($msg);
}

public function testPendingMessage()
{
$msgId = $this->generateGuid();
$msg = ["id" => $msgId, "text" => "hello world"];
$response1 = $this->channel->sendMessage($msg, $this->user1["id"], null, ["pending" => true]);
$this->assertSame($msgId, $response1["message"]["id"]);

$response = $this->client->queryChannels(["id" => $this->channel->id], null, ['user_id' => $this->user1["id"]]);
// check if length of $response["channels"][0]['pending_messages']) is 1
$this->assertSame(1, sizeof($response["channels"][0]['pending_messages']));


$response2 = $this->client->commitMessage($msgId);
$this->assertSame($msgId, $response2["message"]["id"]);
}

public function testDeleteMessage()
{
$msgId = $this->generateGuid();
Expand Down