Skip to content

Commit 4917191

Browse files
feat: commit message endpoint (#110)
* feat: commit message endpoint * fix: failing test * Revert "fix: failing test" This reverts commit d10e9f0. * fix: disable failing test
1 parent 445f962 commit 4917191

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

lib/GetStream/StreamChat/Client.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,15 @@ public function updateMessage(array $message): StreamResponse
782782
return $this->post("messages/" . $messageId, $options);
783783
}
784784

785+
/**
786+
* commits a pending message, making it visible in the channel and for other users
787+
* @link https://getstream.io/chat/docs/javascript/pending_messages/?language=php
788+
*/
789+
public function commitMessage(string $id)
790+
{
791+
return $this->post("messages/" . $id . "/commit", []);
792+
}
793+
785794
/** Deletes a message.
786795
* @link https://getstream.io/chat/docs/php/send_message/?language=php
787796
* @throws StreamException

tests/integration/IntegrationTest.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,23 @@ public function testHttpClientSet()
9595
$this->assertTrue(array_key_exists("app", (array)$response));
9696
}
9797

98-
public function testStreamResponse()
99-
{
100-
$response = $this->client->getAppSettings();
101-
$rateLimits = $response->getRateLimits();
102-
103-
$this->assertEquals(200, $response->getStatusCode());
104-
$this->assertGreaterThan(0, $rateLimits->getLimit());
105-
$this->assertGreaterThan(0, $rateLimits->getRemaining());
106-
$this->assertNotNull($rateLimits->getReset());
107-
108-
$serialized = json_encode($response);
109-
$this->assertFalse(str_contains($serialized, "rate"));
110-
$this->assertTrue(str_starts_with($serialized, '{"app"'));
111-
}
98+
// Disabling following test sincewe don't add rate limits from backend anymore
99+
// for non-limited api calls
100+
//
101+
// public function testStreamResponse()
102+
// {
103+
// $response = $this->client->getAppSettings();
104+
// $rateLimits = $response->getRateLimits();
105+
106+
// $this->assertEquals(200, $response->getStatusCode());
107+
// $this->assertGreaterThan(0, $rateLimits->getLimit());
108+
// $this->assertGreaterThan(0, $rateLimits->getRemaining());
109+
// $this->assertNotNull($rateLimits->getReset());
110+
111+
// $serialized = json_encode($response);
112+
// $this->assertFalse(str_contains($serialized, "rate"));
113+
// $this->assertTrue(str_starts_with($serialized, '{"app"'));
114+
// }
112115

113116
public function testAuth()
114117
{
@@ -524,6 +527,22 @@ public function testUpdateMessage()
524527
$this->client->updateMessage($msg);
525528
}
526529

530+
public function testPendingMessage()
531+
{
532+
$msgId = $this->generateGuid();
533+
$msg = ["id" => $msgId, "text" => "hello world"];
534+
$response1 = $this->channel->sendMessage($msg, $this->user1["id"], null, ["pending" => true]);
535+
$this->assertSame($msgId, $response1["message"]["id"]);
536+
537+
$response = $this->client->queryChannels(["id" => $this->channel->id], null, ['user_id' => $this->user1["id"]]);
538+
// check if length of $response["channels"][0]['pending_messages']) is 1
539+
$this->assertSame(1, sizeof($response["channels"][0]['pending_messages']));
540+
541+
542+
$response2 = $this->client->commitMessage($msgId);
543+
$this->assertSame($msgId, $response2["message"]["id"]);
544+
}
545+
527546
public function testDeleteMessage()
528547
{
529548
$msgId = $this->generateGuid();

0 commit comments

Comments
 (0)