-
Notifications
You must be signed in to change notification settings - Fork 3
Users
Creating a User - Batch Creating Users - Get User - Get Users - Get Users by IDs - Updating a User - Deleting a User - Get User Rooms - Join a Room - Leave a Room
This method requires a sudo token.
@param array $user
@return \Chess\Chatkit\Models\User
Chatkit::users()->store($user);
id
(string|required): User id assigned to the user in your app.
name
(string|required): Name of the new user.
avatar_url
(string|optional): A link to the user's photo/image.
custom_data
(array|optional): Custom data that may be associated with a user.
Example
$user = Chatkit::users()->store([
'id' => $userId,
'name' => 'John Doe',
'avatar_url' => 'https://placekitten.com/200/300',
'custom_data' => [
'my_custom_key' => 'some data'
]
]);
This method requires a sudo token.
@param array $users
@return \Illuminate\Support\Collection
Chatkit::users()->storeMultiple($users);
See Creating a User for $users
required values
Example
$users = Chatkit::users()->storeMultiple([
[
'id' => $rockyId,
'name' => 'Rocky Balboa',
'avatar_url' => 'https://placekitten.com/200/300',
'custom_data' => [
'my_custom_key' => 'some data'
]
],
[
'id' => $harryId,
'name' => 'Harry Potter',
'avatar_url' => 'https://placekitten.com/200/300',
'custom_data' => [
'my_custom_key' => 'some data'
]
],
[
'id' => $arthurId,
'name' => 'Arthur Dent',
'avatar_url' => 'https://placekitten.com/200/300',
'custom_data' => [
'my_custom_key' => 'some data'
]
]
]);
@param string $userId
@return \Chess\Chatkit\Models\User
Example
$user = Chatkit::users()->show($userId);
@param string $fromTs
@return \Illuminate\Support\Collection
The number of users returned is 20.
$fromTs
(string|optional): Timestamp (inclusive) from which users with a more recent created_at
should be returned. The timestamp should use the ISO 8601 notation; specifically the B8601DZw.d format
. An example of a timestamp in this format is 2018-04-17T14:02:00Z
.
Examples
$users = Chatkit::users()->index();
OR with $fromTs
$users = Chatkit::users()->index('2018-04-17T14:02:00Z');
@param array $usersIds
@return \Illuminate\Support\Collection
Examples
$users = Chatkit::users()->showMultiple([$userIdOne, $userIdTwo, $userIdThree]);
@param string $userId
@param array $userData
@return bool
Chatkit::users()->update($userId, $userData);
name
(string|optional): Updated name for the user.
avatar_url
(string|optional): Updated user image link.
custom_data
(array|optional): Updated custom data.
Example
// User ID in request must match User ID in access token
Chatkit::withUser($userId);
$updated = Chatkit::users()->update($userId, [
'name' => 'Jake',
'avatar_url' => 'https://imgur.com/img/6987',
'custom_data' => ['email' => 'jake@example.com']
]);
The user must also have the right set of permission to perform this action. See Roles & Permissions for details.
If you want to use only your own policies, you can always use :
Chatkit::withSudoUser($userId);
to bypass Chatkit restrictions.
This method requires a sudo token.
@param string $userId
@return bool
Example
$deleted = Chatkit::users()->destroy($userId);
@param string $userId
@return \Illuminate\Support\Collection
joinable
(boolean): Indicates if only rooms that the user can join should be returned.
Examples
$user = new \Chess\Chatkit\Models\User($userId);
$rooms = $user->rooms()->get();
Or with Joinable
$user = new \Chess\Chatkit\Models\User($userId);
$rooms = $user->rooms()->joinable()->get();
@param string $userId
@param int $roomId
@return \Chess\Chatkit\Models\Room
Example
// User ID in request must match User ID in access token
Chatkit::withUser($userId);
$user = new \Chess\Chatkit\Models\User($userId);
$room = $user->room($roomId)->join();
@param string $userId
@param int $roomId
@return bool
Example
// User ID in request must match User ID in access token
Chatkit::withUser($userId);
$user = new \Chess\Chatkit\Models\User($userId);
$leaved = $user->room($roomId)->leave();