diff options
| author | Daniel Weipert <git@mail.dweipert.de> | 2026-04-16 15:39:21 +0200 |
|---|---|---|
| committer | Daniel Weipert <git@mail.dweipert.de> | 2026-04-16 15:39:21 +0200 |
| commit | 21593231a0e7de30004a8b4530047b4ad4680db7 (patch) | |
| tree | 7a86fd3e99bd37631c48474bcdfb267d0763b4af /src/Controllers/Client/KeyController.php | |
| parent | f3202403339e94f0186b9ff19e83c7a32fdad198 (diff) | |
Diffstat (limited to 'src/Controllers/Client/KeyController.php')
| -rw-r--r-- | src/Controllers/Client/KeyController.php | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/Controllers/Client/KeyController.php b/src/Controllers/Client/KeyController.php index 5e3245b..47f8933 100644 --- a/src/Controllers/Client/KeyController.php +++ b/src/Controllers/Client/KeyController.php @@ -2,7 +2,9 @@ namespace App\Controllers\Client; +use App\App; use App\Database; +use App\Models\Device; use App\Models\User; use App\Support\RequestValidator; use Matrix\Responses\ClientKeysUploadPostResponse; @@ -93,10 +95,38 @@ class KeyController $deviceKeys = $body["device_keys"]; $timeout = $body["timeout"] ?? 10000; - foreach ($deviceKeys as $keysUserId => $deviceIds) {} + $downloadedDeviceKeys = []; + foreach ($deviceKeys as $keysUserId => $deviceIds) { + foreach ($deviceIds as $deviceId) { + $result = Database::getInstance() + ->query("select * from device_keys where user_id=:user_id and device_id=:device_id", [ + "user_id" => $keysUserId, + "device_id" => $deviceId, + ]) + ->fetch(); + $device = Device::fetch($deviceId, $keysUserId); + + $downloadedDeviceKeys[$keysUserId][$deviceId] = [ + "algorithms" => $result["supported_algorithms"], + "keys" => $result["keys"], + "signatures" => $result["signatures"], + "device_id" => $result["device_id"], + "user_id" => $result["user_id"], + "unsigned" => [ + "device_display_name" => $device->getName(), + ], + ]; + } + } + + // apply timeout + if ($timeout > 0) { + sleep(intval(($timeout / 1000) - App::getExectionTime())); + } + return new JsonResponse([ - "device_keys" => [], + "device_keys" => empty($downloadedDeviceKeys) ? new \stdClass() : $downloadedDeviceKeys, ]); } |
