Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<summary>Receive a notification when an event in a shared calendar was added, modified or deleted.</summary>
<description><![CDATA[Receive a notification when an event in a shared calendar was added, modified or deleted.]]></description>

<version>0.3.4</version>
<version>1.0.0</version>
<licence>agpl</licence>
<author>Joas Schilling</author>

Expand All @@ -27,6 +27,6 @@
<screenshot>https://github.com/nickv-nextcloud/event_update_notification/raw/master/docs/demo.png</screenshot>

<dependencies>
<nextcloud min-version="14" max-version="16" />
<nextcloud min-version="17" max-version="17" />
</dependencies>
</info>
10 changes: 1 addition & 9 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ public function registerEventListener() {
}

protected function registerNotifier() {
$this->getContainer()->getServer()->getNotificationManager()->registerNotifier(function() {
return $this->getContainer()->query(Notifier::class);
}, function() {
$l = $this->getContainer()->getServer()->getL10NFactory()->get('event_update_notification');
return [
'id' => 'event_update_notification',
'name' => $l->t('Calendar event update notifications'),
];
});
$this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class);
}
}
4 changes: 2 additions & 2 deletions lib/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function onTouchCalendarObject(string $action, array $calendarData, array
}

$classification = $objectData['classification'] ?? CalDavBackend::CLASSIFICATION_PUBLIC;
$action = $action . '_' . $object['type'];
$action .= '_' . $object['type'];
list ($dateTime, $hasTime) = $this->getNearestDateTime($objectData['calendardata']);
$now = new \DateTime();

Expand All @@ -94,7 +94,7 @@ public function onTouchCalendarObject(string $action, array $calendarData, array

$notification = $this->notificationManager->createNotification();
$notification->setApp('event_update_notification')
->setObject('calendar', (int) $calendarData['id'])
->setObject('calendar', (string) $calendarData['id'])
->setUser($currentUser)
->setDateTime($now)
->setMessage('event_update_notification', [
Expand Down
29 changes: 24 additions & 5 deletions lib/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
Expand Down Expand Up @@ -74,14 +75,34 @@ public function __construct(IFactory $languageFactory,
$this->dateTimeFormatter = $dateTimeFormatter;
}

/**
* Identifier of the notifier, only use [a-z0-9_]
*
* @return string
* @since 17.0.0
*/
public function getID(): string {
return 'event_update_notification';
}

/**
* Human readable name describing the notifier
*
* @return string
* @since 17.0.0
*/
public function getName(): string {
return $this->languageFactory->get('event_update_notification')->t('Calendar event update notifications');
}

/**
* @param INotification $notification
* @param string $languageCode The code of the language that should be used to prepare the notification
* @return INotification
* @throws \InvalidArgumentException When the notification was not prepared by a notifier
* @since 9.0.0
*/
public function prepare(INotification $notification, $languageCode): INotification {
public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== 'event_update_notification') {
throw new \InvalidArgumentException('Invalid app');
}
Expand All @@ -97,16 +118,14 @@ public function prepare(INotification $notification, $languageCode): INotificati
} else if ($notification->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_event') {
$subject = $this->l->t('{actor} updated {event} in {calendar}');
} else {
$this->notificationManager->markProcessed($notification);
throw new \InvalidArgumentException('Invalid subject');
throw new AlreadyProcessedException();
}

$params = $notification->getMessageParameters();
$start = \DateTime::createFromFormat(\DateTime::ATOM, $params['start']);

if ($start < $this->timeFactory->getDateTime()) {
$this->notificationManager->markProcessed($notification);
throw new \InvalidArgumentException('Past event');
throw new AlreadyProcessedException();
}

if (!empty($params['hasTime'])) {
Expand Down