<commit_before><?php
/**
 * @copyright Copyright (c) 2016, ownCloud, Inc.
 *
 * @author <NAME> <<EMAIL>>
 *
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * 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, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace OCA\Files\Activity;

use OCP\Activity\IEvent;
use OCP\Activity\IProvider;
use OCP\IL10N;
use OCP\IURLGenerator;

class Provider implements IProvider {

	/** @var IL10N */
	protected $l;

	/** @var IURLGenerator */
	protected $url;

	/**
	 * @param IL10N $l
	 * @param IURLGenerator $url
	 */
	public function __construct(IL10N $l, IURLGenerator $url) {
		$this->l = $l;
		$this->url = $url;
	}

	/**
	 * @param IEvent $event
	 * @param IEvent|null $previousEvent
	 * @return IEvent
	 * @throws \InvalidArgumentException
	 * @since 9.2.0
	 */
	public function parse(IEvent $event, IEvent $previousEvent = null) {
		if ($event->getApp() !== 'files') {
			throw new \InvalidArgumentException();
		}

		$parsedParameters = $this->getParsedParameters($event->getSubject(), $event->getSubjectParameters());
		$richParameters = $this->getRichParameters($event->getSubject(), $event->getSubjectParameters());

		if ($event->getSubject() === 'created_self') {
			$event->setParsedSubject($this->l->t('You created %1$s', $parsedParameters))
				->setRichSubject($this->l->t('You created {file1}'), $richParameters)
				->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg')));
		} else if ($event->getSubject() === 'created_by') {
			$event->setParsedSubject($this->l->t('%2$s created %1$s', $parsedParameters))
				->setRichSubject($this->l->t('{user1} created {file1}'), $richParameters)
				->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg')));
		} else if ($event->getSubject() === 'created_public') {
			$event->setParsedSubject($this->l->t('%1$s was created in a public folder', $parsedParameters))
				->setRichSubject($this->l->t('{file1} was created in a public folder'), $richParameters)
				->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg')));
		} else if ($event->getSubject() === 'changed_self') {
			$event->setParsedSubject($this->l->t('You changed %1$s', $parsedParameters))
				->setRichSubject($this->l->t('You changed {file1}'), $richParameters)
				->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg')));
		} else if ($event->getSubject() === 'changed_by') {
			$event->setParsedSubject($this->l->t('%2$s changed %1$s', $parsedParameters))
				->setRichSubject($this->l->t('{user1} changed {file1}'), $richParameters)
				->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg')));
		} else if ($event->getSubject() === 'deleted_self') {
			$event->setParsedSubject($this->l->t('You deleted %1$s', $parsedParameters))<commit_msg>Don't even try to combine when the subject is different<commit_after><?php
/**
 * @copyright Copyright (c) 2016, ownCloud, Inc.
 *
 * @author <NAME> <<EMAIL>>
 *
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * 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, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace OCA\Files\Activity;

use OCP\Activity\IEvent;
use OCP\Activity\IProvider;
use OCP\IL10N;
use OCP\IURLGenerator;

class Provider implements IProvider {

	/** @var IL10N */
	protected $l;

	/** @var IURLGenerator */
	protected $url;

	/**
	 * @param IL10N $l
	 * @param IURLGenerator $url
	 */
	public function __construct(IL10N $l, IURLGenerator $url) {
		$this->l = $l;
		$this->url = $url;
	}

	/**
	 * @param IEvent $event
	 * @param IEvent|null $previousEvent
	 * @return IEvent
	 * @throws \InvalidArgumentException
	 * @since 9.2.0
	 */
	public function parse(IEvent $event, IEvent $previousEvent = null) {
		if ($event->getApp() !== 'files') {
			throw new \InvalidArgumentException();
		}

		$parsedParameters = $this->getParsedParameters($event->getSubject(), $event->getSubjectParameters());
		$richParameters = $this->getRichParameters($event->getSubject(), $event->getSubjectParameters());

		if ($previousEvent instanceof IEvent && $event->getSubject() !== $previousEvent->getSubject()) {
			// Different subject means not the same string, so no grouping
			$previousEvent = null;
		}

		if ($event->getSubject() === 'created_self') {
			$event->setParsedSubject($this->l->t('You created %1$s', $parsedParameters))
				->setRichSubject($this->l->t('You created {file1}'), $richParameters)
				->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg')));
		} else if ($event->getSubject() === 'created_by') {
			$event->setParsedSubject($this->l->t('%2$s created %1$s', $parsedParameters))
				->setRichSubject($this->l->t('{user1} created {file1}'), $richParameters)
				->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg')));
		} else if ($event->getSubject() === 'created_public') {
			$event->setParsedSubject($this->l->t('%1$s was created in a public folder', $parsedParameters))
				->setRichSubject($this->l->t('{file1} was created in a public folder'), $richParameters)
				->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg')));
		} else if ($event->getSubject() === 'changed_self') {
			$event->setParsedSubject($this->l->t('You changed %1$s', $parsedParameters))
				->setRichSubject($this->l->t('You changed {file1}'), $richParameters)
				->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg')));
		} else if ($event->getSubject() === 'changed_by') {
			$event->setParsedSubject($this->l->t('%2$s changed %1$s', $parsedParameters))
				->setRichSubject($this->l->t('{user1} changed {file1}'), $richParameters)
				->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg')));
		} else if ($event->getSubject() === 'deleted_self') {
			$event->setParsedSubject($this->l->t('You deleted %1$s', $parsedParameters))
{'fraction_non_alphanumeric': 0.18303571428571427, 'fraction_numerical': 0.009792626728110598, 'mean_word_length': 4.744416873449132, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 159, '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': '912836', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2186, 'n_words': 544}