<commit_before><?php
declare(strict_types=1);
/**
 * @copyright Copyright (c) 2018 <NAME> <<EMAIL>>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

namespace OCA\Spreed\Collaboration\Resources;

use OCA\Spreed\Exceptions\RoomNotFoundException;
use OCA\Spreed\Manager;
use OCA\Spreed\Room;
use OCP\Collaboration\Resources\IProvider;
use OCP\Collaboration\Resources\IResource;
use OCP\Collaboration\Resources\ResourceException;
use OCP\IURLGenerator;
use OCP\IUser;

class ConversationProvider implements IProvider {

	/** @var Manager */
	protected $manager;
	/** @var IURLGenerator */
	protected $urlGenerator;

	public function __construct(Manager $manager, IURLGenerator $urlGenerator) {
		$this->manager = $manager;
		$this->urlGenerator = $urlGenerator;
	}

	public function getResourceRichObject(IResource $resource): array {
		try {
			$room = $this->manager->getRoomByToken($resource->getId());

			return [
				'type' => 'room',
				'id' => $resource->getId(),
				'name' => $room->getDisplayName(''),
				'call-type' => $this->getRoomType($room),
				'iconUrl' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('spreed', 'app-dark.svg')),
			];
		} catch (RoomNotFoundException $e) {
			throw new ResourceException('Conversation not found');
		}
	}

	public function canAccessResource(IResource $resource, IUser $user = null): bool {
		try {
			$room = $this->manager->getRoomForParticipantByToken(
				$resource->getId(),
				$user instanceof IUser ? $user->getUID() : null
			);
			return $user instanceof IUser || $room->getType() === Room::PUBLIC_CALL;
		} catch (RoomNotFoundException $e) {
			throw new ResourceException('Conversation not found');
		}
	}

	public function getType(): string {
		return 'room';
	}<commit_msg>Add a link for rooms<commit_after><?php
declare(strict_types=1);
/**
 * @copyright Copyright (c) 2018 <NAME> <<EMAIL>>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

namespace OCA\Spreed\Collaboration\Resources;

use OCA\Spreed\Exceptions\RoomNotFoundException;
use OCA\Spreed\Manager;
use OCA\Spreed\Room;
use OCP\Collaboration\Resources\IProvider;
use OCP\Collaboration\Resources\IResource;
use OCP\Collaboration\Resources\ResourceException;
use OCP\IURLGenerator;
use OCP\IUser;

class ConversationProvider implements IProvider {

	/** @var Manager */
	protected $manager;
	/** @var IURLGenerator */
	protected $urlGenerator;

	public function __construct(Manager $manager, IURLGenerator $urlGenerator) {
		$this->manager = $manager;
		$this->urlGenerator = $urlGenerator;
	}

	public function getResourceRichObject(IResource $resource): array {
		try {
			$room = $this->manager->getRoomByToken($resource->getId());

			return [
				'type' => 'room',
				'id' => $resource->getId(),
				'name' => $room->getDisplayName(''),
				'call-type' => $this->getRoomType($room),
				'iconUrl' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('spreed', 'app-dark.svg')),
				'link' => $this->urlGenerator->linkToRouteAbsolute('spreed.pagecontroller.showCall', ['token' => $room->getToken()])
			];
		} catch (RoomNotFoundException $e) {
			throw new ResourceException('Conversation not found');
		}
	}

	public function canAccessResource(IResource $resource, IUser $user = null): bool {
		try {
			$room = $this->manager->getRoomForParticipantByToken(
				$resource->getId(),
				$user instanceof IUser ? $user->getUID() : null
			);
			return $user instanceof IUser || $room->getType() === Room::PUBLIC_CALL;
		} catch (RoomNotFoundException $e) {
			throw new ResourceException('Conversation not found');
		}
	}

	public function getType(): string {
		return 'room';
	}
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.0027910685805422647, 'mean_word_length': 4.453260869565217, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '130952', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1474, 'n_words': 456}