@@ -1408,6 +1408,99 @@ public function createSharePermissionDefaultValue(Share $share, string $permissi
14081408 );
14091409 }
14101410
1411+ #[\Override]
1412+ public function getRecipientsForUser (
1413+ ShareUser $ user ,
1414+ ?array $ filterRecipientTypeClasses = null ,
1415+ ?string $ notInShare = null ,
1416+ ?int $ count = 5 ,
1417+ ?ShareRecipient $ after = null ,
1418+ ): array {
1419+ $ query = $ this ->connection ->getTypedQueryBuilder ();
1420+ $ query ->select ('recipient_class_id ' , 'recipient_value ' , 'recipient_instance ' , 'initiator_user_id ' , 'initiator_user_id ' )
1421+ ->selectAlias ('count(*) ' , 'count ' )
1422+ ->from ('sharing_share_recipients ' , 'r ' )
1423+ ->innerJoin ('r ' , 'sharing_share ' , 's ' , $ query ->expr ()->eq ('r.share_id ' , 's.id ' ))
1424+ ->where (
1425+ $ query ->expr ()->orX ([
1426+ $ query ->expr ()->andX ([
1427+ $ query ->expr ()->eq ('s.owner_user_id ' , $ query ->createNamedParameter ($ user ->userId )),
1428+ $ query ->expr ()->eq ('s.owner_instance ' , $ query ->createNamedParameter ($ user ->instance )),
1429+ ]),
1430+ $ query ->expr ()->andX ([
1431+ $ query ->expr ()->eq ('r.initiator_user_id ' , $ query ->createNamedParameter ($ user ->userId )),
1432+ $ query ->expr ()->eq ('r.initiator_instance ' , $ query ->createNamedParameter ($ user ->instance )),
1433+ ]),
1434+ ])
1435+ )
1436+ ->groupBy ('r.* ' )
1437+ ->orderBy ('count ' , \SortDirection::Descending)
1438+ // sort by recipient to get a stable output, and allow "after" to be deterministic
1439+ ->addOrderBy (
1440+ 'recipient_instance ' , \SortDirection::Ascending
1441+ )
1442+ ->addOrderBy (
1443+ 'recipient_value ' , \SortDirection::Ascending
1444+ )
1445+ ->addOrderBy ('recipient_class_id ' , \SortDirection::Ascending);
1446+
1447+ if ($ filterRecipientTypeClasses ) {
1448+ $ query = $ query ->andWhere (
1449+ $ query ->expr ()->in ('recipient_class_id ' , $ query ->createNamedParameter ($ filterRecipientTypeClasses , IQueryBuilder::PARAM_STR_ARRAY ))
1450+ );
1451+ }
1452+
1453+ if ($ notInShare ) {
1454+ $ fullRecipientId = $ query ->func ()->concat ('r.recipient_class_id ' , 'recipient_instance ' , 'recipient_value ' );
1455+
1456+ $ subQuery = $ this ->connection ->getTypedQueryBuilder ();
1457+ $ subQuery ->selectAlias ($ fullRecipientId , 'recipient ' )
1458+ ->from ('sharing_share_recipients ' )
1459+ ->where ($ query ->expr ()->eq ('share_id ' , $ query ->createNamedParameter ($ notInShare )));
1460+
1461+ $ query = $ query ->having (
1462+ $ query ->expr ()->notIn (
1463+ $ fullRecipientId ,
1464+ $ query ->createFunction ('( ' . $ subQuery ->getSQL () . ') ' )
1465+ )
1466+ );
1467+ }
1468+
1469+ if ($ count ) {
1470+ $ query ->setMaxResults ($ count );
1471+ }
1472+
1473+ if ($ after ) {
1474+ $ query = $ query ->andWhere (
1475+ $ query ->expr ()->orX ([
1476+ $ query ->expr ()->andX ([
1477+ $ query ->expr ()->eq ('s.recipient_instance ' , $ query ->createNamedParameter ($ after ->instance )),
1478+ $ query ->expr ()->eq ('s.recipient_value ' , $ query ->createNamedParameter ($ user ->userId )),
1479+ $ query ->expr ()->gt ('s.recipient_class_id ' , $ query ->createNamedParameter ($ user ->userId )),
1480+ ]),
1481+ $ query ->expr ()->andX ([
1482+ $ query ->expr ()->eq ('s.recipient_instance ' , $ query ->createNamedParameter ($ after ->instance )),
1483+ $ query ->expr ()->gt ('s.recipient_value ' , $ query ->createNamedParameter ($ user ->userId )),
1484+ ]),
1485+ $ query ->expr ()->gt ('s.recipient_instance ' , $ query ->createNamedParameter ($ after ->instance )),
1486+ ])
1487+ );
1488+ }
1489+
1490+ $ rows = $ query ->executeQuery ()->fetchAll ();
1491+
1492+ return array_map (fn (array $ row ) => new ShareRecipient (
1493+ $ row ['recipient_class_id ' ],
1494+ $ row ['recipient_value ' ],
1495+ $ row ['recipient_instance ' ],
1496+ null ,
1497+ new ShareUser (
1498+ $ row ['initiator_user_id ' ],
1499+ $ row ['initiator_instance ' ],
1500+ )
1501+ ), $ rows );
1502+ }
1503+
14111504 private static function parseTimestamp (string $ timestampMs ): \DateTimeImmutable {
14121505 if (method_exists (\DateTimeImmutable::class, 'createFromTimestamp ' )) {
14131506 // with php 8.3 the method doesn't exist and psalm doesn't know the return type
0 commit comments