Skip to content
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
15 changes: 15 additions & 0 deletions lib/GetStream/StreamChat/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1748,4 +1748,19 @@ public function updateUserActiveLiveLocation(string $userId, array $location): S
$params = ["user_id" => $userId];
return $this->put("users/live_locations", $location, $params);
}

/**
* Mark messages as delivered
* @param string $userId The user ID
* @param array $latestDeliveredMessages Array of DeliveredMessageConfirmation objects
* @throws StreamException
*/
public function markDelivered(string $userId, array $latestDeliveredMessages): StreamResponse
{
$data = [
'latest_delivered_messages' => $latestDeliveredMessages
];
$params = ["user_id" => $userId];
return $this->post("channels/delivered", $data, $params);
}
}
102 changes: 90 additions & 12 deletions tests/integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ public function testUpdateAppSettings()
{
$response = $this->client->getAppSettings();
$settings = $response['app'];

unset($settings['webhook_url']);
unset($settings['webhook_events']);
unset($settings['sqs_url']);
unset($settings['sqs_key']);
unset($settings['sqs_secret']);
unset($settings['sns_topic_arn']);
unset($settings['sns_key']);
unset($settings['sns_secret']);
unset($settings['async_moderation_config']);

// Add new event_hooks format if needed
if (!isset($settings['event_hooks'])) {
$settings['event_hooks'] = [];
}

$response = $this->client->updateAppSettings($settings);
$this->assertTrue(array_key_exists("duration", (array)$response));
}
Expand Down Expand Up @@ -1534,9 +1550,17 @@ public function testExportUsers()

public function testQueryThreadsWithFilter()
{
// Create a fresh channel with both users as members
$testChannel = $this->client->Channel(
"messaging",
$this->generateGuid(),
["test" => true, "language" => "php"]
);
$testChannel->create($this->user1["id"], [$this->user1["id"], $this->user2["id"]]);

// Create a thread by sending a message with a parent_id
$parentMessage = $this->channel->sendMessage(["text" => "Parent message"], $this->user1["id"]);
$threadMessage = $this->channel->sendMessage(
$parentMessage = $testChannel->sendMessage(["text" => "Parent message"], $this->user1["id"]);
$threadMessage = $testChannel->sendMessage(
["text" => "Thread message", "parent_id" => $parentMessage["message"]["id"]],
$this->user2["id"]
);
Expand All @@ -1551,19 +1575,30 @@ public function testQueryThreadsWithFilter()
// Verify the response
$this->assertTrue(array_key_exists("threads", (array)$response));
$this->assertGreaterThanOrEqual(1, count($response["threads"]));

// Cleanup
$testChannel->delete();
}

public function testQueryThreadsWithSort()
{
// Create a fresh channel with both users as members
$testChannel = $this->client->Channel(
"messaging",
$this->generateGuid(),
["test" => true, "language" => "php"]
);
$testChannel->create($this->user1["id"], [$this->user1["id"], $this->user2["id"]]);

// Create multiple threads
$parentMessage1 = $this->channel->sendMessage(["text" => "Parent message 1"], $this->user1["id"]);
$threadMessage1 = $this->channel->sendMessage(
$parentMessage1 = $testChannel->sendMessage(["text" => "Parent message 1"], $this->user1["id"]);
$threadMessage1 = $testChannel->sendMessage(
["text" => "Thread message 1", "parent_id" => $parentMessage1["message"]["id"]],
$this->user2["id"]
);

$parentMessage2 = $this->channel->sendMessage(["text" => "Parent message 2"], $this->user1["id"]);
$threadMessage2 = $this->channel->sendMessage(
$parentMessage2 = $testChannel->sendMessage(["text" => "Parent message 2"], $this->user1["id"]);
$threadMessage2 = $testChannel->sendMessage(
["text" => "Thread message 2", "parent_id" => $parentMessage2["message"]["id"]],
$this->user2["id"]
);
Expand All @@ -1578,19 +1613,30 @@ public function testQueryThreadsWithSort()
// Verify the response
$this->assertTrue(array_key_exists("threads", (array)$response));
$this->assertGreaterThanOrEqual(2, count($response["threads"]));

// Cleanup
$testChannel->delete();
}

public function testQueryThreadsWithFilterAndSort()
{
// Create a fresh channel with both users as members
$testChannel = $this->client->Channel(
"messaging",
$this->generateGuid(),
["test" => true, "language" => "php"]
);
$testChannel->create($this->user1["id"], [$this->user1["id"], $this->user2["id"]]);

// Create multiple threads
$parentMessage1 = $this->channel->sendMessage(["text" => "Parent message 1"], $this->user1["id"]);
$threadMessage1 = $this->channel->sendMessage(
$parentMessage1 = $testChannel->sendMessage(["text" => "Parent message 1"], $this->user1["id"]);
$threadMessage1 = $testChannel->sendMessage(
["text" => "Thread message 1", "parent_id" => $parentMessage1["message"]["id"]],
$this->user2["id"]
);

$parentMessage2 = $this->channel->sendMessage(["text" => "Parent message 2"], $this->user1["id"]);
$threadMessage2 = $this->channel->sendMessage(
$parentMessage2 = $testChannel->sendMessage(["text" => "Parent message 2"], $this->user1["id"]);
$threadMessage2 = $testChannel->sendMessage(
["text" => "Thread message 2", "parent_id" => $parentMessage2["message"]["id"]],
$this->user2["id"]
);
Expand All @@ -1605,13 +1651,24 @@ public function testQueryThreadsWithFilterAndSort()
// Verify the response
$this->assertTrue(array_key_exists("threads", (array)$response));
$this->assertGreaterThanOrEqual(2, count($response["threads"]));

// Cleanup
$testChannel->delete();
}

public function testQueryThreadsWithoutFilterAndSort()
{
// Create a fresh channel with both users as members
$testChannel = $this->client->Channel(
"messaging",
$this->generateGuid(),
["test" => true, "language" => "php"]
);
$testChannel->create($this->user1["id"], [$this->user1["id"], $this->user2["id"]]);

// Create a thread by sending a message with a parent_id
$parentMessage = $this->channel->sendMessage(["text" => "Parent message for no filter test"], $this->user1["id"]);
$threadMessage = $this->channel->sendMessage(
$parentMessage = $testChannel->sendMessage(["text" => "Parent message for no filter test"], $this->user1["id"]);
$threadMessage = $testChannel->sendMessage(
["text" => "Thread message for no filter test", "parent_id" => $parentMessage["message"]["id"]],
$this->user2["id"]
);
Expand All @@ -1626,6 +1683,9 @@ public function testQueryThreadsWithoutFilterAndSort()
// Verify the response
$this->assertTrue(array_key_exists("threads", (array)$response));
$this->assertGreaterThanOrEqual(1, count($response["threads"]));

// Cleanup
$testChannel->delete();
}

public function testCreateDraft()
Expand Down Expand Up @@ -1828,4 +1888,22 @@ public function testSharedLocations()
$this->assertEquals(-118.2437, $newUserLocations["active_live_locations"][0]["longitude"]);
$this->assertEquals('test-device-123', $newUserLocations["active_live_locations"][0]["created_by_device_id"]);
}

public function testMarkDelivered()
{
// Send a message first
$message = $this->channel->sendMessage(["text" => "Test message for delivery receipt"], $this->user1["id"]);

// Mark the message as delivered
$latestDeliveredMessages = [
[
'cid' => $this->channel->getCID(),
'id' => $message["message"]["id"]
]
];

$response = $this->client->markDelivered($this->user1["id"], $latestDeliveredMessages);

$this->assertInstanceOf(\GetStream\StreamChat\StreamResponse::class, $response);
}
}