authorizeSecret()) { return new DataResponse(['error' => 'forbidden'], Http::STATUS_FORBIDDEN); } $params = $this->request->getParams(); $userId = trim((string)($params['userId'] ?? '')); $title = trim((string)($params['title'] ?? '')); $body = trim((string)($params['body'] ?? '')); if ($userId === '' || $title === '') { return new DataResponse(['error' => 'userId and title required'], Http::STATUS_BAD_REQUEST); } $sent = $this->pushDispatcher->dispatch(new PushMessage( userId: $userId, title: $title, body: $body, source: trim((string)($params['source'] ?? 'api')), priority: trim((string)($params['priority'] ?? 'normal')), url: isset($params['url']) ? trim((string)$params['url']) : null, )); return new DataResponse(['success' => true, 'sent' => $sent]); } /** * Send test push to devices of the current user (admin or self). */ #[NoAdminRequired] #[NoCSRFRequired] public function test(): DataResponse { $user = $this->userSession->getUser(); if ($user === null) { return new DataResponse(['error' => 'unauthorized'], Http::STATUS_UNAUTHORIZED); } $sent = $this->pushDispatcher->dispatch(new PushMessage( userId: $user->getUID(), title: 'F7 Push', body: 'Test notification from F7cloud', source: 'f7push', priority: 'normal', url: $this->config->getDefaultClickUrl(), )); return new DataResponse(['success' => true, 'sent' => $sent]); } private function authorizeSecret(): bool { $header = $this->request->getHeader('X-F7-Push-Secret'); if ($header === '') { $header = (string)$this->request->getParam('secret', ''); } return $this->config->verifyApiSecret($header); } }