From 55994c44ff00a053e6ab87e0a73285a156bf5a01 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Thu, 6 Aug 2026 07:49:32 +0200 Subject: [PATCH 1/3] fix: initialize media data source before searching Signed-off-by: Marino Faggiana --- iOSClient/Media/NCMedia.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index 1f0f21a836..a7627d1031 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -180,6 +180,10 @@ class NCMedia: UIViewController { pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinchGesture(_:))) collectionView.addGestureRecognizer(pinchGesture) + Task { + await loadDataSource() + } + NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: global.notificationCenterChangeUser), object: nil, queue: nil) { [weak self] notification in guard let self else { return @@ -247,7 +251,7 @@ class NCMedia: UIViewController { return } - await self.loadDataSource() + self.searchNewMedia() guard !Task.isCancelled else { return @@ -263,8 +267,6 @@ class NCMedia: UIViewController { super.viewDidAppear(animated) NotificationCenter.default.addObserver(self, selector: #selector(enterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) - - searchNewMedia() } override func viewDidDisappear(_ animated: Bool) { From 592b40f1bc82cb6d956f143a8fc7985afcd2fc4d Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Thu, 6 Aug 2026 08:32:18 +0200 Subject: [PATCH 2/3] fix: avoid redundant media collection reloads Signed-off-by: Marino Faggiana --- iOSClient/Media/NCMediaDataSource.swift | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/iOSClient/Media/NCMediaDataSource.swift b/iOSClient/Media/NCMediaDataSource.swift index 332d23f8a7..0c24a8e4c4 100644 --- a/iOSClient/Media/NCMediaDataSource.swift +++ b/iOSClient/Media/NCMediaDataSource.swift @@ -84,6 +84,10 @@ extension NCMedia { return } + guard !self.dataSource.hasSameContent(as: dataSource) else { + return + } + self.dataSource = dataSource self.collectionViewReloadData() } @@ -729,6 +733,26 @@ public class NCMediaDataSource: NSObject { // MARK: - + func hasSameContent(as otherDataSource: NCMediaDataSource) -> Bool { + guard compactMetadatas.count == otherDataSource.compactMetadatas.count else { + return false + } + + for (currentMetadata, otherMetadata) in zip( + compactMetadatas, + otherDataSource.compactMetadatas + ) { + guard currentMetadata.ocId == otherMetadata.ocId, + currentMetadata.etag == otherMetadata.etag, + currentMetadata.date == otherMetadata.date, + currentMetadata.isLivePhoto == otherMetadata.isLivePhoto else { + return false + } + } + + return true + } + func clearCompactMetadatas() { compactMetadatas.removeAll() sections.removeAll() From a49d5e4aac99ac2fe47df5231e85f7ef60398478 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Thu, 6 Aug 2026 10:48:57 +0200 Subject: [PATCH 3/3] fix: force media reload after directory changes Signed-off-by: Marino Faggiana --- iOSClient/Media/NCMedia.swift | 1 + iOSClient/Media/NCMediaDataSource.swift | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index a7627d1031..5c5f63ad6f 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -200,6 +200,7 @@ class NCMedia: UIViewController { self.dataSource.clearCompactMetadatas() self.setTitleDate() + await self.loadDataSource(forced: true) await self.searchMediaUI(true) } } diff --git a/iOSClient/Media/NCMediaDataSource.swift b/iOSClient/Media/NCMediaDataSource.swift index 0c24a8e4c4..89e3ad1294 100644 --- a/iOSClient/Media/NCMediaDataSource.swift +++ b/iOSClient/Media/NCMediaDataSource.swift @@ -7,7 +7,7 @@ import NextcloudKit import RealmSwift extension NCMedia { - func loadDataSource() async { + func loadDataSource(forced: Bool = false) async { let account = self.session.account guard !Task.isCancelled else { @@ -56,10 +56,12 @@ extension NCMedia { } let shouldContinue = await MainActor.run { - self.isViewActived && - self.session.account == account && - self.view.window != nil && - self.tabBarController?.selectedViewController === self.navigationController + forced || ( + self.isViewActived && + self.session.account == account && + self.view.window != nil && + self.tabBarController?.selectedViewController === self.navigationController + ) } guard shouldContinue, @@ -77,10 +79,12 @@ extension NCMedia { await MainActor.run { guard !Task.isCancelled, - self.isViewActived, - self.session.account == account, - self.view.window != nil, - self.tabBarController?.selectedViewController === self.navigationController else { + forced || ( + self.isViewActived && + self.session.account == account && + self.view.window != nil && + self.tabBarController?.selectedViewController === self.navigationController + ) else { return }