Skip to content

Commit a699eed

Browse files
feat(recent-files): add nc:last_activity property to allow sorting by max between upload_time and mtime
Signed-off-by: Cristian Scheid <cristianscheid@gmail.com> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
1 parent fbeb6ba commit a699eed

13 files changed

Lines changed: 41 additions & 10 deletions

File tree

apps/dav/lib/Capabilities.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
}
2121

2222
/**
23-
* @return array{dav: array{chunking: string, public_shares_chunking: bool, search_supports_creation_time: bool, search_supports_upload_time: bool, bulkupload?: string, absence-supported?: bool, absence-replacement?: bool}}
23+
* @return array{dav: array{chunking: string, public_shares_chunking: bool, search_supports_creation_time: bool, search_supports_upload_time: bool, search_supports_last_activity: bool, bulkupload?: string, absence-supported?: bool, absence-replacement?: bool}}
2424
*/
2525
public function getCapabilities() {
2626
$capabilities = [
@@ -29,6 +29,7 @@ public function getCapabilities() {
2929
'public_shares_chunking' => true,
3030
'search_supports_creation_time' => true,
3131
'search_supports_upload_time' => true,
32+
'search_supports_last_activity' => true,
3233
]
3334
];
3435
if ($this->config->getSystemValueBool('bulkupload.enabled', true)) {

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class FilesPlugin extends ServerPlugin {
6868
public const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag';
6969
public const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
7070
public const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
71+
public const LAST_ACTIVITY_PROPERTYNAME = '{http://nextcloud.org/ns}last_activity';
7172
public const SHARE_NOTE = '{http://nextcloud.org/ns}note';
7273
public const SHARE_HIDE_DOWNLOAD_PROPERTYNAME = '{http://nextcloud.org/ns}hide-download';
7374
public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count';
@@ -437,6 +438,11 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
437438
return $node->getFileInfo()->getCreationTime();
438439
});
439440

441+
$propFind->handle(self::LAST_ACTIVITY_PROPERTYNAME, function () use ($node) {
442+
$fileInfo = $node->getFileInfo();
443+
return max($fileInfo->getUploadTime(), $fileInfo->getMTime());
444+
});
445+
440446
foreach ($node->getFileInfo()->getMetadata() as $metadataKey => $metadataValue) {
441447
$propFind->handle(self::FILE_METADATA_PREFIX . $metadataKey, $metadataValue);
442448
}

apps/dav/lib/Files/FileSearchBackend.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function getPropertyDefinitionsForScope(string $href, ?string $path): arr
8888
new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
8989
new SearchPropertyDefinition('{DAV:}creationdate', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
9090
new SearchPropertyDefinition('{http://nextcloud.org/ns}upload_time', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
91+
new SearchPropertyDefinition('{http://nextcloud.org/ns}last_activity', true, false, true, SearchPropertyDefinition::DATATYPE_DATETIME),
9192
new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
9293
new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN),
9394
new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
@@ -304,6 +305,8 @@ private function getSearchResultProperty(SearchResult $result, SearchPropertyDef
304305
return $node->getNode()->getCreationTime();
305306
case '{http://nextcloud.org/ns}upload_time':
306307
return $node->getNode()->getUploadTime();
308+
case '{http://nextcloud.org/ns}last_activity':
309+
return max($node->getNode()->getUploadTime(), $node->getNode()->getMTime());
307310
case FilesPlugin::SIZE_PROPERTYNAME:
308311
return $node->getSize();
309312
case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
@@ -332,6 +335,8 @@ private function transformQuery(Query $query, ?SearchBinaryOperator $scopeOperat
332335
$direction = $order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING;
333336
if (str_starts_with($order->property->name, FilesPlugin::FILE_METADATA_PREFIX)) {
334337
return new SearchOrder($direction, substr($order->property->name, strlen(FilesPlugin::FILE_METADATA_PREFIX)), IMetadataQuery::EXTRA);
338+
} elseif ($order->property->name === FilesPlugin::LAST_ACTIVITY_PROPERTYNAME) {
339+
return new SearchOrder($direction, 'last_activity');
335340
} else {
336341
return new SearchOrder($direction, $this->mapPropertyNameToColumn($order->property));
337342
}

apps/dav/openapi.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"chunking",
3333
"public_shares_chunking",
3434
"search_supports_creation_time",
35-
"search_supports_upload_time"
35+
"search_supports_upload_time",
36+
"search_supports_last_activity"
3637
],
3738
"properties": {
3839
"chunking": {
@@ -47,6 +48,9 @@
4748
"search_supports_upload_time": {
4849
"type": "boolean"
4950
},
51+
"search_supports_last_activity": {
52+
"type": "boolean"
53+
},
5054
"bulkupload": {
5155
"type": "string"
5256
},

apps/dav/tests/unit/CapabilitiesTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function testGetCapabilities(): void {
3333
'public_shares_chunking' => true,
3434
'search_supports_creation_time' => true,
3535
'search_supports_upload_time' => true,
36+
'search_supports_last_activity' => true,
3637
],
3738
];
3839
$this->assertSame($expected, $capabilities->getCapabilities());
@@ -55,6 +56,7 @@ public function testGetCapabilitiesWithBulkUpload(): void {
5556
'public_shares_chunking' => true,
5657
'search_supports_creation_time' => true,
5758
'search_supports_upload_time' => true,
59+
'search_supports_last_activity' => true,
5860
'bulkupload' => '1.0',
5961
],
6062
];
@@ -78,6 +80,7 @@ public function testGetCapabilitiesWithAbsence(): void {
7880
'public_shares_chunking' => true,
7981
'search_supports_creation_time' => true,
8082
'search_supports_upload_time' => true,
83+
'search_supports_last_activity' => true,
8184
'absence-supported' => true,
8285
'absence-replacement' => true,
8386
],

apps/files/src/services/Recent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function getContents(path = '/', options: { signal: AbortSignal }):
4141
const contentsResponse = await client.search('/', {
4242
signal: options.signal,
4343
details: true,
44-
data: getRecentSearch(lastTwoWeeksTimestamp, store.userConfig.recent_files_limit),
44+
data: getRecentSearch(lastTwoWeeksTimestamp, store.userConfig.recent_files_limit + 1),
4545
}) as ResponseDataDetailed<SearchResult>
4646

4747
const contents = contentsResponse.data.results

dist/files-init.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)