@@ -34,101 +34,101 @@ |
||
34 | 34 | use OCP\Share\IShareHelper; |
35 | 35 | |
36 | 36 | class Listener { |
37 | - /** @var IManager */ |
|
38 | - protected $activityManager; |
|
39 | - /** @var IUserSession */ |
|
40 | - protected $session; |
|
41 | - /** @var \OCP\App\IAppManager */ |
|
42 | - protected $appManager; |
|
43 | - /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
44 | - protected $mountCollection; |
|
45 | - /** @var \OCP\Files\IRootFolder */ |
|
46 | - protected $rootFolder; |
|
47 | - /** @var IShareHelper */ |
|
48 | - protected $shareHelper; |
|
37 | + /** @var IManager */ |
|
38 | + protected $activityManager; |
|
39 | + /** @var IUserSession */ |
|
40 | + protected $session; |
|
41 | + /** @var \OCP\App\IAppManager */ |
|
42 | + protected $appManager; |
|
43 | + /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
44 | + protected $mountCollection; |
|
45 | + /** @var \OCP\Files\IRootFolder */ |
|
46 | + protected $rootFolder; |
|
47 | + /** @var IShareHelper */ |
|
48 | + protected $shareHelper; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Listener constructor. |
|
52 | - * |
|
53 | - * @param IManager $activityManager |
|
54 | - * @param IUserSession $session |
|
55 | - * @param IAppManager $appManager |
|
56 | - * @param IMountProviderCollection $mountCollection |
|
57 | - * @param IRootFolder $rootFolder |
|
58 | - * @param IShareHelper $shareHelper |
|
59 | - */ |
|
60 | - public function __construct(IManager $activityManager, |
|
61 | - IUserSession $session, |
|
62 | - IAppManager $appManager, |
|
63 | - IMountProviderCollection $mountCollection, |
|
64 | - IRootFolder $rootFolder, |
|
65 | - IShareHelper $shareHelper) { |
|
66 | - $this->activityManager = $activityManager; |
|
67 | - $this->session = $session; |
|
68 | - $this->appManager = $appManager; |
|
69 | - $this->mountCollection = $mountCollection; |
|
70 | - $this->rootFolder = $rootFolder; |
|
71 | - $this->shareHelper = $shareHelper; |
|
72 | - } |
|
50 | + /** |
|
51 | + * Listener constructor. |
|
52 | + * |
|
53 | + * @param IManager $activityManager |
|
54 | + * @param IUserSession $session |
|
55 | + * @param IAppManager $appManager |
|
56 | + * @param IMountProviderCollection $mountCollection |
|
57 | + * @param IRootFolder $rootFolder |
|
58 | + * @param IShareHelper $shareHelper |
|
59 | + */ |
|
60 | + public function __construct(IManager $activityManager, |
|
61 | + IUserSession $session, |
|
62 | + IAppManager $appManager, |
|
63 | + IMountProviderCollection $mountCollection, |
|
64 | + IRootFolder $rootFolder, |
|
65 | + IShareHelper $shareHelper) { |
|
66 | + $this->activityManager = $activityManager; |
|
67 | + $this->session = $session; |
|
68 | + $this->appManager = $appManager; |
|
69 | + $this->mountCollection = $mountCollection; |
|
70 | + $this->rootFolder = $rootFolder; |
|
71 | + $this->shareHelper = $shareHelper; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param CommentsEvent $event |
|
76 | - */ |
|
77 | - public function commentEvent(CommentsEvent $event) { |
|
78 | - if ($event->getComment()->getObjectType() !== 'files' |
|
79 | - || $event->getEvent() !== CommentsEvent::EVENT_ADD |
|
80 | - || !$this->appManager->isInstalled('activity')) { |
|
81 | - // Comment not for file, not adding a comment or no activity-app enabled (save the energy) |
|
82 | - return; |
|
83 | - } |
|
74 | + /** |
|
75 | + * @param CommentsEvent $event |
|
76 | + */ |
|
77 | + public function commentEvent(CommentsEvent $event) { |
|
78 | + if ($event->getComment()->getObjectType() !== 'files' |
|
79 | + || $event->getEvent() !== CommentsEvent::EVENT_ADD |
|
80 | + || !$this->appManager->isInstalled('activity')) { |
|
81 | + // Comment not for file, not adding a comment or no activity-app enabled (save the energy) |
|
82 | + return; |
|
83 | + } |
|
84 | 84 | |
85 | - // Get all mount point owners |
|
86 | - $cache = $this->mountCollection->getMountCache(); |
|
87 | - $mounts = $cache->getMountsForFileId((int)$event->getComment()->getObjectId()); |
|
88 | - if (empty($mounts)) { |
|
89 | - return; |
|
90 | - } |
|
85 | + // Get all mount point owners |
|
86 | + $cache = $this->mountCollection->getMountCache(); |
|
87 | + $mounts = $cache->getMountsForFileId((int)$event->getComment()->getObjectId()); |
|
88 | + if (empty($mounts)) { |
|
89 | + return; |
|
90 | + } |
|
91 | 91 | |
92 | - $users = []; |
|
93 | - foreach ($mounts as $mount) { |
|
94 | - $owner = $mount->getUser()->getUID(); |
|
95 | - $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
96 | - $nodes = $ownerFolder->getById((int)$event->getComment()->getObjectId()); |
|
97 | - if (!empty($nodes)) { |
|
98 | - /** @var Node $node */ |
|
99 | - $node = array_shift($nodes); |
|
100 | - $al = $this->shareHelper->getPathsForAccessList($node); |
|
101 | - $users += $al['users']; |
|
102 | - } |
|
103 | - } |
|
92 | + $users = []; |
|
93 | + foreach ($mounts as $mount) { |
|
94 | + $owner = $mount->getUser()->getUID(); |
|
95 | + $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
96 | + $nodes = $ownerFolder->getById((int)$event->getComment()->getObjectId()); |
|
97 | + if (!empty($nodes)) { |
|
98 | + /** @var Node $node */ |
|
99 | + $node = array_shift($nodes); |
|
100 | + $al = $this->shareHelper->getPathsForAccessList($node); |
|
101 | + $users += $al['users']; |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | - $actor = $this->session->getUser(); |
|
106 | - if ($actor instanceof IUser) { |
|
107 | - $actor = $actor->getUID(); |
|
108 | - } else { |
|
109 | - $actor = ''; |
|
110 | - } |
|
105 | + $actor = $this->session->getUser(); |
|
106 | + if ($actor instanceof IUser) { |
|
107 | + $actor = $actor->getUID(); |
|
108 | + } else { |
|
109 | + $actor = ''; |
|
110 | + } |
|
111 | 111 | |
112 | - $activity = $this->activityManager->generateEvent(); |
|
113 | - $activity->setApp('comments') |
|
114 | - ->setType('comments') |
|
115 | - ->setAuthor($actor) |
|
116 | - ->setObject($event->getComment()->getObjectType(), (int) $event->getComment()->getObjectId()) |
|
117 | - ->setMessage('add_comment_message', [ |
|
118 | - 'commentId' => $event->getComment()->getId(), |
|
119 | - ]); |
|
112 | + $activity = $this->activityManager->generateEvent(); |
|
113 | + $activity->setApp('comments') |
|
114 | + ->setType('comments') |
|
115 | + ->setAuthor($actor) |
|
116 | + ->setObject($event->getComment()->getObjectType(), (int) $event->getComment()->getObjectId()) |
|
117 | + ->setMessage('add_comment_message', [ |
|
118 | + 'commentId' => $event->getComment()->getId(), |
|
119 | + ]); |
|
120 | 120 | |
121 | - foreach ($users as $user => $path) { |
|
122 | - // numerical user ids end up as integers from array keys, but string |
|
123 | - // is required |
|
124 | - $activity->setAffectedUser((string)$user); |
|
121 | + foreach ($users as $user => $path) { |
|
122 | + // numerical user ids end up as integers from array keys, but string |
|
123 | + // is required |
|
124 | + $activity->setAffectedUser((string)$user); |
|
125 | 125 | |
126 | - $activity->setSubject('add_comment_subject', [ |
|
127 | - 'actor' => $actor, |
|
128 | - 'fileId' => (int) $event->getComment()->getObjectId(), |
|
129 | - 'filePath' => trim($path, '/'), |
|
130 | - ]); |
|
131 | - $this->activityManager->publish($activity); |
|
132 | - } |
|
133 | - } |
|
126 | + $activity->setSubject('add_comment_subject', [ |
|
127 | + 'actor' => $actor, |
|
128 | + 'fileId' => (int) $event->getComment()->getObjectId(), |
|
129 | + 'filePath' => trim($path, '/'), |
|
130 | + ]); |
|
131 | + $this->activityManager->publish($activity); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | } |