userSession->getUser(); if ($user === null) { return new DataResponse(['error' => 'unauthorized'], Http::STATUS_UNAUTHORIZED); } $params = $this->request->getParams(); $deviceId = trim((string)($params['deviceId'] ?? '')); $fcmToken = trim((string)($params['fcmToken'] ?? '')); if ($deviceId === '' || $fcmToken === '') { return new DataResponse(['error' => 'deviceId and fcmToken required'], Http::STATUS_BAD_REQUEST); } $platform = trim((string)($params['platform'] ?? 'android')); $clientApp = trim((string)($params['clientApp'] ?? 'f7cloud-apk')); $device = $this->pushDispatcher->registerDevice( $user->getUID(), $deviceId, $fcmToken, $platform !== '' ? $platform : 'android', $clientApp !== '' ? $clientApp : 'f7cloud-apk', ); return new DataResponse([ 'success' => true, 'deviceId' => $device->getDeviceId(), ]); } #[NoAdminRequired] #[NoCSRFRequired] public function unregister(string $deviceId): DataResponse { $user = $this->userSession->getUser(); if ($user === null) { return new DataResponse(['error' => 'unauthorized'], Http::STATUS_UNAUTHORIZED); } $this->pushDispatcher->unregisterDevice($user->getUID(), $deviceId); return new DataResponse(['success' => true]); } #[NoAdminRequired] #[NoCSRFRequired] public function listDevices(): DataResponse { $user = $this->userSession->getUser(); if ($user === null) { return new DataResponse(['error' => 'unauthorized'], Http::STATUS_UNAUTHORIZED); } $devices = $this->pushDispatcher->listDevices($user->getUID()); $list = array_map(static function ($device) { return [ 'deviceId' => $device->getDeviceId(), 'platform' => $device->getPlatform(), 'clientApp' => $device->getClientApp(), 'lastSeen' => $device->getLastSeen(), ]; }, $devices); return new DataResponse(['devices' => $list]); } }