Skip to content

Auto-index shared folders on share event (up to a configurable file limit) #1318

Description

@chrischris616

Summary

When a user shares a folder containing audio files with another user, the receiving user's music library is not automatically updated. The current code in ShareHooks::itemShared() explicitly skips folder shares and only handles individual file shares:

// Do not auto-update database when a folder is shared. The folder might contain
// thousands of audio files, and indexing them could take minutes or hours.
if ($params['itemType'] === 'file' && $params['shareType'] == self::SHARE_TYPE_USER) {

The receiving user must manually trigger a library rescan to see the shared music.

Problem

This creates a confusing experience: a user shares their Music folder → the recipient opens the Music app → nothing appears → no clear indication why.

Proposed Solution

Extend itemShared() to also handle folder shares, with a configurable upper limit on the number of audio files (default: 500). Folders exceeding the limit fall back to the existing behavior (user prompted to rescan manually).

} elseif ($params['itemType'] === 'folder') {
    $audioFiles = $sharedFolder->searchByMime('audio');
    if (count($audioFiles) <= $configuredLimit) {
        // auto-index each file for the receiving user
    }
    // else: prompt user to rescan (existing behavior)
}

Benefits

  • Shared music folders appear immediately in the recipient's library
  • No impact on large libraries (> 500 files → existing behavior)
  • Backward compatible

Notes

  • The itemUnshared path already correctly handles folders (removeSharedItem with itemType === 'folder'), so the asymmetry between share and unshare is resolved
  • The configurable limit could be exposed via admin_settings or occ config:app:set music shared_folder_auto_scan_limit

Environment

  • Nextcloud Music: 3.0.0
  • Nextcloud: 32.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions