2020use OCP \IURLGenerator ;
2121use OCP \IUserManager ;
2222use OCP \L10N \IFactory ;
23- use OCP \RichObjectStrings \IValidator ;
2423use Psr \Log \LoggerInterface ;
2524
2625class Provider implements IProvider {
2726 public function __construct (
2827 protected string $ appName ,
29- private FormMapper $ formMapper ,
30- private IEventMerger $ eventMerger ,
31- private IGroupManager $ groupManager ,
32- private LoggerInterface $ logger ,
33- private IURLGenerator $ urlGenerator ,
34- private IUserManager $ userManager ,
35- private IFactory $ l10nFactory ,
36- private IValidator $ validator ,
37- private CirclesService $ circlesService ,
28+ private readonly FormMapper $ formMapper ,
29+ private readonly IEventMerger $ eventMerger ,
30+ private readonly IGroupManager $ groupManager ,
31+ private readonly LoggerInterface $ logger ,
32+ private readonly IURLGenerator $ urlGenerator ,
33+ private readonly IUserManager $ userManager ,
34+ private readonly IFactory $ l10nFactory ,
35+ private readonly CirclesService $ circlesService ,
3836 ) {
3937 }
4038
@@ -113,32 +111,27 @@ public function parseSubjectString(string $subjectString, array $parameters): st
113111 * @return array
114112 */
115113 public function getRichParams (IL10N $ l10n , string $ subject , array $ params ): array {
116- switch ($ subject ) {
117- case ActivityConstants::SUBJECT_NEWSHARE :
118- return [
119- 'user ' => $ this ->getRichUser ($ l10n , $ params ['userId ' ]),
120- 'formTitle ' => $ this ->getRichFormTitle ($ params ['formTitle ' ], $ params ['formHash ' ])
121- ];
122- case ActivityConstants::SUBJECT_NEWGROUPSHARE :
123- return [
124- 'user ' => $ this ->getRichUser ($ l10n , $ params ['userId ' ]),
125- 'formTitle ' => $ this ->getRichFormTitle ($ params ['formTitle ' ], $ params ['formHash ' ]),
126- 'group ' => $ this ->getRichGroup ($ params ['groupId ' ])
127- ];
128- case ActivityConstants::SUBJECT_NEWCIRCLESHARE :
129- return [
130- 'user ' => $ this ->getRichUser ($ l10n , $ params ['userId ' ]),
131- 'formTitle ' => $ this ->getRichFormTitle ($ params ['formTitle ' ], $ params ['formHash ' ]),
132- 'circle ' => $ this ->getRichCircle ($ params ['circleId ' ])
133- ];
134- case ActivityConstants::SUBJECT_NEWSUBMISSION :
135- return [
136- 'user ' => $ this ->getRichUser ($ l10n , $ params ['userId ' ]),
137- 'formTitle ' => $ this ->getRichFormTitle ($ params ['formTitle ' ], $ params ['formHash ' ], 'results ' )
138- ];
139- default :
140- return [];
141- }
114+ return match ($ subject ) {
115+ ActivityConstants::SUBJECT_NEWSHARE => [
116+ 'user ' => $ this ->getRichUser ($ l10n , $ params ['userId ' ]),
117+ 'formTitle ' => $ this ->getRichFormTitle ($ params ['formTitle ' ], $ params ['formHash ' ])
118+ ],
119+ ActivityConstants::SUBJECT_NEWGROUPSHARE => [
120+ 'user ' => $ this ->getRichUser ($ l10n , $ params ['userId ' ]),
121+ 'formTitle ' => $ this ->getRichFormTitle ($ params ['formTitle ' ], $ params ['formHash ' ]),
122+ 'group ' => $ this ->getRichGroup ($ params ['groupId ' ])
123+ ],
124+ ActivityConstants::SUBJECT_NEWCIRCLESHARE => [
125+ 'user ' => $ this ->getRichUser ($ l10n , $ params ['userId ' ]),
126+ 'formTitle ' => $ this ->getRichFormTitle ($ params ['formTitle ' ], $ params ['formHash ' ]),
127+ 'circle ' => $ this ->getRichCircle ($ params ['circleId ' ])
128+ ],
129+ ActivityConstants::SUBJECT_NEWSUBMISSION => [
130+ 'user ' => $ this ->getRichUser ($ l10n , $ params ['userId ' ]),
131+ 'formTitle ' => $ this ->getRichFormTitle ($ params ['formTitle ' ], $ params ['formHash ' ], 'results ' )
132+ ],
133+ default => [],
134+ };
142135 }
143136
144137 /**
@@ -148,7 +141,7 @@ public function getRichParams(IL10N $l10n, string $subject, array $params): arra
148141 */
149142 public function getRichUser (IL10N $ l10n , string $ userId ): array {
150143 // Special handling for anonyomous users
151- if (substr ($ userId , 0 , 10 ) === 'anon-user- ' ) {
144+ if (str_starts_with ($ userId , 'anon-user- ' ) ) {
152145 return [
153146 'type ' => 'highlight ' ,
154147 'id ' => $ userId ,
@@ -198,7 +191,7 @@ public function getRichGroup(string $groupId): array {
198191 /**
199192 * Turn a circleId into a rich-circle array.
200193 *
201- * @param string $groupId
194+ * @param string $circleId
202195 * @return array
203196 */
204197 public function getRichCircle (string $ circleId ): array {
@@ -240,7 +233,7 @@ public function getRichFormTitle(string $formTitle, string $formHash, string $ro
240233 if ($ route !== '' ) {
241234 $ formLink .= '/ ' . $ route ;
242235 }
243- } catch (IMapperException $ e ) {
236+ } catch (IMapperException ) {
244237 // Ignore if not found, just use stored title
245238 }
246239
@@ -260,14 +253,10 @@ public function getRichFormTitle(string $formTitle, string $formHash, string $ro
260253 * @return string
261254 */
262255 public function getEventIcon (string $ subject ): string {
263- switch ($ subject ) {
264- case ActivityConstants::SUBJECT_NEWSHARE :
265- case ActivityConstants::SUBJECT_NEWGROUPSHARE :
266- return $ this ->urlGenerator ->getAbsoluteURL ($ this ->urlGenerator ->imagePath ('core ' , 'actions/shared.svg ' ));
267- case ActivityConstants::SUBJECT_NEWSUBMISSION :
268- return $ this ->urlGenerator ->getAbsoluteURL ($ this ->urlGenerator ->imagePath ('core ' , 'actions/add.svg ' ));
269- default :
270- return $ this ->urlGenerator ->getAbsoluteURL ($ this ->urlGenerator ->imagePath ('forms ' , 'forms-dark.svg ' ));
271- }
256+ return match ($ subject ) {
257+ ActivityConstants::SUBJECT_NEWSHARE , ActivityConstants::SUBJECT_NEWGROUPSHARE => $ this ->urlGenerator ->getAbsoluteURL ($ this ->urlGenerator ->imagePath ('core ' , 'actions/shared.svg ' )),
258+ ActivityConstants::SUBJECT_NEWSUBMISSION => $ this ->urlGenerator ->getAbsoluteURL ($ this ->urlGenerator ->imagePath ('core ' , 'actions/add.svg ' )),
259+ default => $ this ->urlGenerator ->getAbsoluteURL ($ this ->urlGenerator ->imagePath ('forms ' , 'forms-dark.svg ' )),
260+ };
272261 }
273262}
0 commit comments