@@ -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 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | |
85 | 85 | // Get all mount point owners |
86 | 86 | $cache = $this->mountCollection->getMountCache(); |
87 | - $mounts = $cache->getMountsForFileId((int)$event->getComment()->getObjectId()); |
|
87 | + $mounts = $cache->getMountsForFileId((int) $event->getComment()->getObjectId()); |
|
88 | 88 | if (empty($mounts)) { |
89 | 89 | return; |
90 | 90 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | foreach ($mounts as $mount) { |
94 | 94 | $owner = $mount->getUser()->getUID(); |
95 | 95 | $ownerFolder = $this->rootFolder->getUserFolder($owner); |
96 | - $nodes = $ownerFolder->getById((int)$event->getComment()->getObjectId()); |
|
96 | + $nodes = $ownerFolder->getById((int) $event->getComment()->getObjectId()); |
|
97 | 97 | if (!empty($nodes)) { |
98 | 98 | /** @var Node $node */ |
99 | 99 | $node = array_shift($nodes); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | foreach ($users as $user => $path) { |
122 | 122 | // numerical user ids end up as integers from array keys, but string |
123 | 123 | // is required |
124 | - $activity->setAffectedUser((string)$user); |
|
124 | + $activity->setAffectedUser((string) $user); |
|
125 | 125 | |
126 | 126 | $activity->setSubject('add_comment_subject', [ |
127 | 127 | 'actor' => $actor, |
@@ -43,224 +43,224 @@ |
||
43 | 43 | use OCP\SystemTag\TagNotFoundException; |
44 | 44 | |
45 | 45 | class Listener { |
46 | - /** @var IGroupManager */ |
|
47 | - protected $groupManager; |
|
48 | - /** @var IManager */ |
|
49 | - protected $activityManager; |
|
50 | - /** @var IUserSession */ |
|
51 | - protected $session; |
|
52 | - /** @var IConfig */ |
|
53 | - protected $config; |
|
54 | - /** @var \OCP\SystemTag\ISystemTagManager */ |
|
55 | - protected $tagManager; |
|
56 | - /** @var \OCP\App\IAppManager */ |
|
57 | - protected $appManager; |
|
58 | - /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
59 | - protected $mountCollection; |
|
60 | - /** @var \OCP\Files\IRootFolder */ |
|
61 | - protected $rootFolder; |
|
62 | - /** @var IShareHelper */ |
|
63 | - protected $shareHelper; |
|
46 | + /** @var IGroupManager */ |
|
47 | + protected $groupManager; |
|
48 | + /** @var IManager */ |
|
49 | + protected $activityManager; |
|
50 | + /** @var IUserSession */ |
|
51 | + protected $session; |
|
52 | + /** @var IConfig */ |
|
53 | + protected $config; |
|
54 | + /** @var \OCP\SystemTag\ISystemTagManager */ |
|
55 | + protected $tagManager; |
|
56 | + /** @var \OCP\App\IAppManager */ |
|
57 | + protected $appManager; |
|
58 | + /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
59 | + protected $mountCollection; |
|
60 | + /** @var \OCP\Files\IRootFolder */ |
|
61 | + protected $rootFolder; |
|
62 | + /** @var IShareHelper */ |
|
63 | + protected $shareHelper; |
|
64 | 64 | |
65 | - /** |
|
66 | - * Listener constructor. |
|
67 | - * |
|
68 | - * @param IGroupManager $groupManager |
|
69 | - * @param IManager $activityManager |
|
70 | - * @param IUserSession $session |
|
71 | - * @param IConfig $config |
|
72 | - * @param ISystemTagManager $tagManager |
|
73 | - * @param IAppManager $appManager |
|
74 | - * @param IMountProviderCollection $mountCollection |
|
75 | - * @param IRootFolder $rootFolder |
|
76 | - * @param IShareHelper $shareHelper |
|
77 | - */ |
|
78 | - public function __construct(IGroupManager $groupManager, |
|
79 | - IManager $activityManager, |
|
80 | - IUserSession $session, |
|
81 | - IConfig $config, |
|
82 | - ISystemTagManager $tagManager, |
|
83 | - IAppManager $appManager, |
|
84 | - IMountProviderCollection $mountCollection, |
|
85 | - IRootFolder $rootFolder, |
|
86 | - IShareHelper $shareHelper) { |
|
87 | - $this->groupManager = $groupManager; |
|
88 | - $this->activityManager = $activityManager; |
|
89 | - $this->session = $session; |
|
90 | - $this->config = $config; |
|
91 | - $this->tagManager = $tagManager; |
|
92 | - $this->appManager = $appManager; |
|
93 | - $this->mountCollection = $mountCollection; |
|
94 | - $this->rootFolder = $rootFolder; |
|
95 | - $this->shareHelper = $shareHelper; |
|
96 | - } |
|
65 | + /** |
|
66 | + * Listener constructor. |
|
67 | + * |
|
68 | + * @param IGroupManager $groupManager |
|
69 | + * @param IManager $activityManager |
|
70 | + * @param IUserSession $session |
|
71 | + * @param IConfig $config |
|
72 | + * @param ISystemTagManager $tagManager |
|
73 | + * @param IAppManager $appManager |
|
74 | + * @param IMountProviderCollection $mountCollection |
|
75 | + * @param IRootFolder $rootFolder |
|
76 | + * @param IShareHelper $shareHelper |
|
77 | + */ |
|
78 | + public function __construct(IGroupManager $groupManager, |
|
79 | + IManager $activityManager, |
|
80 | + IUserSession $session, |
|
81 | + IConfig $config, |
|
82 | + ISystemTagManager $tagManager, |
|
83 | + IAppManager $appManager, |
|
84 | + IMountProviderCollection $mountCollection, |
|
85 | + IRootFolder $rootFolder, |
|
86 | + IShareHelper $shareHelper) { |
|
87 | + $this->groupManager = $groupManager; |
|
88 | + $this->activityManager = $activityManager; |
|
89 | + $this->session = $session; |
|
90 | + $this->config = $config; |
|
91 | + $this->tagManager = $tagManager; |
|
92 | + $this->appManager = $appManager; |
|
93 | + $this->mountCollection = $mountCollection; |
|
94 | + $this->rootFolder = $rootFolder; |
|
95 | + $this->shareHelper = $shareHelper; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @param ManagerEvent $event |
|
100 | - */ |
|
101 | - public function event(ManagerEvent $event) { |
|
102 | - $actor = $this->session->getUser(); |
|
103 | - if ($actor instanceof IUser) { |
|
104 | - $actor = $actor->getUID(); |
|
105 | - } else { |
|
106 | - $actor = ''; |
|
107 | - } |
|
108 | - $tag = $event->getTag(); |
|
98 | + /** |
|
99 | + * @param ManagerEvent $event |
|
100 | + */ |
|
101 | + public function event(ManagerEvent $event) { |
|
102 | + $actor = $this->session->getUser(); |
|
103 | + if ($actor instanceof IUser) { |
|
104 | + $actor = $actor->getUID(); |
|
105 | + } else { |
|
106 | + $actor = ''; |
|
107 | + } |
|
108 | + $tag = $event->getTag(); |
|
109 | 109 | |
110 | - $activity = $this->activityManager->generateEvent(); |
|
111 | - $activity->setApp('systemtags') |
|
112 | - ->setType('systemtags') |
|
113 | - ->setAuthor($actor) |
|
114 | - ->setObject('systemtag', $tag->getId(), $tag->getName()); |
|
115 | - if ($event->getEvent() === ManagerEvent::EVENT_CREATE) { |
|
116 | - $activity->setSubject(Provider::CREATE_TAG, [ |
|
117 | - $actor, |
|
118 | - $this->prepareTagAsParameter($event->getTag()), |
|
119 | - ]); |
|
120 | - } else if ($event->getEvent() === ManagerEvent::EVENT_UPDATE) { |
|
121 | - $activity->setSubject(Provider::UPDATE_TAG, [ |
|
122 | - $actor, |
|
123 | - $this->prepareTagAsParameter($event->getTag()), |
|
124 | - $this->prepareTagAsParameter($event->getTagBefore()), |
|
125 | - ]); |
|
126 | - } else if ($event->getEvent() === ManagerEvent::EVENT_DELETE) { |
|
127 | - $activity->setSubject(Provider::DELETE_TAG, [ |
|
128 | - $actor, |
|
129 | - $this->prepareTagAsParameter($event->getTag()), |
|
130 | - ]); |
|
131 | - } else { |
|
132 | - return; |
|
133 | - } |
|
110 | + $activity = $this->activityManager->generateEvent(); |
|
111 | + $activity->setApp('systemtags') |
|
112 | + ->setType('systemtags') |
|
113 | + ->setAuthor($actor) |
|
114 | + ->setObject('systemtag', $tag->getId(), $tag->getName()); |
|
115 | + if ($event->getEvent() === ManagerEvent::EVENT_CREATE) { |
|
116 | + $activity->setSubject(Provider::CREATE_TAG, [ |
|
117 | + $actor, |
|
118 | + $this->prepareTagAsParameter($event->getTag()), |
|
119 | + ]); |
|
120 | + } else if ($event->getEvent() === ManagerEvent::EVENT_UPDATE) { |
|
121 | + $activity->setSubject(Provider::UPDATE_TAG, [ |
|
122 | + $actor, |
|
123 | + $this->prepareTagAsParameter($event->getTag()), |
|
124 | + $this->prepareTagAsParameter($event->getTagBefore()), |
|
125 | + ]); |
|
126 | + } else if ($event->getEvent() === ManagerEvent::EVENT_DELETE) { |
|
127 | + $activity->setSubject(Provider::DELETE_TAG, [ |
|
128 | + $actor, |
|
129 | + $this->prepareTagAsParameter($event->getTag()), |
|
130 | + ]); |
|
131 | + } else { |
|
132 | + return; |
|
133 | + } |
|
134 | 134 | |
135 | - $group = $this->groupManager->get('admin'); |
|
136 | - if ($group instanceof IGroup) { |
|
137 | - foreach ($group->getUsers() as $user) { |
|
138 | - $activity->setAffectedUser($user->getUID()); |
|
139 | - $this->activityManager->publish($activity); |
|
140 | - } |
|
141 | - } |
|
135 | + $group = $this->groupManager->get('admin'); |
|
136 | + if ($group instanceof IGroup) { |
|
137 | + foreach ($group->getUsers() as $user) { |
|
138 | + $activity->setAffectedUser($user->getUID()); |
|
139 | + $this->activityManager->publish($activity); |
|
140 | + } |
|
141 | + } |
|
142 | 142 | |
143 | 143 | |
144 | - if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) { |
|
145 | - $this->updateLastUsedTags($actor, $event->getTag()); |
|
146 | - } |
|
147 | - } |
|
144 | + if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) { |
|
145 | + $this->updateLastUsedTags($actor, $event->getTag()); |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * @param MapperEvent $event |
|
151 | - */ |
|
152 | - public function mapperEvent(MapperEvent $event) { |
|
153 | - $tagIds = $event->getTags(); |
|
154 | - if ($event->getObjectType() !== 'files' ||empty($tagIds) |
|
155 | - || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
|
156 | - || !$this->appManager->isInstalled('activity')) { |
|
157 | - // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy) |
|
158 | - return; |
|
159 | - } |
|
149 | + /** |
|
150 | + * @param MapperEvent $event |
|
151 | + */ |
|
152 | + public function mapperEvent(MapperEvent $event) { |
|
153 | + $tagIds = $event->getTags(); |
|
154 | + if ($event->getObjectType() !== 'files' ||empty($tagIds) |
|
155 | + || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
|
156 | + || !$this->appManager->isInstalled('activity')) { |
|
157 | + // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy) |
|
158 | + return; |
|
159 | + } |
|
160 | 160 | |
161 | - try { |
|
162 | - $tags = $this->tagManager->getTagsByIds($tagIds); |
|
163 | - } catch (TagNotFoundException $e) { |
|
164 | - // User assigned/unassigned a non-existing tag, ignore... |
|
165 | - return; |
|
166 | - } |
|
161 | + try { |
|
162 | + $tags = $this->tagManager->getTagsByIds($tagIds); |
|
163 | + } catch (TagNotFoundException $e) { |
|
164 | + // User assigned/unassigned a non-existing tag, ignore... |
|
165 | + return; |
|
166 | + } |
|
167 | 167 | |
168 | - if (empty($tags)) { |
|
169 | - return; |
|
170 | - } |
|
168 | + if (empty($tags)) { |
|
169 | + return; |
|
170 | + } |
|
171 | 171 | |
172 | - // Get all mount point owners |
|
173 | - $cache = $this->mountCollection->getMountCache(); |
|
174 | - $mounts = $cache->getMountsForFileId($event->getObjectId()); |
|
175 | - if (empty($mounts)) { |
|
176 | - return; |
|
177 | - } |
|
172 | + // Get all mount point owners |
|
173 | + $cache = $this->mountCollection->getMountCache(); |
|
174 | + $mounts = $cache->getMountsForFileId($event->getObjectId()); |
|
175 | + if (empty($mounts)) { |
|
176 | + return; |
|
177 | + } |
|
178 | 178 | |
179 | - $users = []; |
|
180 | - foreach ($mounts as $mount) { |
|
181 | - $owner = $mount->getUser()->getUID(); |
|
182 | - $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
183 | - $nodes = $ownerFolder->getById($event->getObjectId()); |
|
184 | - if (!empty($nodes)) { |
|
185 | - /** @var Node $node */ |
|
186 | - $node = array_shift($nodes); |
|
187 | - $al = $this->shareHelper->getPathsForAccessList($node); |
|
188 | - $users += $al['users']; |
|
189 | - } |
|
190 | - } |
|
179 | + $users = []; |
|
180 | + foreach ($mounts as $mount) { |
|
181 | + $owner = $mount->getUser()->getUID(); |
|
182 | + $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
183 | + $nodes = $ownerFolder->getById($event->getObjectId()); |
|
184 | + if (!empty($nodes)) { |
|
185 | + /** @var Node $node */ |
|
186 | + $node = array_shift($nodes); |
|
187 | + $al = $this->shareHelper->getPathsForAccessList($node); |
|
188 | + $users += $al['users']; |
|
189 | + } |
|
190 | + } |
|
191 | 191 | |
192 | - $actor = $this->session->getUser(); |
|
193 | - if ($actor instanceof IUser) { |
|
194 | - $actor = $actor->getUID(); |
|
195 | - } else { |
|
196 | - $actor = ''; |
|
197 | - } |
|
192 | + $actor = $this->session->getUser(); |
|
193 | + if ($actor instanceof IUser) { |
|
194 | + $actor = $actor->getUID(); |
|
195 | + } else { |
|
196 | + $actor = ''; |
|
197 | + } |
|
198 | 198 | |
199 | - $activity = $this->activityManager->generateEvent(); |
|
200 | - $activity->setApp('systemtags') |
|
201 | - ->setType('systemtags') |
|
202 | - ->setAuthor($actor) |
|
203 | - ->setObject($event->getObjectType(), (int) $event->getObjectId()); |
|
199 | + $activity = $this->activityManager->generateEvent(); |
|
200 | + $activity->setApp('systemtags') |
|
201 | + ->setType('systemtags') |
|
202 | + ->setAuthor($actor) |
|
203 | + ->setObject($event->getObjectType(), (int) $event->getObjectId()); |
|
204 | 204 | |
205 | - foreach ($users as $user => $path) { |
|
206 | - $user = (string)$user; // numerical ids could be ints which are not accepted everywhere |
|
207 | - $activity->setAffectedUser($user); |
|
205 | + foreach ($users as $user => $path) { |
|
206 | + $user = (string)$user; // numerical ids could be ints which are not accepted everywhere |
|
207 | + $activity->setAffectedUser($user); |
|
208 | 208 | |
209 | - foreach ($tags as $tag) { |
|
210 | - // don't publish activity for non-admins if tag is invisible |
|
211 | - if (!$tag->isUserVisible() && !$this->groupManager->isAdmin($user)) { |
|
212 | - continue; |
|
213 | - } |
|
214 | - if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
215 | - $activity->setSubject(Provider::ASSIGN_TAG, [ |
|
216 | - $actor, |
|
217 | - $path, |
|
218 | - $this->prepareTagAsParameter($tag), |
|
219 | - ]); |
|
220 | - } else if ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) { |
|
221 | - $activity->setSubject(Provider::UNASSIGN_TAG, [ |
|
222 | - $actor, |
|
223 | - $path, |
|
224 | - $this->prepareTagAsParameter($tag), |
|
225 | - ]); |
|
226 | - } |
|
209 | + foreach ($tags as $tag) { |
|
210 | + // don't publish activity for non-admins if tag is invisible |
|
211 | + if (!$tag->isUserVisible() && !$this->groupManager->isAdmin($user)) { |
|
212 | + continue; |
|
213 | + } |
|
214 | + if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
215 | + $activity->setSubject(Provider::ASSIGN_TAG, [ |
|
216 | + $actor, |
|
217 | + $path, |
|
218 | + $this->prepareTagAsParameter($tag), |
|
219 | + ]); |
|
220 | + } else if ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) { |
|
221 | + $activity->setSubject(Provider::UNASSIGN_TAG, [ |
|
222 | + $actor, |
|
223 | + $path, |
|
224 | + $this->prepareTagAsParameter($tag), |
|
225 | + ]); |
|
226 | + } |
|
227 | 227 | |
228 | - $this->activityManager->publish($activity); |
|
229 | - } |
|
230 | - } |
|
228 | + $this->activityManager->publish($activity); |
|
229 | + } |
|
230 | + } |
|
231 | 231 | |
232 | - if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
233 | - foreach ($tags as $tag) { |
|
234 | - $this->updateLastUsedTags($actor, $tag); |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
232 | + if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
233 | + foreach ($tags as $tag) { |
|
234 | + $this->updateLastUsedTags($actor, $tag); |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * @param string $actor |
|
241 | - * @param ISystemTag $tag |
|
242 | - */ |
|
243 | - protected function updateLastUsedTags($actor, ISystemTag $tag) { |
|
244 | - $lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]'); |
|
245 | - $lastUsedTags = json_decode($lastUsedTags, true); |
|
239 | + /** |
|
240 | + * @param string $actor |
|
241 | + * @param ISystemTag $tag |
|
242 | + */ |
|
243 | + protected function updateLastUsedTags($actor, ISystemTag $tag) { |
|
244 | + $lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]'); |
|
245 | + $lastUsedTags = json_decode($lastUsedTags, true); |
|
246 | 246 | |
247 | - array_unshift($lastUsedTags, $tag->getId()); |
|
248 | - array_unique($lastUsedTags); |
|
249 | - $lastUsedTags = array_slice($lastUsedTags, 0, 10); |
|
247 | + array_unshift($lastUsedTags, $tag->getId()); |
|
248 | + array_unique($lastUsedTags); |
|
249 | + $lastUsedTags = array_slice($lastUsedTags, 0, 10); |
|
250 | 250 | |
251 | - $this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags)); |
|
252 | - } |
|
251 | + $this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags)); |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * @param ISystemTag $tag |
|
256 | - * @return string |
|
257 | - */ |
|
258 | - protected function prepareTagAsParameter(ISystemTag $tag) { |
|
259 | - return json_encode([ |
|
260 | - 'id' => $tag->getId(), |
|
261 | - 'name' => $tag->getName(), |
|
262 | - 'assignable' => $tag->isUserAssignable(), |
|
263 | - 'visible' => $tag->isUserVisible(), |
|
264 | - ]); |
|
265 | - } |
|
254 | + /** |
|
255 | + * @param ISystemTag $tag |
|
256 | + * @return string |
|
257 | + */ |
|
258 | + protected function prepareTagAsParameter(ISystemTag $tag) { |
|
259 | + return json_encode([ |
|
260 | + 'id' => $tag->getId(), |
|
261 | + 'name' => $tag->getName(), |
|
262 | + 'assignable' => $tag->isUserAssignable(), |
|
263 | + 'visible' => $tag->isUserVisible(), |
|
264 | + ]); |
|
265 | + } |
|
266 | 266 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function mapperEvent(MapperEvent $event) { |
153 | 153 | $tagIds = $event->getTags(); |
154 | - if ($event->getObjectType() !== 'files' ||empty($tagIds) |
|
154 | + if ($event->getObjectType() !== 'files' || empty($tagIds) |
|
155 | 155 | || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
156 | 156 | || !$this->appManager->isInstalled('activity')) { |
157 | 157 | // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy) |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | ->setObject($event->getObjectType(), (int) $event->getObjectId()); |
204 | 204 | |
205 | 205 | foreach ($users as $user => $path) { |
206 | - $user = (string)$user; // numerical ids could be ints which are not accepted everywhere |
|
206 | + $user = (string) $user; // numerical ids could be ints which are not accepted everywhere |
|
207 | 207 | $activity->setAffectedUser($user); |
208 | 208 | |
209 | 209 | foreach ($tags as $tag) { |