summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-09-01 17:59:01 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-09-08 09:01:01 +0200
commitd191a0daccfa923dcef4ffa9c020fe01f3caf129 (patch)
tree585e0399cd5f6abb3b57d25ff7a88a19480889a1 /apps/files_sharing
parent57c273b2dae918e1b007c1f1d1cd37ec9f6fb248 (diff)
downloadnextcloud-server-d191a0daccfa923dcef4ffa9c020fe01f3caf129.tar.gz
nextcloud-server-d191a0daccfa923dcef4ffa9c020fe01f3caf129.zip
Add notifications for remote shares
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/api/server2server.php22
-rw-r--r--apps/files_sharing/appinfo/app.php7
-rw-r--r--apps/files_sharing/lib/notifier.php86
3 files changed, 115 insertions, 0 deletions
diff --git a/apps/files_sharing/api/server2server.php b/apps/files_sharing/api/server2server.php
index 4328e3830ba..d5f1dce5055 100644
--- a/apps/files_sharing/api/server2server.php
+++ b/apps/files_sharing/api/server2server.php
@@ -82,6 +82,28 @@ class Server2Server {
Activity::FILES_SHARING_APP, Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user, trim($name, '/')), '', array(),
'', '', $shareWith, Activity::TYPE_REMOTE_SHARE, Activity::PRIORITY_LOW);
+ $urlGenerator = \OC::$server->getURLGenerator();
+
+ $notificationManager = \OC::$server->getNotificationManager();
+ $notification = $notificationManager->createNotification();
+ $notification->setApp('files_sharing')
+ ->setUser($shareWith)
+ ->setTimestamp(time())
+ ->setObject('remote_share', $remoteId)
+ ->setSubject('remote_share', [$user, trim($name, '/')]);
+
+ $acceptAction = $notification->createAction();
+ $acceptAction->setLabel('accept')
+ ->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/' . $remoteId), 'POST');
+ $declineAction = $notification->createAction();
+ $declineAction->setLabel('decline')
+ ->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/' . $remoteId), 'DELETE');
+
+ $notification->addAction($acceptAction)
+ ->addAction($declineAction);
+
+ $notificationManager->notify($notification);
+
return new \OC_OCS_Result();
} catch (\Exception $e) {
\OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR);
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index 295d013beff..20f1b046d35 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -103,3 +103,10 @@ if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') {
}
}
}
+
+$manager = \OC::$server->getNotificationManager();
+$manager->registerNotifier(function() {
+ return new \OCA\Files_Sharing\Notifier(
+ \OC::$server->getL10NFactory()
+ );
+});
diff --git a/apps/files_sharing/lib/notifier.php b/apps/files_sharing/lib/notifier.php
new file mode 100644
index 00000000000..e050d4d3c1a
--- /dev/null
+++ b/apps/files_sharing/lib/notifier.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_Sharing;
+
+
+use OCP\Notification\INotification;
+use OCP\Notification\INotifier;
+
+class Notifier implements INotifier {
+ /** @var \OCP\L10N\IFactory */
+ protected $factory;
+
+ /**
+ * @param \OCP\L10N\IFactory $factory
+ */
+ public function __construct(\OCP\L10N\IFactory $factory) {
+ $this->factory = $factory;
+ }
+
+ /**
+ * @param INotification $notification
+ * @param string $languageCode The code of the language that should be used to prepare the notification
+ * @return INotification
+ */
+ public function prepare(INotification $notification, $languageCode) {
+ if ($notification->getApp() !== 'files_sharing') {
+ // Not my app => throw
+ throw new \InvalidArgumentException();
+ }
+
+ // Read the language from the notification
+ $l = $this->factory->get('files_sharing', $languageCode);
+
+ switch ($notification->getSubject()) {
+ // Deal with known subjects
+ case 'remote_share':
+ $params = $notification->getSubjectParameters();
+ $notification->setParsedSubject(
+ (string) $l->t('You received %s as a remote share from %s', $params)
+ );
+
+ // Deal with the actions for a known subject
+ foreach ($notification->getActions() as $action) {
+ switch ($action->getLabel()) {
+ case 'accept':
+ $action->setParsedLabel(
+ (string) $l->t('Accept')
+ );
+ break;
+
+ case 'decline':
+ $action->setParsedLabel(
+ (string) $l->t('Decline')
+ );
+ break;
+ }
+
+ $notification->addParsedAction($action);
+ }
+ return $notification;
+
+ default:
+ // Unknown subject => Unknown notification => throw
+ throw new \InvalidArgumentException();
+ }
+ }
+}