Skip to content

fix: make photo editing available from the viewer menu - #4411

Open
mvanhorn wants to merge 4 commits into
nextcloud:masterfrom
mvanhorn:fix/4332-photo-viewer-edit-action
Open

mvanhorn wants to merge 4 commits into
nextcloud:masterfrom
mvanhorn:fix/4332-photo-viewer-edit-action

Conversation

@mvanhorn

Copy link
Copy Markdown

While viewing a photo, the overflow menu has no way to edit it. Editing appears only from the file context menu, and only for some photos, under the label Modify. The viewer menu added that item only when the full image file was already on the device, so a photo that was only previewed or not yet downloaded was left out. Activating the item always notified transfer delegates that the file had already downloaded, using the Quick Look load selector. The title was the Modify string.

The viewer menu now shows Edit for an image Quick Look can modify when the device is online or the file is already stored locally, and the file context menu uses that same Edit title. A file already on the device still opens through the downloaded-file notification; otherwise, while online, the photo is marked for download with the Quick Look selector and the download is started. Unit tests check that an online preview-only image offers one Edit action and that building the menu leaves it undownloaded, and that a web view, a non-image, and an encrypted photo offer none. The new test file is included in the unit test target.

Tests for the ios NCContextMenuMain: change live in Tests/NextcloudUnitTests/NCContextMenuViewerTests.swift.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (N/A)

AI was used for assistance.

Fixes #4332

The viewer menu now shows Edit for an image Quick Look can modify when
the device is online or the file is already stored locally, and the file
context menu uses that same Edit title. A file already on the device
still opens through the downloaded-file notification; otherwise, while
online, the photo is marked for download with the Quick Look selector
and the download is started. Unit tests check that an online
preview-only image offers one Edit action and that building the menu
leaves it undownloaded, and that a web view, a non-image, and an
encrypted photo offer none. The new test file is included in the unit
test target.

Fixes nextcloud#4332

Assisted-by: AI
Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
…ewer-edit-action

Signed-off-by: Matt Van Horn <mvanhorn@gmail.com>
@marinofaggiana

Copy link
Copy Markdown
Member

Thanks, Matt. Showing Edit for photos that only have a preview makes sense. I’d like to address two issues before merging.

  • Isolate each Quick Look session. A pending download can finish while another photo is being edited. Creating the second editor resets the shared hasChangesQuickLook flag, so the first editor can lose its save prompt. If the files have the same name, the second editor also overwrites the temporary file the first one will upload. Please give each editor its own change flag and a unique temporary file.
  • Keep the download tied to the Edit request. If Info is already downloading the original, tapping Edit resets the transfer state and can start a second download to the same path. Please reuse the in-flight download and open Quick Look only if the originating viewer is still showing that photo when it completes.

Could you add regression coverage for these cases? The current tests verify whether Edit appears in the menu. The regressions above happen after the tap.

@marinofaggiana marinofaggiana left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read my consideration

Each Quick Look editor now owns its change flag, so opening a second
editor no longer clears the first one's save prompt. Editors also get a
temporary copy in their own directory, keeping the file name, so two
photos with the same name never overwrite the file the other uploads.
The download-then-open code moved into NCViewerQuickLook.presentEditor,
which the Quick Look transfer selector now uses as well.

Edit from the media viewer goes through the viewer's loader. The loader
shares a download that is already running for the same photo, so Edit
while Info downloads the original neither resets the transfer state nor
starts a second download to the same path. Quick Look opens only if the
viewer is still on screen and showing that photo when the download ends.

New unit tests cover separate change flags, separate temporary files
for same-name photos, joining a running download, and not opening the
editor after the viewer moved on, closed, or the download failed.

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 23:25
@mvanhorn

Copy link
Copy Markdown
Author

Thanks @marinofaggiana, both are addressed in 8ce96c7.

Isolated Quick Look sessions: hasChangesQuickLook is now an instance property of NCViewerQuickLook, so opening a second editor no longer clears the first one's save prompt. Each editor also gets its own temporary copy from NCViewerQuickLook.makeEditingFileURL, which keeps the file name inside a per-session directory, so two photos with the same name never overwrite each other's upload. The Quick Look transfer selector in NCNetworking+TransferDelegate.swift now goes through the same presentEditor path.

Download tied to the Edit request: Edit from the media viewer now goes through the viewer's loader, which shares a download already running for the same photo (NCInFlightTaskRegistry in NCNextcloudMediaViewerLoader.swift). Tapping Edit while Info is downloading the original joins that transfer instead of resetting it or starting a second download to the same path, and Quick Look opens only if the originating viewer is still on screen and showing that photo when the download completes.

Regression coverage is in NCViewerPhotoEditTests: separate change flags per editor, separate temporary files for same-name photos, joining a running download, and not opening the editor after the viewer moved to another photo, closed, or the download failed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved issues allow stale photo editors to be presented, queued downloads to continue after cancellation, and full-resolution temporary image copies to accumulate without cleanup.

3 open issues
What changed in this PR

This PR addresses #4332 by making photo editing available from the viewer’s overflow menu, including eligible photos whose originals are not yet downloaded.

Changes:

  • Uses the Edit label in both viewer and file context menus.
  • Adds viewer-aware editing, shared downloads, and isolated Quick Look editing sessions.
  • Adds unit tests for menu eligibility, download sharing, and editing-session behavior.
File Description
Tests/​NextcloudUnitTests/​NCViewerPhotoEditTests.swift Tests session isolation, shared downloads, and viewer-validity checks.
Tests/​NextcloudUnitTests/​NCContextMenuViewerTests.swift Tests Edit availability and side-effect-free menu creation.
Tests/​NextcloudUnitTests/​MockViewerPhotoEditSource.swift Provides a controllable viewer and download mock.
Nextcloud.xcodeproj/​project.pbxproj Registers the new tests and mock in the unit test target.
iOSClient/​Viewer/​NCViewerQuickLook/​NCViewerQuickLook.swift Isolates editing state and temporary files; centralizes editor presentation.
iOSClient/​Viewer/​NCViewerMedia/​NCNextcloudMediaViewerLoader.swift Shares in-flight original-file downloads.
iOSClient/​Viewer/​NCViewerMedia/​NCMediaViewerHostingController.swift Connects the media viewer to the editing flow.
iOSClient/​Networking/​NCNetworking+TransferDelegate.swift Uses the shared editor-presentation helper.
iOSClient/​Menu/​NCContextMenuViewer.swift Adds eligible Edit actions and viewer-aware download handling.
iOSClient/​Menu/​NCContextMenuMain.swift Renames the file context menu action to Edit.

Review effort: Balanced

Comment on lines +304 to +305
let current = await NCManageDatabase.shared.getMetadataFromOcIdAsync(metadata.ocId) ?? metadata
NCViewerQuickLook.presentEditor(metadata: current, from: controller)
Comment on lines +316 to +318
let directory = temporaryDirectory.appendingPathComponent("QuickLookEdit-" + UUID().uuidString, isDirectory: true)
do {
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
The shared download ran in an unstructured task, so cancelling the viewer
while it waited for a transfer slot left it queued. Each caller now
registers on the shared operation; when the last one is cancelled the
operation is cancelled too. cancelDownload(for:) and cancelAllDownloads()
also cancel queued shared operations.

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
@mvanhorn
mvanhorn force-pushed the fix/4332-photo-viewer-edit-action branch from 0923dc8 to b0a1f4c Compare November 11, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modify action only shown in context menu

3 participants