Skip to content

Commit 55d22b2

Browse files
rafaelmf3Rafael Marinho
andauthored
[CHA-650]: feat(CHA-769): support shared locations (#141)
* feat(CHA-769): support shared locations * fix(CHA-769): lint * tests(cha-650): add unit tests * tests(cha-650) fix unit test * fix tests * fix tests * fix test * refactor * fix tests * lint * fix test * fix test --------- Co-authored-by: Rafael Marinho <[email protected]>
1 parent 3458898 commit 55d22b2

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

lib/GetStream/StreamChat/Client.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,4 +1728,24 @@ public function queryReminders(string $userId, array $filterConditions = [], ?ar
17281728
]);
17291729
return $this->post('reminders/query', $params);
17301730
}
1731+
1732+
/**
1733+
* Get a user active live locations
1734+
* @throws StreamException
1735+
*/
1736+
public function getUserActiveLiveLocations(string $userId): StreamResponse
1737+
{
1738+
$params = ["user_id" => $userId];
1739+
return $this->get("users/live_locations", $params);
1740+
}
1741+
1742+
/**
1743+
* Update a user active live location
1744+
* @throws StreamException
1745+
*/
1746+
public function updateUserActiveLiveLocation(string $userId, array $location): StreamResponse
1747+
{
1748+
$params = ["user_id" => $userId];
1749+
return $this->put("users/live_locations", $location, $params);
1750+
}
17311751
}

tests/integration/IntegrationTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,4 +1774,58 @@ public function testQueryDrafts()
17741774
// ignore
17751775
}
17761776
}
1777+
1778+
public function testSharedLocations()
1779+
{
1780+
// Enable shared locations for the channel
1781+
$this->channel->updatePartial([
1782+
"config_overrides" => ["shared_locations" => true],
1783+
]);
1784+
1785+
$endAt = new \DateTime('+1 hour');
1786+
// Create a shared location message
1787+
$sharedLocation = [
1788+
'latitude' => 40.7128,
1789+
'longitude' => -74.0060,
1790+
'created_by_device_id' => 'test-device-123',
1791+
'end_at' => $endAt->format('Y-m-d\TH:i:s.u\Z')
1792+
];
1793+
1794+
$message = [
1795+
'shared_location' => $sharedLocation
1796+
];
1797+
1798+
$response = $this->channel->sendMessage($message, $this->user1['id']);
1799+
1800+
$this->assertTrue(array_key_exists("message", (array)$response));
1801+
$this->assertTrue(array_key_exists("shared_location", $response["message"]));
1802+
$this->assertEquals(40.7128, $response["message"]["shared_location"]["latitude"]);
1803+
$this->assertEquals(-74.0060, $response["message"]["shared_location"]["longitude"]);
1804+
$this->assertEquals('test-device-123', $response["message"]["shared_location"]["created_by_device_id"]);
1805+
$this->assertTrue(array_key_exists("end_at", $response["message"]["shared_location"]));
1806+
1807+
$userLocations = $this->client->getUserActiveLiveLocations($this->user1['id']);
1808+
1809+
$this->assertTrue(array_key_exists("active_live_locations", (array)$userLocations));
1810+
$this->assertIsArray($userLocations["active_live_locations"]);
1811+
$this->assertEquals($response["message"]["id"], $userLocations["active_live_locations"][0]["message_id"]);
1812+
1813+
$newLocation = [
1814+
'message_id' => $response["message"]["id"],
1815+
'latitude' => 34.0522,
1816+
'longitude' => -118.2437,
1817+
'created_by_device_id' => 'test-device-123',
1818+
'end_at' => (new \DateTime('+2 hours'))->format('Y-m-d\TH:i:s.u\Z')
1819+
];
1820+
1821+
$this->client->updateUserActiveLiveLocation($this->user1['id'], $newLocation);
1822+
1823+
$newUserLocations = $this->client->getUserActiveLiveLocations($this->user1['id']);
1824+
1825+
$this->assertTrue(array_key_exists("active_live_locations", (array)$newUserLocations));
1826+
$this->assertIsArray($newUserLocations["active_live_locations"]);
1827+
$this->assertEquals(34.0522, $newUserLocations["active_live_locations"][0]["latitude"]);
1828+
$this->assertEquals(-118.2437, $newUserLocations["active_live_locations"][0]["longitude"]);
1829+
$this->assertEquals('test-device-123', $newUserLocations["active_live_locations"][0]["created_by_device_id"]);
1830+
}
17771831
}

0 commit comments

Comments
 (0)