Use constants for the magic strings

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-09-09 14:31:14 +02:00
parent 43517cfac6
commit 19e1892d50
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with 9 additions and 8 deletions

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace OCA\Files_Sharing\Notification;
use OC\Share\Share;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
@ -61,12 +60,12 @@ class Listener {
$share = $event->getSubject();
$notification = $this->instantiateNotification($share);
if ($share->getShareType() === Share::SHARE_TYPE_USER) {
$notification->setSubject('incoming_user_share')
if ($share->getShareType() === IShare::TYPE_USER) {
$notification->setSubject(Notifier::INCOMING_USER_SHARE)
->setUser($share->getSharedWith());
$this->notificationManager->notify($notification);
} else if ($share->getShareType() === Share::SHARE_TYPE_GROUP) {
$notification->setSubject('incoming_group_share');
} else if ($share->getShareType() === IShare::TYPE_GROUP) {
$notification->setSubject(Notifier::INCOMING_GROUP_SHARE);
$group = $this->groupManager->get($share->getSharedWith());
foreach ($group->getUsers() as $user) {
@ -108,7 +107,7 @@ class Listener {
}
$notification = $this->instantiateNotification($share);
$notification->setSubject('incoming_group_share')
$notification->setSubject(Notifier::INCOMING_GROUP_SHARE)
->setUser($user->getUID());
$this->notificationManager->notify($notification);
}

View File

@ -41,6 +41,8 @@ use OCP\Share\IManager;
use OCP\Share\IShare;
class Notifier implements INotifier {
public const INCOMING_USER_SHARE = 'incoming_user_share';
public const INCOMING_GROUP_SHARE = 'incoming_group_share';
/** @var IFactory */
protected $l10nFactory;
@ -158,7 +160,7 @@ class Notifier implements INotifier {
}
switch ($notification->getSubject()) {
case 'incoming_user_share':
case self::INCOMING_USER_SHARE:
if ($share->getSharedWith() !== $notification->getUser()) {
throw new AlreadyProcessedException();
}
@ -178,7 +180,7 @@ class Notifier implements INotifier {
];
break;
case 'incoming_group_share':
case self::INCOMING_GROUP_SHARE:
$user = $this->userManager->get($notification->getUser());
if (!$user instanceof IUser) {
throw new AlreadyProcessedException();