77 */
88namespace OCA \Files \Service ;
99
10- use OCA \Files \Activity \FavoriteProvider ;
1110use OCP \Activity \IManager ;
12- use OCP \EventDispatcher \IEventDispatcher ;
13- use OCP \Files \Events \NodeAddedToFavorite ;
14- use OCP \Files \Events \NodeRemovedFromFavorite ;
1511use OCP \Files \Folder ;
1612use OCP \Files \NotFoundException ;
1713use OCP \ITags ;
18- use OCP \IUser ;
1914use OCP \IUserSession ;
2015
2116/**
@@ -28,7 +23,6 @@ public function __construct(
2823 private IManager $ activityManager ,
2924 private ?ITags $ tagger ,
3025 private ?Folder $ homeFolder ,
31- private IEventDispatcher $ dispatcher ,
3226 ) {
3327 }
3428
@@ -60,57 +54,15 @@ public function updateFileTags($path, $tags) {
6054
6155 $ newTags = array_diff ($ tags , $ currentTags );
6256 foreach ($ newTags as $ tag ) {
63- if ($ tag === ITags::TAG_FAVORITE ) {
64- $ this ->addActivity (true , $ fileId , $ path );
65- }
6657 $ this ->tagger ->tagAs ($ fileId , $ tag );
6758 }
6859 $ deletedTags = array_diff ($ currentTags , $ tags );
6960 foreach ($ deletedTags as $ tag ) {
70- if ($ tag === ITags::TAG_FAVORITE ) {
71- $ this ->addActivity (false , $ fileId , $ path );
72- }
7361 $ this ->tagger ->unTag ($ fileId , $ tag );
7462 }
7563
7664 // TODO: re-read from tagger to make sure the
7765 // list is up to date, in case of concurrent changes ?
7866 return $ tags ;
7967 }
80-
81- /**
82- * @param bool $addToFavorite
83- * @param int $fileId
84- * @param string $path
85- */
86- protected function addActivity ($ addToFavorite , $ fileId , $ path ) {
87- $ user = $ this ->userSession ->getUser ();
88- if (!$ user instanceof IUser) {
89- return ;
90- }
91-
92- if ($ addToFavorite ) {
93- $ event = new NodeAddedToFavorite ($ user , $ fileId , $ path );
94- } else {
95- $ event = new NodeRemovedFromFavorite ($ user , $ fileId , $ path );
96- }
97- $ this ->dispatcher ->dispatchTyped ($ event );
98-
99- $ event = $ this ->activityManager ->generateEvent ();
100- try {
101- $ event ->setApp ('files ' )
102- ->setObject ('files ' , $ fileId , $ path )
103- ->setType ('favorite ' )
104- ->setAuthor ($ user ->getUID ())
105- ->setAffectedUser ($ user ->getUID ())
106- ->setTimestamp (time ())
107- ->setSubject (
108- $ addToFavorite ? FavoriteProvider::SUBJECT_ADDED : FavoriteProvider::SUBJECT_REMOVED ,
109- ['id ' => $ fileId , 'path ' => $ path ]
110- );
111- $ this ->activityManager ->publish ($ event );
112- } catch (\InvalidArgumentException $ e ) {
113- } catch (\BadMethodCallException $ e ) {
114- }
115- }
11668}
0 commit comments