Skip to content

Commit 59c2458

Browse files
author
Rafael Marinho
committed
refactor
1 parent 9bad5a0 commit 59c2458

File tree

5 files changed

+33
-232
lines changed

5 files changed

+33
-232
lines changed

examples/mark_delivered_example.php

Lines changed: 0 additions & 61 deletions
This file was deleted.

lib/GetStream/StreamChat/Channel.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -354,38 +354,6 @@ public function markRead(string $userId, ?array $data = null): StreamResponse
354354
return $this->client->post($this->getUrl() . "/read", $payload);
355355
}
356356

357-
/** Send the mark delivered event for this user, only works if
358-
* the `delivery_receipts` setting is enabled.
359-
*
360-
* @param string $userId The user ID sending the delivery receipt
361-
* @param array|null $data Optional data for the mark delivered request. Expected structure:
362-
* [
363-
* 'channel_delivered_message' => [
364-
* 'channel_id' => 'message_id'
365-
* ],
366-
* 'client_id' => 'optional_client_id',
367-
* 'connection_id' => 'optional_connection_id',
368-
* 'user' => [/* user data */],
369-
* 'user_id' => 'optional_user_id'
370-
* ]
371-
* @return StreamResponse
372-
* @throws StreamException
373-
* @link https://getstream.io/chat/docs/php/send_message/?language=php
374-
*/
375-
public function markDelivered(string $userId, ?array $data = null): StreamResponse
376-
{
377-
if ($data === null) {
378-
$data = [];
379-
}
380-
381-
// Note: In PHP, we don't have access to the current user's privacy settings
382-
// through the client like in JavaScript. The delivery receipts check should
383-
// be handled on the client side before calling this method.
384-
385-
$payload = Channel::addUser($data, $userId);
386-
return $this->client->post("channels/delivered", $payload);
387-
}
388-
389357
/** List the message replies for a parent message.
390358
* @link https://getstream.io/chat/docs/php/threads/?language=php
391359
* @throws StreamException

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", $lastDeliveredMessages, $params);
1765+
}
17511766
}

tests/integration/IntegrationTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,4 +1828,22 @@ public function testSharedLocations()
18281828
$this->assertEquals(-118.2437, $newUserLocations["active_live_locations"][0]["longitude"]);
18291829
$this->assertEquals('test-device-123', $newUserLocations["active_live_locations"][0]["created_by_device_id"]);
18301830
}
1831+
1832+
public function testMarkDelivered()
1833+
{
1834+
// Send a message first
1835+
$message = $this->channel->sendMessage(["text" => "Test message for delivery receipt"], $this->user1["id"]);
1836+
1837+
// Mark the message as delivered
1838+
$latestDeliveredMessages = [
1839+
[
1840+
'cid' => $this->channel->getCID(),
1841+
'id' => $message["message"]["id"]
1842+
]
1843+
];
1844+
1845+
$response = $this->client->markDelivered($this->user1["id"], $latestDeliveredMessages);
1846+
1847+
$this->assertInstanceOf(\GetStream\StreamChat\StreamResponse::class, $response);
1848+
}
18311849
}

tests/unit/MarkDeliveredTest.php

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)