fetchConversation($conversationToken); return is_array($room) && $this->extractModeratorFlag($room); } public function canCurrentUserAccessConversation(string $conversationToken): bool { return is_array($this->fetchConversation($conversationToken)); } /** @return array|null */ private function fetchConversation(string $conversationToken): ?array { $conversationToken = trim($conversationToken); $cookieHeader = trim((string)$this->request->getHeader('cookie')); if ($conversationToken === '' || $cookieHeader === '') { return null; } $url = $this->urlGenerator->getAbsoluteURL( '/ocs/v2.php/apps/spreed/api/v4/room/' . rawurlencode($conversationToken) . '?format=json' ); try { $response = $this->clientService->newClient()->get($url, [ 'timeout' => 15, 'headers' => [ 'Accept' => 'application/json', 'OCS-APIRequest' => 'true', 'Cookie' => $cookieHeader, ], ]); $decoded = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR); } catch (\Throwable) { return null; } $meta = is_array($decoded) ? ($decoded['ocs']['meta'] ?? null) : null; $data = is_array($decoded) ? ($decoded['ocs']['data'] ?? null) : null; if (!is_array($meta) || !is_array($data)) { return null; } return strtolower(trim((string)($meta['status'] ?? ''))) === 'ok' ? $data : null; } /** @param array $room */ private function extractModeratorFlag(array $room): bool { foreach (['canModerate', 'isModerator', 'isOwner', 'moderator', 'owner'] as $key) { if (array_key_exists($key, $room) && filter_var($room[$key], FILTER_VALIDATE_BOOLEAN)) { return true; } } foreach (['participantType', 'attendeeType', 'actorType'] as $key) { if (array_key_exists($key, $room)) { $type = (int)$room[$key]; if ($type > 0 && $type <= 2) { return true; } } } foreach (['participant', 'self', 'attendee'] as $key) { if (isset($room[$key]) && is_array($room[$key]) && $this->extractModeratorFlag($room[$key])) { return true; } } return false; } }