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
4 changes: 2 additions & 2 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5709,7 +5709,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -5775,7 +5775,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down
51 changes: 21 additions & 30 deletions iOSClient/Data/NCManageDatabase+LivePhoto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,28 @@ extension NCManageDatabase {

// MARK: - Realm Write

func setLivePhotoVideo(metadatas: [tableMetadata]) async {
guard !metadatas.isEmpty else {
return
}

func setLivePhotoVideo(account: String, serverUrlFileName: String, fileId: String, classFile: String) async {
await core.performRealmWriteAsync { realm in
for metadata in metadatas {
let serverUrlFileNameNoExt = (metadata.serverUrlFileName as NSString).deletingPathExtension
let primaryKey = metadata.account + serverUrlFileNameNoExt
if let result = realm.object(ofType: tableLivePhoto.self, forPrimaryKey: primaryKey) {
if metadata.isVideo {
// Update existing (only the provided fields)
result.serverUrlFileNameVideo = metadata.serverUrlFileName
result.fileIdVideo = metadata.fileId
} else if metadata.isImage {
result.serverUrlFileNameImage = metadata.serverUrlFileName
result.fileIdImage = metadata.fileId
}
} else {
// Insert new — ensure the initializer sets the same PK used above
let addObject = tableLivePhoto(account: metadata.account, serverUrlFileNameNoExt: serverUrlFileNameNoExt)
if metadata.isVideo {
addObject.serverUrlFileNameVideo = metadata.serverUrlFileName
addObject.fileIdVideo = metadata.fileId
realm.add(addObject, update: .modified)
} else if metadata.isImage {
addObject.serverUrlFileNameImage = metadata.serverUrlFileName
addObject.fileIdImage = metadata.fileId
realm.add(addObject, update: .modified)
}
}
let serverUrlFileNameNoExt = (serverUrlFileName as NSString).deletingPathExtension
let primaryKey = account + serverUrlFileNameNoExt

let livePhoto: tableLivePhoto
if let existing = realm.object(ofType: tableLivePhoto.self, forPrimaryKey: primaryKey) {
livePhoto = existing
} else {
// Create and add a new entry with the proper primary key
let newObject = tableLivePhoto(account: account, serverUrlFileNameNoExt: serverUrlFileNameNoExt)
realm.add(newObject, update: .modified)
livePhoto = newObject
}

// Update only the relevant fields based on metadata content type
if classFile == NKTypeClassFile.video.rawValue {
livePhoto.serverUrlFileNameVideo = serverUrlFileName
livePhoto.fileIdVideo = fileId
} else if classFile == NKTypeClassFile.image.rawValue {
livePhoto.serverUrlFileNameImage = serverUrlFileName
livePhoto.fileIdImage = fileId
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions iOSClient/Data/NCManageDatabase+Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ extension tableMetadata {
!livePhotoFile.isEmpty
}

var isLivePhotoVideo: Bool {
!livePhotoFile.isEmpty && classFile == NKTypeClassFile.video.rawValue
}

var isLivePhotoImage: Bool {
!livePhotoFile.isEmpty && classFile == NKTypeClassFile.image.rawValue
}

var isNotFlaggedAsLivePhotoByServer: Bool {
!isFlaggedAsLivePhotoByServer
}
Expand Down
16 changes: 11 additions & 5 deletions iOSClient/Data/NCMetadataTranfersSuccess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ actor NCMetadataTranfersSuccess {
private var tranfersSuccess: [tableMetadata] = []
private let utility = NCUtility()

func append(metadata: tableMetadata, ocId: String, date: Date?, etag: String?) {
func append(metadata: tableMetadata, ocId: String, date: Date?, etag: String?) async {
metadata.ocId = ocId
metadata.uploadDate = (date as? NSDate) ?? NSDate()
metadata.etag = etag ?? ""
Expand All @@ -29,6 +29,16 @@ actor NCMetadataTranfersSuccess {
} else {
tranfersSuccess.append(metadata)
}

// Create Live Photo metadata
let capabilities = await NKCapabilities.shared.getCapabilities(for: metadata.account)
if capabilities.isLivePhotoServerAvailable,
metadata.isLivePhoto {
await NCManageDatabase.shared.setLivePhotoVideo(account: metadata.account,
serverUrlFileName: metadata.serverUrlFileName,
fileId: metadata.fileId,
classFile: metadata.classFile)
}
}

func count() -> Int {
Expand Down Expand Up @@ -74,11 +84,7 @@ actor NCMetadataTranfersSuccess {
// Auto Upload
await NCManageDatabase.shared.addAutoUploadTransferAsync(autoUploads)

// Create Live Photo metadatas
await NCManageDatabase.shared.setLivePhotoVideo(metadatas: metadatasLivePhoto)

if !NCNetworking.shared.isInBackground() {

// Set livePhoto on Server
let accounts = Set(metadatasLivePhoto.map { $0.account })
for account in accounts {
Expand Down
7 changes: 3 additions & 4 deletions iOSClient/Networking/NCNetworking+NextcloudKitDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ extension NCNetworking {
serverUrl: String,
session: URLSession,
task: URLSessionTask) {

Task {
guard await progressQuantizer.shouldEmit(serverUrlFileName: serverUrl + "/" + fileName, fraction: Double(progress)) else {
return
Expand Down Expand Up @@ -140,9 +139,9 @@ extension NCNetworking {
if let ocId {
if isInBackground() {
await self.uploadSuccess(withMetadata: metadata,
ocId: ocId,
etag: etag,
date: date)
ocId: ocId,
etag: etag,
date: date)
} else {
#if !EXTENSION
await NCManageDatabase.shared.deleteMetadataAsync(ocId: metadata.ocId)
Expand Down
45 changes: 44 additions & 1 deletion iOSClient/Networking/NCNetworking+Upload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ extension NCNetworking {
await NCManageDatabase.shared.addAutoUploadTransferAsync([tblAutoUpload])
}
if let livePhoto = results.livePhoto {
await NCManageDatabase.shared.setLivePhotoVideo(metadatas: [livePhoto])
await NCManageDatabase.shared.setLivePhotoVideo(account: livePhoto.account,
serverUrlFileName: livePhoto.serverUrlFileName,
fileId: livePhoto.fileId,
classFile: livePhoto.classFile)
#if !EXTENSION
await NCNetworking.shared.setLivePhoto(account: metadata.account)
#endif
Expand Down Expand Up @@ -469,4 +472,44 @@ extension NCNetworking {
return controller
}
#endif

// MARK: - Helper

func helperMetadataSuccess(metadata: tableMetadata) async -> (localFile: tableMetadata?,
livePhoto: tableMetadata?,
autoUpload: tableAutoUploadTransfer?) {
var localFile: tableMetadata?
var livePhoto: tableMetadata?
var autoUpload: tableAutoUploadTransfer?

// File System Local file
let fileNamePath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocIdTransfer, userId: metadata.userId, urlBase: metadata.urlBase)

if metadata.sessionSelector == NCGlobal.shared.selectorUploadFileNODelete {
let fineManeToPath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, userId: metadata.userId, urlBase: metadata.urlBase)
await utilityFileSystem.moveFileAsync(atPath: fileNamePath, toPath: fineManeToPath)
localFile = tableMetadata(value: metadata)
} else {
utilityFileSystem.removeFile(atPath: fileNamePath)
}

// Live Photo
let capabilities = await NKCapabilities.shared.getCapabilities(for: metadata.account)
if capabilities.isLivePhotoServerAvailable,
metadata.isLivePhoto {
livePhoto = tableMetadata(value: metadata)
}

// Auto Upload
if metadata.sessionSelector == self.global.selectorUploadAutoUpload,
let serverUrlBase = metadata.autoUploadServerUrlBase {
autoUpload = tableAutoUploadTransfer(account: metadata.account,
serverUrlBase: serverUrlBase,
fileName: metadata.fileNameView,
assetLocalIdentifier: metadata.assetLocalIdentifier,
date: metadata.creationDate as Date)
}

return (localFile: localFile, livePhoto: livePhoto, autoUpload: autoUpload)
}
}
6 changes: 4 additions & 2 deletions iOSClient/Networking/NCNetworking+WebDAV.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ extension NCNetworking {
}

func deleteFileOrFolder(metadata: tableMetadata) async -> NKError {
let results = await NextcloudKit.shared.deleteFileOrFolderAsync(serverUrlFileName: metadata.serverUrlFileName, account: metadata.account) { task in
var results = await NextcloudKit.shared.deleteFileOrFolderAsync(serverUrlFileName: metadata.serverUrlFileName, account: metadata.account) { task in
Task {
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: metadata.account,
path: metadata.serverUrlFileName,
Expand All @@ -473,7 +473,7 @@ extension NCNetworking {
}
}

if results.error == .success || results.error.errorCode == NCGlobal.shared.errorResourceNotFound {
if results.error == .success || results.error.errorCode == NCGlobal.shared.errorResourceNotFound || (results.error.errorCode == NCGlobal.shared.errorForbidden && metadata.isLivePhotoVideo) {
do {
try FileManager.default.removeItem(atPath: self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, userId: metadata.userId, urlBase: metadata.urlBase))
} catch { }
Expand All @@ -490,6 +490,8 @@ extension NCNetworking {
await NCManageDatabase.shared.deleteDirectoryAndSubDirectoryAsync(serverUrl: serverUrl,
account: metadata.account)
}

results.error = .success
} else {
await NCManageDatabase.shared.setMetadataSessionAsync(ocId: metadata.ocId,
status: global.metadataStatusNormal)
Expand Down
39 changes: 0 additions & 39 deletions iOSClient/Networking/NCNetworking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -437,45 +437,6 @@ class NCNetworking: @unchecked Sendable, NextcloudKitDelegate {
(self.p12Data, self.p12Password) = NCPreferences().getClientCertificate(account: account)
}
#endif
// MARK: - Helper

#if !EXTENSION_FILE_PROVIDER_EXTENSION
func helperMetadataSuccess(metadata: tableMetadata) async -> (localFile: tableMetadata?, livePhoto: tableMetadata?, autoUpload: tableAutoUploadTransfer?) {
var localFile: tableMetadata?
var livePhoto: tableMetadata?
var autoUpload: tableAutoUploadTransfer?

// File System Local file
let fileNamePath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocIdTransfer, userId: metadata.userId, urlBase: metadata.urlBase)

if metadata.sessionSelector == NCGlobal.shared.selectorUploadFileNODelete {
let fineManeToPath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, userId: metadata.userId, urlBase: metadata.urlBase)
await utilityFileSystem.moveFileAsync(atPath: fileNamePath, toPath: fineManeToPath)
localFile = tableMetadata(value: metadata)
} else {
utilityFileSystem.removeFile(atPath: fileNamePath)
}

// Live Photo
let capabilities = await NKCapabilities.shared.getCapabilities(for: metadata.account)
if capabilities.isLivePhotoServerAvailable,
metadata.isLivePhoto {
livePhoto = tableMetadata(value: metadata)
}

// Auto Upload
if metadata.sessionSelector == self.global.selectorUploadAutoUpload,
let serverUrlBase = metadata.autoUploadServerUrlBase {
autoUpload = tableAutoUploadTransfer(account: metadata.account,
serverUrlBase: serverUrlBase,
fileName: metadata.fileNameView,
assetLocalIdentifier: metadata.assetLocalIdentifier,
date: metadata.creationDate as Date)
}

return (localFile: localFile, livePhoto: livePhoto, autoUpload: autoUpload)
}
#endif

#if !EXTENSION
@inline(__always)
Expand Down
3 changes: 3 additions & 0 deletions iOSClient/Networking/NCNetworkingProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@

await runMetadataPipelineAsync(metadatas: metadatas)

// TODO: Check temperature

Check warning on line 204 in iOSClient/Networking/NCNetworkingProcess.swift

View workflow job for this annotation

GitHub Actions / Lint

Todo Violation: TODOs should be resolved (Check temperature) (todo)

if lastUsedInterval != minInterval {
await startTimer(interval: minInterval)
Expand All @@ -210,6 +210,9 @@
// Remove upload asset
await removeUploadedAssetsIfNeeded()

// Set Live Photo
await NCNetworking.shared.setLivePhoto(account: currentAccount)

if lastUsedInterval != maxInterval {
await startTimer(interval: maxInterval)
}
Expand Down
Loading