1111use OC \Tagging \TagMapper ;
1212use OCP \DB \Exception ;
1313use OCP \DB \QueryBuilder \IQueryBuilder ;
14+ use OCP \EventDispatcher \IEventDispatcher ;
15+ use OCP \Files \Events \NodeAddedToFavorite ;
16+ use OCP \Files \Events \NodeRemovedFromFavorite ;
1417use OCP \IDBConnection ;
1518use OCP \ITags ;
19+ use OCP \IUserSession ;
1620use OCP \Share_Backend ;
1721use Psr \Log \LoggerInterface ;
1822
@@ -21,10 +25,6 @@ class Tags implements ITags {
2125 * Used for storing objectid/categoryname pairs while rescanning.
2226 */
2327 private static array $ relations = [];
24- private string $ type ;
25- private string $ user ;
26- private IDBConnection $ db ;
27- private LoggerInterface $ logger ;
2828 private array $ tags = [];
2929
3030 /**
@@ -38,11 +38,6 @@ class Tags implements ITags {
3838 */
3939 private array $ owners = [];
4040
41- /**
42- * The Mapper we are using to communicate our Tag objects to the database.
43- */
44- private TagMapper $ mapper ;
45-
4641 /**
4742 * The sharing backend for objects of $this->type. Required if
4843 * $this->includeShared === true to determine ownership of items.
@@ -62,14 +57,18 @@ class Tags implements ITags {
6257 *
6358 * since 20.0.0 $includeShared isn't used anymore
6459 */
65- public function __construct (TagMapper $ mapper , string $ user , string $ type , LoggerInterface $ logger , IDBConnection $ connection , array $ defaultTags = []) {
66- $ this ->mapper = $ mapper ;
67- $ this ->user = $ user ;
68- $ this ->type = $ type ;
60+ public function __construct (
61+ private TagMapper $ mapper ,
62+ private string $ user ,
63+ private string $ type ,
64+ private LoggerInterface $ logger ,
65+ private IDBConnection $ db ,
66+ private IEventDispatcher $ dispatcher ,
67+ private IUserSession $ userSession ,
68+ array $ defaultTags = [],
69+ ) {
6970 $ this ->owners = [$ this ->user ];
7071 $ this ->tags = $ this ->mapper ->loadTags ($ this ->owners , $ this ->type );
71- $ this ->db = $ connection ;
72- $ this ->logger = $ logger ;
7372
7473 if (count ($ defaultTags ) > 0 && count ($ this ->tags ) === 0 ) {
7574 $ this ->addMultiple ($ defaultTags , true );
@@ -502,7 +501,7 @@ public function removeFromFavorites($objid) {
502501 * @param string $tag The id or name of the tag
503502 * @return boolean Returns false on error.
504503 */
505- public function tagAs ($ objid , $ tag ) {
504+ public function tagAs ($ objid , $ tag, string $ path = '' ) {
506505 if (is_string ($ tag ) && !is_numeric ($ tag )) {
507506 $ tag = trim ($ tag );
508507 if ($ tag === '' ) {
@@ -532,6 +531,9 @@ public function tagAs($objid, $tag) {
532531 ]);
533532 return false ;
534533 }
534+ if ($ tag === ITags::TAG_FAVORITE ) {
535+ $ this ->dispatcher ->dispatchTyped (new NodeAddedToFavorite ($ this ->userSession ->getUser (), $ objid , $ path ));
536+ }
535537 return true ;
536538 }
537539
@@ -542,7 +544,7 @@ public function tagAs($objid, $tag) {
542544 * @param string $tag The id or name of the tag
543545 * @return boolean
544546 */
545- public function unTag ($ objid , $ tag ) {
547+ public function unTag ($ objid , $ tag, string $ path = '' ) {
546548 if (is_string ($ tag ) && !is_numeric ($ tag )) {
547549 $ tag = trim ($ tag );
548550 if ($ tag === '' ) {
@@ -569,6 +571,9 @@ public function unTag($objid, $tag) {
569571 ]);
570572 return false ;
571573 }
574+ if ($ tag === ITags::TAG_FAVORITE ) {
575+ $ this ->dispatcher ->dispatchTyped (new NodeRemovedFromFavorite ($ this ->userSession ->getUser (), $ objid , $ path ));
576+ }
572577 return true ;
573578 }
574579
0 commit comments