GetStream / stream-chat-php

Stream Chat official PHP API Client
https://getstream.io/chat/
BSD 3-Clause "New" or "Revised" License
30 stars 9 forks source link

feat: add `restoreUsers` to `Client.php` #122

Closed muzucode closed 2 months ago

muzucode commented 3 months ago

Updates:


The restoreUsers functionality can be tested with the following code after the commits are implemented:

<?php

use GetStream\StreamChat\Client;

require_once "./vendor/autoload.php";

$client = new Client($_ENV['STREAM_KEY'], $_ENV['STREAM_SECRET']);

# Create users
$user_1 = [
    'id' => 'u-70', # Have to keep updating this between testing this out-- you cannot upsert a previously deleted user ID
    'role' => 'admin',
    'name' => 'Bob',
];

# Add users to Stream
$client->upsertUsers([$user_1]);

# Users Query Object
$queryUsersInput = [
    'id' => ['$in' => [$user_1['id']] ],
];

# SOFT-delete user
$delete_users_response = $client->deleteUsers([$user_1['id']], [
    'user' => 'soft',
    'messages' => 'soft'
]);

sleep(3); # Let the delete task complete before fetching it
$task = $client->getTask($delete_users_response['task_id']);

# Restore user once deleteTask is complete
if($task["status"] == "completed") {
    echo 'Now will try to restore a soft-deleted user...';

    $client->restoreUsers([$user_1['id']]);
    $users = $client->queryUsers($queryUsersInput)['users'];

    echo 'Queried Users: ' . PHP_EOL;
    var_dump($users);
}

# HARD-delete user
$delete_users_response = $client->deleteUsers([$user_1['id']], [
    'user' => 'hard',
    'messages' => 'hard'
]);

sleep(3); # Let the delete task complete before fetching it
$task = $client->getTask($delete_users_response['task_id']);

# Try to restore user once deleteTask is complete
if($task["status"] == "completed") {
    echo 'Now will try to restore a hard-deleted user...';
    $client->restoreUsers([$user_1['id']]);
    # 404 Errors out
}