Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
7 changes: 5 additions & 2 deletions lib/Service/RecentlyEditedFilesSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/Service/RecommendationScorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
Expand Down
3 changes: 3 additions & 0 deletions src/components/RecommendedFile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
21 changes: 20 additions & 1 deletion tests/Unit/Service/RecentlyEditedFilesSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
Loading