Skip to content

Commit f551a2b

Browse files
feat: set creation_time on file creation and render recently created icon
Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
1 parent 79d4953 commit f551a2b

8 files changed

Lines changed: 129 additions & 5 deletions

File tree

apps/dav/lib/Files/FileSearchBackend.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function getPropertyDefinitionsForScope(string $href, ?string $path): arr
8686
new SearchPropertyDefinition('{DAV:}displayname', true, true, true),
8787
new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
8888
new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
89+
new SearchPropertyDefinition('{http://nextcloud.org/ns}creation_time', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
8990
new SearchPropertyDefinition('{http://nextcloud.org/ns}upload_time', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
9091
new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
9192
new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN),
@@ -299,6 +300,8 @@ private function getSearchResultProperty(SearchResult $result, SearchPropertyDef
299300
return $node->getName();
300301
case '{DAV:}getlastmodified':
301302
return $node->getLastModified();
303+
case '{http://nextcloud.org/ns}creation_time':
304+
return $node->getNode()->getCreationTime();
302305
case '{http://nextcloud.org/ns}upload_time':
303306
return $node->getNode()->getUploadTime();
304307
case FilesPlugin::SIZE_PROPERTYNAME:
@@ -461,6 +464,8 @@ private function mapPropertyNameToColumn(SearchPropertyDefinition $property) {
461464
return 'mimetype';
462465
case '{DAV:}getlastmodified':
463466
return 'mtime';
467+
case '{http://nextcloud.org/ns}creation_time':
468+
return 'creation_time';
464469
case '{http://nextcloud.org/ns}upload_time':
465470
return 'upload_time';
466471
case FilesPlugin::SIZE_PROPERTYNAME:

apps/files/src/components/FileEntry/FileEntryPreview.vue

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
<FavoriteIcon v-once />
4343
</span>
4444

45+
<!-- Recently created icon -->
46+
<span v-else-if="isRecentView && isRecentlyCreated" class="files-list__row-icon-recently-created">
47+
<RecentlyCreatedIcon v-once />
48+
</span>
49+
4550
<component
4651
:is="fileOverlay"
4752
v-if="fileOverlay"
@@ -71,6 +76,7 @@ import PlayCircleIcon from 'vue-material-design-icons/PlayCircle.vue'
7176
import TagIcon from 'vue-material-design-icons/Tag.vue'
7277
import CollectivesIcon from './CollectivesIcon.vue'
7378
import FavoriteIcon from './FavoriteIcon.vue'
79+
import RecentlyCreatedIcon from './RecentlyCreatedIcon.vue'
7480
import { usePreviewImage } from '../../composables/usePreviewImage.ts'
7581
import logger from '../../logger.ts'
7682
import { isLivePhoto } from '../../services/LivePhotos.ts'
@@ -91,6 +97,7 @@ export default defineComponent({
9197
LinkIcon,
9298
NetworkIcon,
9399
TagIcon,
100+
RecentlyCreatedIcon,
94101
},
95102
96103
props: {
@@ -138,6 +145,29 @@ export default defineComponent({
138145
return this.source.attributes.favorite === 1
139146
},
140147
148+
isRecentlyCreated(): boolean {
149+
if (this.source.attributes.upload_time) {
150+
return false
151+
}
152+
153+
const creationDate = this.source.attributes.creationdate
154+
? new Date(this.source.attributes.creationdate)
155+
: null
156+
157+
if (!creationDate) {
158+
return false
159+
}
160+
161+
const oneDayAgo = new Date()
162+
oneDayAgo.setDate(oneDayAgo.getDate() - 1)
163+
164+
return creationDate > oneDayAgo
165+
},
166+
167+
isRecentView(): boolean {
168+
return this.$route?.params?.view === 'recent'
169+
},
170+
141171
userConfig(): UserConfig {
142172
return this.userConfigStore.userConfig
143173
},
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<!--
2+
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
- SPDX-License-Identifier: AGPL-3.0-or-later
4+
-->
5+
<template>
6+
<NcIconSvgWrapper class="recently-created-marker-icon" :name="t('files', 'Recently created')" :svg="PlusSvg" />
7+
</template>
8+
9+
<script lang="ts">
10+
import PlusSvg from '@mdi/svg/svg/plus.svg?raw'
11+
import { translate as t } from '@nextcloud/l10n'
12+
import { defineComponent } from 'vue'
13+
import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
14+
15+
/**
16+
* A recently created icon to be used for overlaying recently created entries like the file preview / icon
17+
* It has a stroke around the icon to ensure enough contrast for accessibility.
18+
*
19+
* If the background has a hover state you might want to also apply it to the stroke like this:
20+
* ```scss
21+
* .parent:hover :deep(.favorite-marker-icon svg path) {
22+
* stroke: var(--color-background-hover);
23+
* }
24+
* ```
25+
*/
26+
export default defineComponent({
27+
name: 'RecentlyCreatedIcon',
28+
components: {
29+
NcIconSvgWrapper,
30+
},
31+
32+
data() {
33+
return {
34+
PlusSvg,
35+
}
36+
},
37+
38+
async mounted() {
39+
await this.$nextTick()
40+
// MDI default viewBox is "0 0 24 24" but we add a stroke of 10px so we must adjust it
41+
const el = this.$el.querySelector('svg')
42+
el?.setAttribute?.('viewBox', '-4 -4 30 30')
43+
},
44+
45+
methods: {
46+
t,
47+
},
48+
})
49+
</script>
50+
51+
<style lang="scss" scoped>
52+
.recently-created-marker-icon {
53+
color: var(--color-element-success);
54+
// Override NcIconSvgWrapper defaults (clickable area)
55+
min-width: unset !important;
56+
min-height: unset !important;
57+
58+
:deep() {
59+
svg {
60+
// We added a stroke for a11y so we must increase the size to include the stroke
61+
width: 20px !important;
62+
height: 20px !important;
63+
64+
// Override NcIconSvgWrapper defaults of 20px
65+
max-width: unset !important;
66+
max-height: unset !important;
67+
68+
// Show a border around the icon for better contrast
69+
path {
70+
stroke: var(--color-main-background);
71+
stroke-width: 8px;
72+
stroke-linejoin: round;
73+
paint-order: stroke;
74+
}
75+
}
76+
}
77+
}
78+
</style>

apps/files/src/components/FilesListVirtual.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ export default defineComponent({
743743
& > span {
744744
justify-content: flex-start;
745745
746-
&:not(.files-list__row-icon-favorite) svg {
746+
&:not(.files-list__row-icon-favorite):not(.files-list__row-icon-recently-created) svg {
747747
width: var(--icon-preview-size);
748748
height: var(--icon-preview-size);
749749
}
@@ -791,7 +791,8 @@ export default defineComponent({
791791
}
792792
}
793793
794-
&-favorite {
794+
&-favorite,
795+
&-recently-created {
795796
position: absolute;
796797
top: 0px;
797798
inset-inline-end: -10px;
@@ -993,8 +994,9 @@ export default defineComponent({
993994
}
994995
}
995996
996-
// Star icon in the top right
997-
.files-list__row-icon-favorite {
997+
// Icon in the top right
998+
.files-list__row-icon-favorite,
999+
.files-list__row-icon-recently-created {
9981000
position: absolute;
9991001
top: 0;
10001002
inset-inline-end: 0;

lib/private/Files/Cache/Cache.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ public function getFolderContentsById(int $fileId, ?string $mimeTypeFilter = nul
250250
* @throws \RuntimeException
251251
*/
252252
public function put($file, array $data) {
253+
// do not carry over creation_time to file versions, as each new version would otherwise
254+
// create a filecache_extended entry with the same creation_time as the original file
255+
if (str_starts_with($file, 'files_versions/')) {
256+
unset($data['creation_time']);
257+
}
258+
253259
if (($id = $this->getId($file)) > -1) {
254260
$this->update($id, $data);
255261
return $id;

lib/private/Files/Cache/QuerySearchHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array
153153

154154
$requestedFields = $this->searchBuilder->extractRequestedFields($searchQuery->getSearchOperation());
155155

156-
$joinExtendedCache = in_array('upload_time', $requestedFields);
156+
$joinExtendedCache = in_array('creation_time', $requestedFields) || in_array('upload_time', $requestedFields);
157157

158158
$query = $builder->selectFileCache('file', $joinExtendedCache);
159159

lib/private/Files/Cache/SearchBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class SearchBuilder {
6464
'share_with' => 'string',
6565
'share_type' => 'integer',
6666
'owner' => 'string',
67+
'creation_time' => 'integer',
6768
'upload_time' => 'integer',
6869
];
6970

@@ -258,6 +259,7 @@ private function validateComparison(ISearchComparison $operator) {
258259
'share_with' => ['eq'],
259260
'share_type' => ['eq'],
260261
'owner' => ['eq'],
262+
'creation_time' => ['eq', 'gt', 'lt', 'gte', 'lte'],
261263
'upload_time' => ['eq', 'gt', 'lt', 'gte', 'lte'],
262264
];
263265

lib/private/Files/Node/Folder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public function newFile($path, $content = null) {
175175
throw new NotPermittedException('Could not create path "' . $fullPath . '"');
176176
}
177177
$node = new File($this->root, $this->view, $fullPath, null, $this);
178+
$this->view->putFileInfo($fullPath, ['creation_time' => time()]);
178179
$this->sendHooks(['postWrite', 'postCreate'], [$node]);
179180
return $node;
180181
}

0 commit comments

Comments
 (0)