From 4731c9c9a0dfe28ea02b791f71149278e5d22073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= <14975046+skjnldsv@users.noreply.github.com> Date: Thu, 29 Oct 2026 08:08:22 +0100 Subject: [PATCH] feat: recommend recently uploaded files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An upload keeps the mtime it had on the uploader's device, so a file uploaded today could look weeks old. When the upload is newer than the mtime, recommend the file as uploaded, at its upload time. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com> --- README.md | 1 + lib/Service/RecentlyEditedFilesSource.php | 7 +++++-- lib/Service/RecommendationScorer.php | 1 + src/components/RecommendedFile.vue | 3 +++ .../Service/RecentlyEditedFilesSourceTest.php | 21 ++++++++++++++++++- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 64538d6a..69e18998 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Each source suggests up to 7 files, and every reason a file is suggested for add | Frequently opened | `weight_frequently_opened` | 0.2 | | Favorite | `weight_favorite` | 0.2 | | Recently edited | `weight_recently_edited` | 0.1 | +| Recently uploaded | `weight_recently_uploaded` | 0.1 | | Recently shared | `weight_recently_shared` | 0.1 | | Recently commented | `weight_recently_commented` | 0.1 | diff --git a/lib/Service/RecentlyEditedFilesSource.php b/lib/Service/RecentlyEditedFilesSource.php index d5b5349d..9b0f5fa1 100644 --- a/lib/Service/RecentlyEditedFilesSource.php +++ b/lib/Service/RecentlyEditedFilesSource.php @@ -19,6 +19,7 @@ class RecentlyEditedFilesSource implements IRecommendationSource { public const REASON = 'recently-edited'; + public const REASON_UPLOADED = 'recently-uploaded'; public function __construct( private readonly ContainerInterface $serverContainer, @@ -69,11 +70,13 @@ public function getMostRecentRecommendation(IUser $user, int $max): array { if ($parentPath === '' || $parentPath === '.' || $parentPath === '/') { $parentPath = $node->getParent()->getPath(); } + // An upload keeps the mtime it had on the uploader's device + $uploaded = $node->getUploadTime() > $node->getMTime(); $results[] = new RecommendedFile( $userFolder->getRelativePath($parentPath), $node, - $node->getMTime(), - self::REASON, + $uploaded ? $node->getUploadTime() : $node->getMTime(), + $uploaded ? self::REASON_UPLOADED : self::REASON, ); } catch (StorageNotAvailableException $e) { // skip unavailable files diff --git a/lib/Service/RecommendationScorer.php b/lib/Service/RecommendationScorer.php index 45b06c50..2e12d7f5 100644 --- a/lib/Service/RecommendationScorer.php +++ b/lib/Service/RecommendationScorer.php @@ -37,6 +37,7 @@ class RecommendationScorer { FrequentlyOpenedFilesSource::REASON => 0.2, FavoriteFilesSource::REASON => 0.2, RecentlyEditedFilesSource::REASON => 0.1, + RecentlyEditedFilesSource::REASON_UPLOADED => 0.1, RecentlySharedFilesSource::REASON => 0.1, RecentlyCommentedFilesSource::REASON => 0.1, ]; diff --git a/src/components/RecommendedFile.vue b/src/components/RecommendedFile.vue index f7bf1468..4759fc0f 100644 --- a/src/components/RecommendedFile.vue +++ b/src/components/RecommendedFile.vue @@ -118,6 +118,9 @@ const description = computed(() => { if (props.reason === 'recently-edited') { return t('recommendations', 'Last updated {timeAgo}', { timeAgo: formattedTime.value }) } + if (props.reason === 'recently-uploaded') { + return t('recommendations', 'Uploaded {timeAgo}', { timeAgo: formattedTime.value }) + } if (props.reason === 'recently-shared') { return t('recommendations', 'Shared with you {timeAgo}', { timeAgo: formattedTime.value }) } diff --git a/tests/Unit/Service/RecentlyEditedFilesSourceTest.php b/tests/Unit/Service/RecentlyEditedFilesSourceTest.php index 39ee2454..eab03819 100644 --- a/tests/Unit/Service/RecentlyEditedFilesSourceTest.php +++ b/tests/Unit/Service/RecentlyEditedFilesSourceTest.php @@ -77,10 +77,11 @@ public function getUserFolder(string $uid): Folder { /** * Helper to create a mock Node with a specific path and mtime. */ - private function createNodeMock(string $path, int $mtime = 1000): Node&MockObject { + private function createNodeMock(string $path, int $mtime = 1000, int $uploadTime = 0): Node&MockObject { $node = $this->createMock(Node::class); $node->method('getPath')->willReturn($path); $node->method('getMTime')->willReturn($mtime); + $node->method('getUploadTime')->willReturn($uploadTime); // dirname of e.g. "/testuser/files/doc.pdf" → "/testuser/files" $parent = $this->createMock(Folder::class); @@ -117,6 +118,24 @@ public function testNormalFilesAreIncluded(): void { $this->assertSame(RecentlyEditedFilesSource::REASON, $results[0]->getReason()); } + public function testUploadsNewerThanTheirMtimeAreUploaded(): void { + $this->setShowHidden(false); + + $uploaded = $this->createNodeMock('/testuser/files/photo.jpg', 1000, 5000); + $edited = $this->createNodeMock('/testuser/files/notes.md', 3000, 2000); + $this->userFolder->method('getRecent') + ->willReturnCallback(fn (int $limit, int $offset): array => $offset === 0 ? [$uploaded, $edited] : []); + $this->userFolder->method('getRelativePath') + ->willReturnCallback(fn (string $path) => str_replace('/testuser/files', '', $path)); + + $results = $this->source->getMostRecentRecommendation($this->user, 5); + + $this->assertSame( + [[RecentlyEditedFilesSource::REASON_UPLOADED, 5000], [RecentlyEditedFilesSource::REASON, 3000]], + array_map(fn (RecommendedFile $r): array => [$r->getReason(), $r->getTimestamp()], $results), + ); + } + public function testHiddenFilesAreExcludedWhenShowHiddenIsFalse(): void { $this->setShowHidden(false);