2016-11-16 14:09:41 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
|
|
|
*
|
|
|
|
* @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\Files_Sharing\Activity\Providers;
|
|
|
|
|
|
|
|
use OCP\Activity\IEvent;
|
|
|
|
use OCP\Activity\IManager;
|
2017-01-27 14:52:17 +03:00
|
|
|
use OCP\Federation\ICloudIdManager;
|
2016-11-16 14:09:41 +03:00
|
|
|
use OCP\IURLGenerator;
|
2017-01-27 14:52:17 +03:00
|
|
|
use OCP\IUserManager;
|
2016-12-01 13:35:23 +03:00
|
|
|
use OCP\L10N\IFactory;
|
2016-11-16 14:09:41 +03:00
|
|
|
|
2017-02-08 13:55:50 +03:00
|
|
|
class RemoteShares extends Base {
|
2016-11-16 14:09:41 +03:00
|
|
|
|
2017-01-27 14:52:17 +03:00
|
|
|
protected $cloudIdManager;
|
|
|
|
|
2016-11-16 14:09:41 +03:00
|
|
|
const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted';
|
|
|
|
const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined';
|
|
|
|
const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received';
|
|
|
|
const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared';
|
|
|
|
|
2017-01-27 14:52:17 +03:00
|
|
|
/**
|
|
|
|
* @param IFactory $languageFactory
|
|
|
|
* @param IURLGenerator $url
|
|
|
|
* @param IManager $activityManager
|
|
|
|
* @param IUserManager $userManager
|
|
|
|
* @param ICloudIdManager $cloudIdManager
|
|
|
|
*/
|
|
|
|
public function __construct(IFactory $languageFactory,
|
|
|
|
IURLGenerator $url,
|
|
|
|
IManager $activityManager,
|
|
|
|
IUserManager $userManager,
|
|
|
|
ICloudIdManager $cloudIdManager
|
|
|
|
) {
|
|
|
|
parent::__construct($languageFactory, $url, $activityManager, $userManager);
|
|
|
|
$this->cloudIdManager = $cloudIdManager;
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:09:41 +03:00
|
|
|
/**
|
|
|
|
* @param IEvent $event
|
|
|
|
* @return IEvent
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @since 11.0.0
|
|
|
|
*/
|
|
|
|
public function parseShortVersion(IEvent $event) {
|
|
|
|
$parsedParameters = $this->getParsedParameters($event);
|
|
|
|
|
|
|
|
if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('{user} accepted the remote share');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('{user} declined the remote share');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
|
2017-06-20 14:48:51 +03:00
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2017-02-08 13:55:50 +03:00
|
|
|
$this->setSubjects($event, $subject, $parsedParameters);
|
|
|
|
|
2016-11-16 14:09:41 +03:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IEvent $event
|
|
|
|
* @return IEvent
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @since 11.0.0
|
|
|
|
*/
|
|
|
|
public function parseLongVersion(IEvent $event) {
|
|
|
|
$parsedParameters = $this->getParsedParameters($event);
|
|
|
|
|
|
|
|
if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_RECEIVED) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('You received a new remote share {file} from {user}');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('{user} accepted the remote share of {file}');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('{user} declined the remote share of {file}');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_UNSHARED) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('{user} unshared {file} from you');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
|
2017-06-20 14:48:51 +03:00
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2017-02-08 13:55:50 +03:00
|
|
|
$this->setSubjects($event, $subject, $parsedParameters);
|
|
|
|
|
2016-11-16 14:09:41 +03:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getParsedParameters(IEvent $event) {
|
|
|
|
$subject = $event->getSubject();
|
|
|
|
$parameters = $event->getSubjectParameters();
|
|
|
|
|
|
|
|
switch ($subject) {
|
|
|
|
case self::SUBJECT_REMOTE_SHARE_RECEIVED:
|
|
|
|
case self::SUBJECT_REMOTE_SHARE_UNSHARED:
|
|
|
|
return [
|
|
|
|
'file' => [
|
|
|
|
'type' => 'pending-federated-share',
|
|
|
|
'id' => $parameters[1],
|
|
|
|
'name' => $parameters[1],
|
|
|
|
],
|
2017-02-08 13:55:50 +03:00
|
|
|
'user' => $this->getFederatedUser($parameters[0]),
|
2016-11-16 14:09:41 +03:00
|
|
|
];
|
|
|
|
case self::SUBJECT_REMOTE_SHARE_ACCEPTED:
|
|
|
|
case self::SUBJECT_REMOTE_SHARE_DECLINED:
|
2017-07-10 13:10:36 +03:00
|
|
|
$fileParameter = $parameters[1];
|
|
|
|
if (!is_array($fileParameter)) {
|
|
|
|
$fileParameter = [$event->getObjectId() => $event->getObjectName()];
|
|
|
|
}
|
2016-11-16 14:09:41 +03:00
|
|
|
return [
|
2017-07-10 13:10:36 +03:00
|
|
|
'file' => $this->getFile($fileParameter),
|
2017-02-08 13:55:50 +03:00
|
|
|
'user' => $this->getFederatedUser($parameters[0]),
|
2016-11-16 14:09:41 +03:00
|
|
|
];
|
|
|
|
}
|
2016-11-23 00:46:18 +03:00
|
|
|
throw new \InvalidArgumentException();
|
2016-11-16 14:09:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-02-08 13:55:50 +03:00
|
|
|
* @param string $cloudId
|
2016-11-16 14:09:41 +03:00
|
|
|
* @return array
|
|
|
|
*/
|
2017-02-08 13:55:50 +03:00
|
|
|
protected function getFederatedUser($cloudId) {
|
2017-01-27 14:52:17 +03:00
|
|
|
$remoteUser = $this->cloudIdManager->resolveCloudId($cloudId);
|
2016-11-16 14:09:41 +03:00
|
|
|
return [
|
2017-02-08 13:55:50 +03:00
|
|
|
'type' => 'user',
|
2017-01-27 14:52:17 +03:00
|
|
|
'id' => $remoteUser->getUser(),
|
2017-02-08 13:55:50 +03:00
|
|
|
'name' => $cloudId,// Todo display name from contacts
|
2017-01-27 14:52:17 +03:00
|
|
|
'server' => $remoteUser->getRemote(),
|
2016-11-16 14:09:41 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|