Skip to content
Merged
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
8 changes: 4 additions & 4 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5784,7 +5784,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 0;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
Expand Down Expand Up @@ -5812,7 +5812,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 33.0.5;
MARKETING_VERSION = 33.0.6;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = "";
Expand Down Expand Up @@ -5852,7 +5852,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 0;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = NKUJUXUJ3B;
Expand All @@ -5878,7 +5878,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 33.0.5;
MARKETING_VERSION = 33.0.6;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = "";
Expand Down
48 changes: 27 additions & 21 deletions iOSClient/Data/NCManageDatabase+Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -340,34 +340,50 @@ extension tableMetadata {
CGSize(width: width, height: height)
}

var tagNames: [String] {
tags.map(\.name)
}

/// Returns false if the user is lokced out of the file. I.e. The file is locked but by somone else
func canUnlock(as user: String) -> Bool {
return !lock || (lockOwner == user && lockOwnerType == 0)
}

/// Returns a detached (unmanaged) deep copy of the current `tableMetadata` object.
///
/// - Note: Primitive list properties (e.g., `shareType`) are copied automatically by `init(value:)`.
/// For `List` containing Realm objects (e.g., `exifPhotos`, `tags`) this method creates new instances
/// to ensure the copy is fully detached and safe to use outside of a Realm context.
/// - Note: Primitive properties and lists of primitive values (for example `shareType`)
/// are copied automatically by `init(value:)`.
/// For `List` properties containing Realm objects (for example `exifPhotos` and `tags`),
/// this method recreates each element explicitly to ensure the resulting copy is fully
/// detached and safe to use across Realm contexts.
///
/// - Returns: A new `tableMetadata` instance fully detached from Realm.
func detachedCopy() -> tableMetadata {
// Use Realm's built-in copy constructor for primitive properties and List of primitives
// Use Realm's built-in copy constructor for primitive properties and lists of primitive values.
let detached = tableMetadata(value: self)

// Deep copy of List of Realm objects (exifPhotos and tags)
// Deep copy of List of Realm objects
detached.exifPhotos.removeAll()
detached.exifPhotos.append(objectsIn: self.exifPhotos.map { NCKeyValue(value: $0) })
detached.exifPhotos.append(objectsIn: self.exifPhotos.map {
let copy = NCKeyValue()
copy.key = $0.key
copy.value = $0.value
return copy
})

detached.tags.removeAll()
detached.tags.append(objectsIn: self.tags.map { tableMetadataTag(value: $0) })
detached.tags.append(objectsIn: self.tags.map {
let copy = tableMetadataTag()
copy.primaryKey = $0.primaryKey
copy.account = $0.account
copy.id = $0.id
copy.name = $0.name
copy.color = $0.color
return copy
})

return detached
}

var tagNames: [String] {
tags.map(\.name)
}
}

extension NCManageDatabase {
Expand Down Expand Up @@ -474,16 +490,6 @@ extension NCManageDatabase {
}
}

func addMetadataIfNotExistsAsync(_ metadata: tableMetadata) async {
let detached = metadata.detachedCopy()

await core.performRealmWriteAsync { realm in
if realm.object(ofType: tableMetadata.self, forPrimaryKey: metadata.ocId) == nil {
realm.add(detached)
}
}
}

func deleteMetadataAsync(predicate: NSPredicate) async {
await core.performRealmWriteAsync { realm in
let result = realm.objects(tableMetadata.self)
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Networking/NCNetworking+Recommendations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension NCNetworking {

if results.error == .success, let file = results.files?.first {
let metadata = await NCManageDatabaseCreateMetadata().convertFileToMetadataAsync(file)
await NCManageDatabase.shared.addMetadataIfNotExistsAsync(metadata)
await NCManageDatabase.shared.addMetadataAsync(metadata)

if metadata.isLivePhoto, metadata.isVideo {
continue
Expand Down
Loading