Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/firstrunwizard.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-07-11 14:25:07 +0300
committerJulius Härtl <jus@bitgrid.net>2019-07-16 17:21:49 +0300
commitf06a744f531ae867952440ba91320c2412513471 (patch)
treee774f8389192ed5f97cd8f8ddfc0e6ab9665205b
parent0c66132df8fcf14af9e4a9288c0c8477585a7790 (diff)
Notify admin on first login about suggested apps
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r--img/apps/calendar.svg1
-rw-r--r--img/apps/contacts.svg1
-rw-r--r--img/apps/mail.svg4
-rw-r--r--img/apps/spreed.svg1
-rw-r--r--lib/AppInfo/Application.php7
-rw-r--r--lib/Notification/AppHint.php109
-rw-r--r--lib/Notification/Notifier.php44
7 files changed, 165 insertions, 2 deletions
diff --git a/img/apps/calendar.svg b/img/apps/calendar.svg
new file mode 100644
index 00000000..020ae8fe
--- /dev/null
+++ b/img/apps/calendar.svg
@@ -0,0 +1 @@
+<svg height="16" width="16" xmlns="http://www.w3.org/2000/svg" version="1.1" viewbox="0 0 16 16"><path d="m4 1c-0.5 0-1 0.5-1 1v2c0 0.5 0.5 1 1 1s1-0.5 1-1v-2c0-0.5-0.5-1-1-1zm8 0c-0.5 0-1 0.5-1 1v2c0 0.5 0.5 1 1 1s1-0.5 1-1v-2c0-0.5-0.5-1-1-1zm-6.5 2v1c0 0.831-0.5 1.5-1.5 1.5s-1.5-0.5-1.5-1.5v-0.9375c-0.8841 0.227-1.5 1.0247-1.5 1.9375v8c0 1.108 0.892 2 2 2h10c1.108 0 2-0.892 2-2v-8c0-0.9128-0.61588-1.7105-1.5-1.9375v0.9375c0 0.831-0.5 1.5-1.5 1.5s-1.5-0.5-1.5-1.5v-1zm7.5 5v5h-10v-5z"/></svg>
diff --git a/img/apps/contacts.svg b/img/apps/contacts.svg
new file mode 100644
index 00000000..5bc91dc5
--- /dev/null
+++ b/img/apps/contacts.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 16 16" height="16" width="16" version="1.1"><path d="m9 1c-1.746 0-3 1.43-3 2.8 0 1.4 0.1 2.4 0.8 3.5 0.224 0.29 0.485 0.35 0.7 0.6 0.135 0.5 0.24 1 0.1 1.5-0.436 0.153-0.85 0.332-1.27 0.5-0.51-0.273-1.1-0.5-1.61-0.7-0.07-0.28-0.02-0.487 0.05-0.75 0.12-0.125 0.23-0.18 0.36-0.3 0.37-0.45 0.39-1.21 0.39-1.75 0-0.8-0.72-1.4-1.5-1.4-0.87 0-1.5 0.72-1.5 1.4h-0.02c0 0.7 0.05 1.2 0.4 1.75 0.1 0.15 0.242 0.175 0.35 0.3 0.0674 0.25 0.121 0.5 0.05 0.75-0.64 0.223-1.244 0.5-1.8 0.8-0.42 0.3-0.233 0.182-0.5 1.15-0.124 0.5 1.3 0.73 2.32 0.81-0.05 0.275-0.12 0.64-0.32 1.34-0.32 1.25 4.353 1.7 6 1.7 2.43 0 6.313-0.456 5.98-1.7-0.52-1.94-0.208-1.71-0.98-2.3-1.09-0.654-2.452-1.167-3.6-1.6-0.15-0.557-0.04-0.97 0.1-1.5 0.235-0.25 0.5-0.36 0.72-0.6 0.69-0.884 0.78-2.424 0.78-3.5 0-1.586-1.43-2.8-3-2.8z"/></svg>
diff --git a/img/apps/mail.svg b/img/apps/mail.svg
new file mode 100644
index 00000000..57c5010b
--- /dev/null
+++ b/img/apps/mail.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns="http://www.w3.org/2000/svg" height="32" width="32" version="1.0" viewBox="0 0 32 32">
+ <path fill="#000" d="m1.7778 6c-0.98491 0-1.7778 0.7935-1.7778 1.7784v16.446c0 0.985 0.79289 1.776 1.7778 1.776h28.444c0.985 0 1.778-0.791 1.778-1.776v-16.446c0-0.9849-0.793-1.7784-1.778-1.7784zm1.5 2.0562 12.167 12.167h1.0556l12.222-12.167 1.2222 1.2222-7.2778 7.3889 5.5 5.6111-1.2222 1.2222-5.6111-5.6111-4.0556 4.1111h-2.5556l-4.055-4.11-5.6114 5.666-1.2223-1.278 5.5556-5.611-7.3333-7.3886z"/>
+</svg>
diff --git a/img/apps/spreed.svg b/img/apps/spreed.svg
new file mode 100644
index 00000000..3b0f0e64
--- /dev/null
+++ b/img/apps/spreed.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1" viewBox="0 0 16 16"><path d="m7.9992 0.999a6.9993 6.9994 0 0 0 -6.9992 6.9996 6.9993 6.9994 0 0 0 6.9992 6.9994 6.9993 6.9994 0 0 0 3.6308 -1.024c0.86024 0.34184 2.7871 1.356 3.2457 0.91794 0.47922-0.45765-0.56261-2.6116-0.81238-3.412a6.9993 6.9994 0 0 0 0.935 -3.4814 6.9993 6.9994 0 0 0 -6.9991 -6.9993zm0.0008 2.6611a4.34 4.3401 0 0 1 4.34 4.3401 4.34 4.3401 0 0 1 -4.34 4.3398 4.34 4.3401 0 0 1 -4.34 -4.3398 4.34 4.3401 0 0 1 4.34 -4.3401z" stroke-width="0.14"/></svg>
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index f517b27c..163a226c 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -23,6 +23,7 @@
namespace OCA\FirstRunWizard\AppInfo;
+use OCA\FirstRunWizard\Notification\AppHint;
use OCA\FirstRunWizard\Notification\Notifier;
use OCP\AppFramework\App;
use OCP\AppFramework\Http\TemplateResponse;
@@ -69,7 +70,7 @@ class Application extends App {
/** @var IConfig $config */
$config = $this->getContainer()->query(IConfig::class);
-
+ $appHint = $this->getContainer()->query(AppHint::class);
if ($config->getUserValue($user->getUID(), 'firstrunwizard', 'show', '1') !== '0') {
\OC_Util::addScript('firstrunwizard', 'activate');
@@ -77,6 +78,7 @@ class Application extends App {
$jobList = $this->getContainer()->getServer()->getJobList();
$jobList->add('OCA\FirstRunWizard\Notification\BackgroundJob', ['uid' => $userSession->getUser()->getUID()]);
}
+ $appHint->sendAppHintNotifications();
});
}
@@ -90,5 +92,8 @@ class Application extends App {
'name' => $l->t('First run wizard'),
];
});
+ /** @var AppHint $appHint */
+ $appHint = $this->getContainer()->query(AppHint::class);
+ $appHint->registerAppListener();
}
}
diff --git a/lib/Notification/AppHint.php b/lib/Notification/AppHint.php
new file mode 100644
index 00000000..01c2be88
--- /dev/null
+++ b/lib/Notification/AppHint.php
@@ -0,0 +1,109 @@
+<?php
+/**
+ * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\FirstRunWizard\Notification;
+
+use OCP\App\IAppManager;
+use OCP\App\ManagerEvent;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IConfig;
+use OCP\IGroupManager;
+use OCP\Notification\IManager as INotificationManager;
+
+class AppHint {
+
+ /** @var INotificationManager */
+ protected $notificationManager;
+
+ /** @var IGroupManager */
+ protected $groupManager;
+
+ /** @var IAppManager */
+ protected $appManager;
+
+ /** @var IConfig */
+ protected $config;
+
+ /** @var IEventDispatcher */
+ private $dispatcher;
+
+ /** @var string */
+ private $userId;
+
+ public function __construct(INotificationManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IConfig $config, IEventDispatcher $eventDispatcher, $userId) {
+ $this->notificationManager = $notificationManager;
+ $this->groupManager = $groupManager;
+ $this->appManager =$appManager;
+ $this->config = $config;
+ $this->dispatcher = $eventDispatcher;
+ $this->userId = $userId;
+ }
+
+ public function sendAppHintNotifications(): void {
+ if ($this->userId !== null && $this->groupManager->isAdmin($this->userId) && $this->config->getUserValue($this->userId, 'firstrunwizard', 'apphint') !== 'yes') {
+ $this->sendNotification('calendar', $this->userId);
+ $this->sendNotification('contacts', $this->userId);
+ $this->sendNotification('mail', $this->userId);
+ $this->sendNotification('spreed', $this->userId);
+ $this->config->setUserValue($this->userId, 'firstrunwizard', 'apphint', 'yes');
+ }
+ }
+
+ public function registerAppListener(): void {
+ $this->dispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function(ManagerEvent $event) {
+ $this->dismissNotification($event->getAppID());
+ });
+ }
+
+ protected function sendNotification(string $app, string $user): void {
+ $notification = $this->generateNotification($app, $user);
+ if (
+ $this->config->getUserValue($this->userId, 'firstrunwizard', 'apphint') !== 'yes'
+ && $this->notificationManager->getCount($notification) === 0
+ && !$this->appManager->isEnabledForUser($app)
+ ) {
+ $notification->setDateTime(new \DateTime());
+ $this->notificationManager->notify($notification);
+ }
+ if ($this->notificationManager->getCount($notification) === 0) {
+ return;
+ }
+ }
+
+ protected function dismissNotification(string $app) {
+ $notification = $this->notificationManager->createNotification();
+ $notification->setApp('firstrunwizard')
+ ->setSubject('apphint-'. $app)
+ ->setObject('app', $app);
+ $this->notificationManager->markProcessed($notification);
+ }
+
+ protected function generateNotification(string $app, string $user) {
+ $notification = $this->notificationManager->createNotification();
+ $notification->setApp('firstrunwizard')
+ ->setSubject('apphint-'. $app)
+ ->setObject('app', $app)
+ ->setUser($user);
+ return $notification;
+ }
+}
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index 154969a8..a5946b0a 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -81,7 +81,12 @@ class Notifier implements INotifier {
$notification->setParsedSubject($subject)
->setLink($this->url->linkToRouteAbsolute('settings.PersonalSettings.index'));
return $notification;
-
+ case 'apphint-calendar':
+ case 'apphint-contacts':
+ case 'apphint-mail':
+ case 'apphint-spreed':
+ $app = $notification->getObjectId();
+ return $this->setAppHintDetails($notification, $languageCode, $app);
default:
// Unknown subject => Unknown notification => throw
throw new \InvalidArgumentException();
@@ -116,4 +121,41 @@ class Notifier implements INotifier {
}
}
}
+
+ /**
+ * @param INotification $notification
+ * @param string $languageCode
+ * @return INotification
+ */
+ protected function setAppHintDetails(INotification $notification, $languageCode, $app) {
+ $l = $this->factory->get('firstrunwizard', $languageCode);
+ $appLink = '';
+ switch ($app) {
+ case 'calendar':
+ $notification->setParsedSubject($l->t('App recommendation - Nextcloud Calendar'));
+ $notification->setParsedMessage($l->t('Schedule work and meetings online'));
+ $appLink = '/organization/calendar';
+ break;
+ case 'contacts':
+ $notification->setParsedSubject($l->t('App recommendation - Install Nextcloud Contacts'));
+ $notification->setParsedMessage($l->t('Keep your relations organized'));
+ $appLink = '/organization/contacts';
+ break;
+ case 'mail':
+ $notification->setParsedSubject($l->t('App recommendation - Nextcloud Mail'));
+ $notification->setParsedMessage($l->t('Send and receive emails in a breeze'));
+ $appLink = '/social/mail';
+ break;
+ case 'spreed':
+ $notification->setParsedSubject($l->t('App recommendation - Nextcloud Talk'));
+ $notification->setParsedMessage($l->t('Screensharing, online meetings & web conferencing without data leaks'));
+ $appLink = '/social/spreed';
+ break;
+ }
+ $notification
+ ->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps') . $appLink, 'GET')
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('firstrunwizard', 'apps/'. $app . '.svg')));
+ return $notification;
+ }
+
}