diff --git a/appinfo/info.xml b/appinfo/info.xml
index c4198a210f..232214f8b6 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -54,6 +54,7 @@ Developed with ❤️ by [LibreCode](https://librecode.coop). Help us transform
OCA\Libresign\Migration\DeleteOldBinaries
OCA\Libresign\Migration\ResynchronizeDatabaseSequences
+ OCA\Libresign\Migration\NotifyAdminsAfterUpgrade
diff --git a/lib/Migration/NotifyAdminsAfterUpgrade.php b/lib/Migration/NotifyAdminsAfterUpgrade.php
new file mode 100644
index 0000000000..a20082a1c1
--- /dev/null
+++ b/lib/Migration/NotifyAdminsAfterUpgrade.php
@@ -0,0 +1,59 @@
+appManager->getAppVersion(AppInfoApplication::APP_ID);
+ $lastNotifiedVersion = $this->config->getAppValue(AppInfoApplication::APP_ID, 'last_notified_version', '');
+
+ if ($currentVersion === $lastNotifiedVersion) {
+ return;
+ }
+
+ $admins = $this->userManager->search('', 1, 0, ['admin']);
+ foreach ($admins as $admin) {
+ $notification = $this->notificationManager->createNotification();
+ $notification
+ ->setApp(AppInfoApplication::APP_ID)
+ ->setUser($admin->getUID())
+ ->setDateTime(new \DateTime())
+ ->setObject('upgrade', '1')
+ ->setSubject('libresign_upgrade', [
+ 'version' => $currentVersion,
+ 'message' => 'If LibreSign is useful to you or your organization, please consider supporting our cooperative by clicking the Donate button below.',
+ ]);
+ $this->notificationManager->notify($notification);
+ }
+
+ $this->config->setAppValue(AppInfoApplication::APP_ID, 'last_notified_version', $currentVersion);
+ }
+
+}
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index 6c77dfecde..0483787604 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -49,6 +49,7 @@ public function prepare(INotification $notification, string $languageCode): INot
'new_sign_request' => $this->parseSignRequest($notification, $l, false),
'update_sign_request' => $this->parseSignRequest($notification, $l, true),
'file_signed' => $this->parseSigned($notification, $l),
+ 'libresign_upgrade' => $this->parseUpgrade($notification, $l),
default => throw new UnknownActivityException(),
};
}
@@ -221,4 +222,46 @@ private function parseSigned(
return $notification;
}
+
+ private function parseUpgrade(
+ INotification $notification,
+ IL10N $l,
+ ): INotification {
+
+ $parameters = $notification->getSubjectParameters();
+ $version = $parameters['version'] ?? '';
+ $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')));
+ $subject = $l->t('LibreSign has been updated to version %s!', [$version]);
+ $message = $parameters['message'] ?? '';
+ $notification->setParsedSubject($subject)
+ ->setParsedMessage($message);
+
+ $donateAction = $notification->createAction()
+ ->setParsedLabel($l->t('Donate'))
+ ->setPrimary(true)
+ ->setLink('https://libresign.coop', \OCP\Notification\IAction::TYPE_WEB);
+
+ $notification->addParsedAction($donateAction);
+
+ $dismissAction = $notification->createAction()
+ ->setParsedLabel($l->t('Dismiss notification'))
+ ->setPrimary(false)
+ ->setLink(
+ $this->url->linkToOCSRouteAbsolute(
+ 'libresign.notify.notificationDismiss',
+ [
+ 'apiVersion' => 'v1',
+ 'timestamp' => $notification->getDateTime()->getTimestamp(),
+ 'objectType' => 'upgrade',
+ 'objectId' => '1',
+ 'subject' => 'libresign_upgrade',
+ ],
+ ),
+ IAction::TYPE_DELETE
+ );
+
+ $notification->addParsedAction($dismissAction);
+
+ return $notification;
+ }
}