2016-11-29 18:21:36 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
|
|
|
*
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
*
|
2016-11-29 18:21:36 +03:00
|
|
|
* @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
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-11-29 18:21:36 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\CalDAV\Activity\Provider;
|
|
|
|
|
|
|
|
use OCP\Activity\IEvent;
|
|
|
|
|
|
|
|
class Todo extends Event {
|
|
|
|
|
|
|
|
/**
|
2016-12-01 13:35:23 +03:00
|
|
|
* @param string $language
|
2016-11-29 18:21:36 +03:00
|
|
|
* @param IEvent $event
|
|
|
|
* @param IEvent|null $previousEvent
|
|
|
|
* @return IEvent
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @since 11.0.0
|
|
|
|
*/
|
2016-12-01 13:35:23 +03:00
|
|
|
public function parse($language, IEvent $event, IEvent $previousEvent = null) {
|
2016-11-29 18:21:36 +03:00
|
|
|
if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar_todo') {
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
|
2016-12-01 13:35:23 +03:00
|
|
|
$this->l = $this->languageFactory->get('dav', $language);
|
|
|
|
|
2017-06-20 14:48:51 +03:00
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.svg')));
|
|
|
|
}
|
2016-11-29 18:21:36 +03:00
|
|
|
|
|
|
|
if ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_todo') {
|
|
|
|
$subject = $this->l->t('{actor} created todo {todo} in list {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_ADD . '_todo_self') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = $this->l->t('You created todo {todo} in list {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_todo') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = $this->l->t('{actor} deleted todo {todo} from list {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_DELETE . '_todo_self') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = $this->l->t('You deleted todo {todo} from list {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = $this->l->t('{actor} updated todo {todo} in list {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_self') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = $this->l->t('You updated todo {todo} in list {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_completed') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = $this->l->t('{actor} solved todo {todo} in list {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = $this->l->t('You solved todo {todo} in list {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = $this->l->t('{actor} reopened todo {todo} in list {calendar}');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = $this->l->t('You reopened todo {todo} in list {calendar}');
|
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$parsedParameters = $this->getParameters($event);
|
|
|
|
$this->setSubjects($event, $subject, $parsedParameters);
|
|
|
|
|
|
|
|
$event = $this->eventMerger->mergeEvents('todo', $event, $previousEvent);
|
|
|
|
|
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IEvent $event
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getParameters(IEvent $event) {
|
|
|
|
$subject = $event->getSubject();
|
|
|
|
$parameters = $event->getSubjectParameters();
|
|
|
|
|
2017-10-16 19:31:43 +03:00
|
|
|
// Nextcloud 13+
|
|
|
|
if (isset($parameters['calendar'])) {
|
|
|
|
switch ($subject) {
|
|
|
|
case self::SUBJECT_OBJECT_ADD . '_todo':
|
|
|
|
case self::SUBJECT_OBJECT_DELETE . '_todo':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo_completed':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action':
|
|
|
|
return [
|
|
|
|
'actor' => $this->generateUserParameter($parameters['actor']),
|
|
|
|
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
|
|
|
|
'todo' => $this->generateObjectParameter($parameters['object']),
|
|
|
|
];
|
|
|
|
case self::SUBJECT_OBJECT_ADD . '_todo_self':
|
|
|
|
case self::SUBJECT_OBJECT_DELETE . '_todo_self':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo_self':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self':
|
|
|
|
return [
|
|
|
|
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
|
|
|
|
'todo' => $this->generateObjectParameter($parameters['object']),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 13:35:55 +03:00
|
|
|
// Legacy - Do NOT Remove unless necessary
|
|
|
|
// Removing this will break parsing of activities that were created on
|
|
|
|
// Nextcloud 12, so we should keep this as long as it's acceptable.
|
|
|
|
// Otherwise if people upgrade over multiple releases in a short period,
|
|
|
|
// they will get the dead entries in their stream.
|
2016-11-29 18:21:36 +03:00
|
|
|
switch ($subject) {
|
|
|
|
case self::SUBJECT_OBJECT_ADD . '_todo':
|
|
|
|
case self::SUBJECT_OBJECT_DELETE . '_todo':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo_completed':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action':
|
|
|
|
return [
|
|
|
|
'actor' => $this->generateUserParameter($parameters[0]),
|
2021-01-11 14:57:03 +03:00
|
|
|
'calendar' => $this->generateLegacyCalendarParameter($event->getObjectId(), $parameters[1]),
|
2016-11-29 18:21:36 +03:00
|
|
|
'todo' => $this->generateObjectParameter($parameters[2]),
|
|
|
|
];
|
|
|
|
case self::SUBJECT_OBJECT_ADD . '_todo_self':
|
|
|
|
case self::SUBJECT_OBJECT_DELETE . '_todo_self':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo_self':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self':
|
|
|
|
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self':
|
|
|
|
return [
|
2021-01-11 14:57:03 +03:00
|
|
|
'calendar' => $this->generateLegacyCalendarParameter($event->getObjectId(), $parameters[1]),
|
2016-11-29 18:21:36 +03:00
|
|
|
'todo' => $this->generateObjectParameter($parameters[2]),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
}
|