Skip to content
Draft
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
5 changes: 5 additions & 0 deletions apps/files_versions/lib/Sabre/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Plugin extends ServerPlugin {
public const AUTHOR = 'author';
public const VERSION_LABEL = '{http://nextcloud.org/ns}version-label';
public const VERSION_AUTHOR = '{http://nextcloud.org/ns}version-author';
public const VERSION_IS_CURRENT = '{http://nextcloud.org/ns}version-is-current';
private const LEGACY_FILENAME_HEADER_USER_AGENTS = [ // Quirky clients
Request::USER_AGENT_IE,
Request::USER_AGENT_ANDROID_MOBILE_CHROME,
Expand Down Expand Up @@ -101,6 +102,10 @@ public function propFind(PropFind $propFind, INode $node): void {
self::VERSION_AUTHOR,
fn () => $node->getMetadataValue(self::AUTHOR)
);
$propFind->handle(
self::VERSION_IS_CURRENT,
fn (): string => $node->getVersion()->getTimestamp() === $node->getVersion()->getSourceFile()->getMTime() ? 'true' : 'false'
);
$propFind->handle(
FilesPlugin::HAS_PREVIEW_PROPERTYNAME,
fn (): string => $this->previewManager->isMimeSupported($node->getContentType()) ? 'true' : 'false',
Expand Down
1 change: 1 addition & 0 deletions apps/files_versions/src/utils/davRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default `<?xml version="1.0"?>
<d:getetag />
<nc:version-label />
<nc:version-author />
<nc:version-is-current />
<nc:has-preview />
</d:prop>
</d:propfind>`
5 changes: 4 additions & 1 deletion apps/files_versions/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Version {
label: string // 'Current version' or ''
author: string | null // UID for the author of the version
authorName: string | null // Display name of the author
isCurrent: boolean // True if this is the current version
filename: string // File name relative to the version DAV endpoint
basename: string // A base name generated from the mtime
mime: string // Empty for the current version, else the actual mime type of the version
Expand Down Expand Up @@ -98,9 +99,10 @@ export async function restoreVersion(version: Version) {
*/
function formatVersion(version: Required<FileStat>, node: INode): Version {
const mtime = Date.parse(version.lastmod)
const isCurrentVersion = version.props['version-is-current'] === 'true' || mtime === node.mtime?.getTime()

let previewUrl: string
if (mtime === node.mtime?.getTime()) { // Version is the current one
if (isCurrentVersion) {
previewUrl = generateUrl('/core/preview?fileId={fileId}&c={fileEtag}&x=250&y=250&forceIcon=0&a=0&forceIcon=1&mimeFallback=1', {
fileId: node.id,
fileEtag: node.attributes.etag,
Expand All @@ -118,6 +120,7 @@ function formatVersion(version: Required<FileStat>, node: INode): Version {
label: version.props['version-label'] ? String(version.props['version-label']) : '',
author: version.props['version-author'] ? String(version.props['version-author']) : null,
authorName: null,
isCurrent: isCurrentVersion,
filename: version.filename,
basename: new Date(mtime).toLocaleString(
[getCanonicalLocale(), getCanonicalLocale().split('-')[0]!],
Expand Down
6 changes: 2 additions & 4 deletions apps/files_versions/src/views/FilesVersionsSidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
:loadPreview="active"
:version="row.items[0].version"
:node="node"
:isCurrent="row.items[0].version.mtime === currentVersionMtime"
:isCurrent="row.items[0].version.isCurrent"
:isFirstVersion="row.items[0].version.mtime === initialVersionMtime"
@click="openVersion"
@compare="compareVersion"
Expand Down Expand Up @@ -73,8 +73,6 @@ const loading = ref(false)
const showVersionLabelForm = ref(false)
const editedVersion = ref<Version | null>(null)

const currentVersionMtime = computed(() => props.node?.mtime?.getTime() ?? 0)

/**
* Order versions by mtime.
* Put the current version at the top.
Expand Down Expand Up @@ -131,7 +129,7 @@ const canCompare = computed(() => {
// When the id changed we immediately show changes
watch(() => props.node.id, loadVersions, { immediate: true })
// On mtime changes we debounce to prevent too many requests.
watchDebounced(currentVersionMtime, loadVersions, { debounce: 600 })
watchDebounced(() => props.node.mtime?.getTime(), loadVersions, { debounce: 600 })

/**
* Load versions for the current node
Expand Down
Loading