2626namespace OCA \Recommendations \Service ;
2727
2828use OCP \Files \Node ;
29+ use OCP \Files \NotFoundException ;
2930use OCP \Files \StorageNotAvailableException ;
3031use OCP \IL10N ;
3132use OCP \IServerContainer ;
@@ -45,26 +46,61 @@ public function __construct(IServerContainer $serverContainer,
4546 $ this ->l10n = $ l10n ;
4647 }
4748
49+ /**
50+ * @return bool
51+ */
52+ private function isNodeExcluded (Node $ node , bool $ showHidden ): bool {
53+ $ next = $ node ;
54+
55+ while (!$ showHidden ) {
56+ if ($ next ->getName ()[0 ] == ". " )
57+ return true ;
58+
59+ try {
60+ $ next = $ next ->getParent ();
61+ } catch (NotFoundException $ e ) {
62+ break ;
63+ }
64+ }
65+
66+ return false ;
67+ }
68+
4869 /**
4970 * @return array
5071 */
5172 public function getMostRecentRecommendation (IUser $ user , int $ max ): array {
73+ $ showHidden = (bool ) $ this ->serverContainer ->getConfig ()->getUserValue ($ user ->getUID (), 'files ' , 'show_hidden ' , false );
5274 $ userFolder = $ this ->serverContainer ->getUserFolder ($ user ->getUID ());
5375
54- return array_filter (array_map (function (Node $ node ) use ($ userFolder ) {
55- try {
56- return new RecommendedFile (
57- $ userFolder ->getRelativePath ($ node ->getParent ()->getPath ()),
58- $ node ,
59- $ node ->getMTime (),
60- $ this ->l10n ->t ("Recently edited " )
61- );
62- } catch (StorageNotAvailableException $ e ) {
63- return null ;
76+ $ count = 0 ;
77+ $ limit = 2 * $ max ;
78+ $ offset = 0 ;
79+ $ results = [];
80+
81+ do {
82+ $ recentFiles = $ userFolder ->getRecent ($ limit , $ offset );
83+
84+ foreach ($ recentFiles as $ node ) {
85+ if (!$ this ->isNodeExcluded ($ node , $ showHidden )) {
86+ try {
87+ $ results [] = new RecommendedFile (
88+ $ userFolder ->getRelativePath ($ node ->getParent ()->getPath ()),
89+ $ node ,
90+ $ node ->getMTime (),
91+ $ this ->l10n ->t ("Recently edited " )
92+ );
93+ } catch (StorageNotAvailableException $ e ) {
94+ //pass
95+ }
96+ }
6497 }
65- }, $ userFolder ->getRecent ($ max )), function ($ entry ) {
66- return $ entry !== null ;
67- });
98+
99+ $ offset += $ limit ;
100+ $ count ++;
101+ } while ((count ($ results ) < $ max ) && ($ count < 5 ));
102+
103+ return array_slice ($ results , 0 , $ max );
68104 }
69105
70106}
0 commit comments