Skip to content

Commit 5787268

Browse files
rafaelmf3Rafael Marinhoadityaalifn
authored
[CHA-1226]: support delivery receipts (#145)
* [CHA-1226]: support delivery receipts * refactor * refactor * fix typo * fix typo * fix * fix webhook v2 tests * Fix query threads tests (#146) --------- Co-authored-by: Rafael Marinho <[email protected]> Co-authored-by: Aditya Alif Nugraha <[email protected]>
1 parent e65ed3b commit 5787268

File tree

2 files changed

+105
-12
lines changed

2 files changed

+105
-12
lines changed

lib/GetStream/StreamChat/Client.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,4 +1748,19 @@ public function updateUserActiveLiveLocation(string $userId, array $location): S
17481748
$params = ["user_id" => $userId];
17491749
return $this->put("users/live_locations", $location, $params);
17501750
}
1751+
1752+
/**
1753+
* Mark messages as delivered
1754+
* @param string $userId The user ID
1755+
* @param array $latestDeliveredMessages Array of DeliveredMessageConfirmation objects
1756+
* @throws StreamException
1757+
*/
1758+
public function markDelivered(string $userId, array $latestDeliveredMessages): StreamResponse
1759+
{
1760+
$data = [
1761+
'latest_delivered_messages' => $latestDeliveredMessages
1762+
];
1763+
$params = ["user_id" => $userId];
1764+
return $this->post("channels/delivered", $data, $params);
1765+
}
17511766
}

tests/integration/IntegrationTest.php

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,22 @@ public function testUpdateAppSettings()
157157
{
158158
$response = $this->client->getAppSettings();
159159
$settings = $response['app'];
160+
161+
unset($settings['webhook_url']);
162+
unset($settings['webhook_events']);
163+
unset($settings['sqs_url']);
164+
unset($settings['sqs_key']);
165+
unset($settings['sqs_secret']);
166+
unset($settings['sns_topic_arn']);
167+
unset($settings['sns_key']);
168+
unset($settings['sns_secret']);
169+
unset($settings['async_moderation_config']);
170+
171+
// Add new event_hooks format if needed
172+
if (!isset($settings['event_hooks'])) {
173+
$settings['event_hooks'] = [];
174+
}
175+
160176
$response = $this->client->updateAppSettings($settings);
161177
$this->assertTrue(array_key_exists("duration", (array)$response));
162178
}
@@ -1534,9 +1550,17 @@ public function testExportUsers()
15341550

15351551
public function testQueryThreadsWithFilter()
15361552
{
1553+
// Create a fresh channel with both users as members
1554+
$testChannel = $this->client->Channel(
1555+
"messaging",
1556+
$this->generateGuid(),
1557+
["test" => true, "language" => "php"]
1558+
);
1559+
$testChannel->create($this->user1["id"], [$this->user1["id"], $this->user2["id"]]);
1560+
15371561
// Create a thread by sending a message with a parent_id
1538-
$parentMessage = $this->channel->sendMessage(["text" => "Parent message"], $this->user1["id"]);
1539-
$threadMessage = $this->channel->sendMessage(
1562+
$parentMessage = $testChannel->sendMessage(["text" => "Parent message"], $this->user1["id"]);
1563+
$threadMessage = $testChannel->sendMessage(
15401564
["text" => "Thread message", "parent_id" => $parentMessage["message"]["id"]],
15411565
$this->user2["id"]
15421566
);
@@ -1551,19 +1575,30 @@ public function testQueryThreadsWithFilter()
15511575
// Verify the response
15521576
$this->assertTrue(array_key_exists("threads", (array)$response));
15531577
$this->assertGreaterThanOrEqual(1, count($response["threads"]));
1578+
1579+
// Cleanup
1580+
$testChannel->delete();
15541581
}
15551582

15561583
public function testQueryThreadsWithSort()
15571584
{
1585+
// Create a fresh channel with both users as members
1586+
$testChannel = $this->client->Channel(
1587+
"messaging",
1588+
$this->generateGuid(),
1589+
["test" => true, "language" => "php"]
1590+
);
1591+
$testChannel->create($this->user1["id"], [$this->user1["id"], $this->user2["id"]]);
1592+
15581593
// Create multiple threads
1559-
$parentMessage1 = $this->channel->sendMessage(["text" => "Parent message 1"], $this->user1["id"]);
1560-
$threadMessage1 = $this->channel->sendMessage(
1594+
$parentMessage1 = $testChannel->sendMessage(["text" => "Parent message 1"], $this->user1["id"]);
1595+
$threadMessage1 = $testChannel->sendMessage(
15611596
["text" => "Thread message 1", "parent_id" => $parentMessage1["message"]["id"]],
15621597
$this->user2["id"]
15631598
);
15641599

1565-
$parentMessage2 = $this->channel->sendMessage(["text" => "Parent message 2"], $this->user1["id"]);
1566-
$threadMessage2 = $this->channel->sendMessage(
1600+
$parentMessage2 = $testChannel->sendMessage(["text" => "Parent message 2"], $this->user1["id"]);
1601+
$threadMessage2 = $testChannel->sendMessage(
15671602
["text" => "Thread message 2", "parent_id" => $parentMessage2["message"]["id"]],
15681603
$this->user2["id"]
15691604
);
@@ -1578,19 +1613,30 @@ public function testQueryThreadsWithSort()
15781613
// Verify the response
15791614
$this->assertTrue(array_key_exists("threads", (array)$response));
15801615
$this->assertGreaterThanOrEqual(2, count($response["threads"]));
1616+
1617+
// Cleanup
1618+
$testChannel->delete();
15811619
}
15821620

15831621
public function testQueryThreadsWithFilterAndSort()
15841622
{
1623+
// Create a fresh channel with both users as members
1624+
$testChannel = $this->client->Channel(
1625+
"messaging",
1626+
$this->generateGuid(),
1627+
["test" => true, "language" => "php"]
1628+
);
1629+
$testChannel->create($this->user1["id"], [$this->user1["id"], $this->user2["id"]]);
1630+
15851631
// Create multiple threads
1586-
$parentMessage1 = $this->channel->sendMessage(["text" => "Parent message 1"], $this->user1["id"]);
1587-
$threadMessage1 = $this->channel->sendMessage(
1632+
$parentMessage1 = $testChannel->sendMessage(["text" => "Parent message 1"], $this->user1["id"]);
1633+
$threadMessage1 = $testChannel->sendMessage(
15881634
["text" => "Thread message 1", "parent_id" => $parentMessage1["message"]["id"]],
15891635
$this->user2["id"]
15901636
);
15911637

1592-
$parentMessage2 = $this->channel->sendMessage(["text" => "Parent message 2"], $this->user1["id"]);
1593-
$threadMessage2 = $this->channel->sendMessage(
1638+
$parentMessage2 = $testChannel->sendMessage(["text" => "Parent message 2"], $this->user1["id"]);
1639+
$threadMessage2 = $testChannel->sendMessage(
15941640
["text" => "Thread message 2", "parent_id" => $parentMessage2["message"]["id"]],
15951641
$this->user2["id"]
15961642
);
@@ -1605,13 +1651,24 @@ public function testQueryThreadsWithFilterAndSort()
16051651
// Verify the response
16061652
$this->assertTrue(array_key_exists("threads", (array)$response));
16071653
$this->assertGreaterThanOrEqual(2, count($response["threads"]));
1654+
1655+
// Cleanup
1656+
$testChannel->delete();
16081657
}
16091658

16101659
public function testQueryThreadsWithoutFilterAndSort()
16111660
{
1661+
// Create a fresh channel with both users as members
1662+
$testChannel = $this->client->Channel(
1663+
"messaging",
1664+
$this->generateGuid(),
1665+
["test" => true, "language" => "php"]
1666+
);
1667+
$testChannel->create($this->user1["id"], [$this->user1["id"], $this->user2["id"]]);
1668+
16121669
// Create a thread by sending a message with a parent_id
1613-
$parentMessage = $this->channel->sendMessage(["text" => "Parent message for no filter test"], $this->user1["id"]);
1614-
$threadMessage = $this->channel->sendMessage(
1670+
$parentMessage = $testChannel->sendMessage(["text" => "Parent message for no filter test"], $this->user1["id"]);
1671+
$threadMessage = $testChannel->sendMessage(
16151672
["text" => "Thread message for no filter test", "parent_id" => $parentMessage["message"]["id"]],
16161673
$this->user2["id"]
16171674
);
@@ -1626,6 +1683,9 @@ public function testQueryThreadsWithoutFilterAndSort()
16261683
// Verify the response
16271684
$this->assertTrue(array_key_exists("threads", (array)$response));
16281685
$this->assertGreaterThanOrEqual(1, count($response["threads"]));
1686+
1687+
// Cleanup
1688+
$testChannel->delete();
16291689
}
16301690

16311691
public function testCreateDraft()
@@ -1828,4 +1888,22 @@ public function testSharedLocations()
18281888
$this->assertEquals(-118.2437, $newUserLocations["active_live_locations"][0]["longitude"]);
18291889
$this->assertEquals('test-device-123', $newUserLocations["active_live_locations"][0]["created_by_device_id"]);
18301890
}
1891+
1892+
public function testMarkDelivered()
1893+
{
1894+
// Send a message first
1895+
$message = $this->channel->sendMessage(["text" => "Test message for delivery receipt"], $this->user1["id"]);
1896+
1897+
// Mark the message as delivered
1898+
$latestDeliveredMessages = [
1899+
[
1900+
'cid' => $this->channel->getCID(),
1901+
'id' => $message["message"]["id"]
1902+
]
1903+
];
1904+
1905+
$response = $this->client->markDelivered($this->user1["id"], $latestDeliveredMessages);
1906+
1907+
$this->assertInstanceOf(\GetStream\StreamChat\StreamResponse::class, $response);
1908+
}
18311909
}

0 commit comments

Comments
 (0)