|
|
|
@ -30,126 +30,128 @@ use OCP\Notification\IManager as INotificationManager; |
|
|
|
|
|
|
|
|
|
class Notifier implements INotifier { |
|
|
|
|
|
|
|
|
|
/** @var IFactory */ |
|
|
|
|
protected $factory; |
|
|
|
|
/** @var IFactory */ |
|
|
|
|
protected $factory; |
|
|
|
|
|
|
|
|
|
/** @var INotificationManager */ |
|
|
|
|
protected $notificationManager; |
|
|
|
|
/** @var INotificationManager */ |
|
|
|
|
protected $notificationManager; |
|
|
|
|
|
|
|
|
|
/** @var IURLGenerator */ |
|
|
|
|
protected $url; |
|
|
|
|
/** @var IURLGenerator */ |
|
|
|
|
protected $url; |
|
|
|
|
|
|
|
|
|
public function __construct(IFactory $factory, INotificationManager $notificationManager, IURLGenerator $urlGenerator) { |
|
|
|
|
$this->factory = $factory; |
|
|
|
|
$this->notificationManager = $notificationManager; |
|
|
|
|
$this->url = $urlGenerator; |
|
|
|
|
} |
|
|
|
|
public function __construct(IFactory $factory, INotificationManager $notificationManager, |
|
|
|
|
IURLGenerator $urlGenerator) { |
|
|
|
|
$this->factory = $factory; |
|
|
|
|
$this->notificationManager = $notificationManager; |
|
|
|
|
$this->url = $urlGenerator; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Identifier of the notifier, only use [a-z0-9_] |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
* @since 17.0.0 |
|
|
|
|
*/ |
|
|
|
|
public function getID(): string { |
|
|
|
|
return Application::APP_ID; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Identifier of the notifier, only use [a-z0-9_] |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
* @since 17.0.0 |
|
|
|
|
*/ |
|
|
|
|
public function getID(): string { |
|
|
|
|
return Application::APP_ID; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Human readable name describing the notifier |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
* @since 17.0.0 |
|
|
|
|
*/ |
|
|
|
|
public function getName(): string { |
|
|
|
|
return $this->factory->get($this->getID())->t('First run migrate'); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Human readable name describing the notifier |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
* @since 17.0.0 |
|
|
|
|
*/ |
|
|
|
|
public function getName(): string { |
|
|
|
|
return $this->factory->get($this->getID())->t('First run migrate'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @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, string $languageCode): INotification { |
|
|
|
|
if ($notification->getApp() !== $this->getID()) { |
|
|
|
|
// Not my app => throw |
|
|
|
|
throw new \InvalidArgumentException(); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* @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, string $languageCode): INotification { |
|
|
|
|
if ($notification->getApp() !== $this->getID()) { |
|
|
|
|
// Not my app => throw |
|
|
|
|
throw new \InvalidArgumentException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$l = $this->factory->get($this->getID(), $languageCode); |
|
|
|
|
$notify_subject = $notification->getSubject(); |
|
|
|
|
$user = $notification->getUser(); |
|
|
|
|
$notify_subject = $notification->getSubject(); |
|
|
|
|
$user = $notification->getUser(); |
|
|
|
|
|
|
|
|
|
$subject = null; |
|
|
|
|
$message = null; |
|
|
|
|
switch ($notify_subject) { |
|
|
|
|
case 'data_scheduled': |
|
|
|
|
$subject = $l->t('Data migration scheduled'); |
|
|
|
|
$message = $l->t('Your data will be soon available'); |
|
|
|
|
break; |
|
|
|
|
case 'data_started': |
|
|
|
|
$subject = $l->t('Data migration started'); |
|
|
|
|
$message = $l->t('Your data will be soon available'); |
|
|
|
|
break; |
|
|
|
|
case 'data_finished': |
|
|
|
|
$message = null; |
|
|
|
|
switch ($notify_subject) { |
|
|
|
|
case 'data_scheduled': |
|
|
|
|
$subject = $l->t('Data migration scheduled'); |
|
|
|
|
$message = $l->t('Your data will be soon available'); |
|
|
|
|
break; |
|
|
|
|
case 'data_started': |
|
|
|
|
$subject = $l->t('Data migration started'); |
|
|
|
|
$message = $l->t('Your data will be soon available'); |
|
|
|
|
break; |
|
|
|
|
case 'data_finished': |
|
|
|
|
$subject = $l->t('Data migration complete'); |
|
|
|
|
$message = $l->t('Your data are available !'); |
|
|
|
|
break; |
|
|
|
|
case 'group_scheduled': |
|
|
|
|
$subject = $l->t('Groups migration scheduled'); |
|
|
|
|
$message = $l->t('Your group folders will be soon available'); |
|
|
|
|
break; |
|
|
|
|
case 'group_started': |
|
|
|
|
$subject = $l->t('Groups migration started'); |
|
|
|
|
$message = $l->t('Your group folders will be soon available'); |
|
|
|
|
break; |
|
|
|
|
case 'group_finished': |
|
|
|
|
$subject = $l->t('Groups migration complete'); |
|
|
|
|
$message = $l->t('Your group folders are available !'); |
|
|
|
|
break; |
|
|
|
|
case 'quota_scheduled': |
|
|
|
|
$subject = $l->t('Quota migration scheduled'); |
|
|
|
|
break; |
|
|
|
|
case 'quota_started': |
|
|
|
|
$subject = $l->t('Quota migration started'); |
|
|
|
|
break; |
|
|
|
|
case 'quota_finished': |
|
|
|
|
$subject = $l->t('Quota migration complete'); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
// Unknown subject => Unknown notification => throw |
|
|
|
|
throw new \InvalidArgumentException(); |
|
|
|
|
} |
|
|
|
|
$message = $l->t('Your data are available !'); |
|
|
|
|
break; |
|
|
|
|
case 'group_scheduled': |
|
|
|
|
$subject = $l->t('Groups migration scheduled'); |
|
|
|
|
$message = $l->t('Your group folders will be soon available'); |
|
|
|
|
break; |
|
|
|
|
case 'group_started': |
|
|
|
|
$subject = $l->t('Groups migration started'); |
|
|
|
|
$message = $l->t('Your group folders will be soon available'); |
|
|
|
|
break; |
|
|
|
|
case 'group_finished': |
|
|
|
|
$subject = $l->t('Groups migration complete'); |
|
|
|
|
$message = $l->t('Your group folders are available !'); |
|
|
|
|
break; |
|
|
|
|
case 'quota_scheduled': |
|
|
|
|
$subject = $l->t('Quota migration scheduled'); |
|
|
|
|
break; |
|
|
|
|
case 'quota_started': |
|
|
|
|
$subject = $l->t('Quota migration started'); |
|
|
|
|
break; |
|
|
|
|
case 'quota_finished': |
|
|
|
|
$subject = $l->t('Quota migration complete'); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
// Unknown subject => Unknown notification => throw |
|
|
|
|
throw new \InvalidArgumentException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$icon = null; |
|
|
|
|
$old_notification = $this->notificationManager->createNotification()->setApp(Application::APP_ID)->setUser($user); |
|
|
|
|
switch ($notification->getObjectId()) { |
|
|
|
|
case 'scheduled': |
|
|
|
|
$icon = $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/recent.svg')); |
|
|
|
|
break; |
|
|
|
|
case 'started': |
|
|
|
|
$icon = $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/change.svg')); |
|
|
|
|
$old_notification->setObject($notification->getObjectType(), 'scheduled'); |
|
|
|
|
break; |
|
|
|
|
case 'finished': |
|
|
|
|
$icon = $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.svg')); |
|
|
|
|
$old_notification->setObject($notification->getObjectType(), 'started'); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
$icon = $this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app.svg')); |
|
|
|
|
} |
|
|
|
|
$icon = null; |
|
|
|
|
$old_notification = $this->notificationManager->createNotification() |
|
|
|
|
->setApp(Application::APP_ID)->setUser($user); |
|
|
|
|
switch ($notification->getObjectId()) { |
|
|
|
|
case 'scheduled': |
|
|
|
|
$icon = $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/recent.svg')); |
|
|
|
|
break; |
|
|
|
|
case 'started': |
|
|
|
|
$icon = $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/change.svg')); |
|
|
|
|
$old_notification->setObject($notification->getObjectType(), 'scheduled'); |
|
|
|
|
break; |
|
|
|
|
case 'finished': |
|
|
|
|
$icon = $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/checkmark.svg')); |
|
|
|
|
$old_notification->setObject($notification->getObjectType(), 'started'); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
$icon = $this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app.svg')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($old_notification->getObjectId()) { |
|
|
|
|
$this->notificationManager->markProcessed($old_notification); |
|
|
|
|
} |
|
|
|
|
if ($old_notification->getObjectId()) { |
|
|
|
|
$this->notificationManager->markProcessed($old_notification); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$notification->setParsedSubject($subject); |
|
|
|
|
if (!empty($message)) { |
|
|
|
|
$notification->setParsedMessage($message); |
|
|
|
|
} |
|
|
|
|
$notification->setIcon($icon); |
|
|
|
|
if (!empty($message)) { |
|
|
|
|
$notification->setParsedMessage($message); |
|
|
|
|
} |
|
|
|
|
$notification->setIcon($icon); |
|
|
|
|
return $notification; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|