Skip to content

[FEATURE REQUEST] Take advantage of the search_min_length capability#4792

Open
nero002 wants to merge 2 commits intoowncloud:masterfrom
nero002:feature/search-min-lenght-capability
Open

[FEATURE REQUEST] Take advantage of the search_min_length capability#4792
nero002 wants to merge 2 commits intoowncloud:masterfrom
nero002:feature/search-min-lenght-capability

Conversation

@nero002
Copy link

@nero002 nero002 commented Mar 4, 2026

Related Issues

App:

  • Add changelog files for the fixed issues in folder changelog/unreleased. More info here
  • Add feature to Release Notes in ReleaseNotesViewModel.kt creating a new ReleaseNote() with String resources (if required)

Description

  • Make files_sharing.search_min_lenght drive the minimum typed characters required before running user/member searches.
  • Apply this to file/folder sharing user search and space member search.
  • Keep the default value at 3 when the capability is not provided.

QA

  1. ./gradlew :owncloudComLibrary:testDebugUnitTest --tests "*CapabilityResponseTest" :owncloudDomain:testDebugUnitTest --tests "*OCCapabilityTest"
  2. ./gradlew :owncloudApp:compileOriginalDebugKotlin
  3. Manual: verify share/member search starts only after the configured capability threshold.
  4. Manual: verify fallback threshold is 3 when capability is absent.
  5. Manual: verify the new release note item appears in the What's New screen.

@CLAassistant
Copy link

CLAassistant commented Mar 4, 2026

CLA assistant check
All committers have signed the CLA.

@nero002
Copy link
Author

nero002 commented Mar 4, 2026

@jesmrec can you please review

@jesmrec
Copy link
Collaborator

jesmrec commented Mar 4, 2026

@nero002 first of all thanks for your contribution. @joragua will review your code and give you feedback and change proposals, after that, i will review it in terms of QA. Keep tuned.

@joragua joragua linked an issue Mar 4, 2026 that may be closed by this pull request
10 tasks
@joragua joragua changed the title Enhancement: make share search minimum length capability-driven [FEATURE REQUEST] Take advantage of the search_min_lenght capability Mar 4, 2026
Copy link
Collaborator

@joragua joragua left a comment

Choose a reason for hiding this comment

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

Good job @nero002! 💯 Some comments here. Let us know if you have any questions about them!

NOTE 1: Just for you to know, we use underscores for the name branch (feature/search_min_lenght_capability). Do not remove the branch, but keep in mind for future PRs 😄

NOTE 2: Be careful with the names. The correct spelling is length, not lenght

class AddMemberFragment: Fragment(), SearchMembersAdapter.SearchMembersAdapterListener {
private var _binding: AddMemberFragmentBinding? = null
private val binding get() = _binding!!
private val getStoredCapabilitiesUseCase: GetStoredCapabilitiesUseCase by inject()
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you inject a use case directly into the fragment, we are not following the Clean Architecture. In these cases, we use the ViewModels, which contain the methods that execute the use cases.

In this case, if you want to run getStoredCapabilitiesUseCase you would need to use the CapabilityViewModel in the fragment (or create a new method in SpaceMembersViewModel that runs that use case)

private val capabilityViewModel: CapabilityViewModel by viewModel {
        parametersOf(
            requireArguments().getString(ARG_ACCOUNT_NAME)
        )
}

Let us know if you have any questions about the app architecture 😄

Comment on lines +61 to +65
ReleaseNote(
title = R.string.release_notes_4_8_0_title_search_minimum_length,
subtitle = R.string.release_notes_4_8_0_subtitle_search_minimum_length,
type = ReleaseNoteType.ENHANCEMENT
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Release note not needed in this case 😄

Comment on lines +110 to +114
if (newText.length >= minimumSearchLength) {
spaceMembersViewModel.searchMembers(newText)
} else {
spaceMembersViewModel.clearSearch()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would not use more than line of code for this block. My suggestion:

if (newText.length >= minimumSearchLength) { spaceMembersViewModel.searchMembers(newText) } else { spaceMembersViewModel.clearSearch() }

Comment on lines +134 to +140
private fun initSearchMinLength() {
val accountName = requireArguments().getString(ARG_ACCOUNT_NAME) ?: return
minimumSearchLength = getStoredCapabilitiesUseCase(
GetStoredCapabilitiesUseCase.Params(accountName = accountName)
)?.getFilesSharingSearchMinLength() ?: OCCapability.DEFAULT_FILES_SHARING_SEARCH_MIN_LENGTH
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Based on the comment above about Clean Architecture, this method is not longer needed. Instead, you must run the ViewModel method

public static final String CAPABILITIES_SHARING_PUBLIC_MULTIPLE = "sharing_public_multiple";
public static final String CAPABILITIES_SHARING_PUBLIC_SUPPORTS_UPLOAD_ONLY = "supports_upload_only";
public static final String CAPABILITIES_SHARING_RESHARING = "sharing_resharing";
public static final String CAPABILITIES_SHARING_SEARCH_MIN_LENGTH = "search_min_length";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not needed. db/ProviderMeta.java is deprecated as it belongs to the old database

Comment on lines +80 to +81
filesSharingSearchMinLength = capabilities?.fileSharingCapabilities?.fileSharingSearchMinLenght
?: capabilities?.fileSharingCapabilities?.fileSharingSearchMinLength,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it OK? The same code appears before and after ?:

capabilities?.fileSharingCapabilities?.fileSharingSearchMinLenght ?: capabilities?.fileSharingCapabilities?.fileSharingSearchMinLength

@Json(name = "search_min_lenght")
val fileSharingSearchMinLenght: Int?,
@Json(name = "search_min_length")
val fileSharingSearchMinLength: Int?,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Duplicated fields? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Unit tests for response objects are not maintained at this moment in the project. In the future, we will have to discuss about them but right now we only create unit tests for datasources and repositories. So, you can remove this file 😄

Comment on lines +73 to +79
fun getFilesSharingSearchMinLength(): Int =
filesSharingSearchMinLength?.takeIf { it > 0 } ?: DEFAULT_FILES_SHARING_SEARCH_MIN_LENGTH

companion object {
const val DEFAULT_FILES_SHARING_SEARCH_MIN_LENGTH = 3
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't set a default value for filesSharingSearchMinLenght in the model (OCCapability) when it's null, because we are losing some information that comes from the server. Instead, I would handle this in the fragment after observing the capabilities. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The same for these tests. We are not maintaining tests for model classes. We have to discuss about them - you can remove the tests from OCCapabilityTest.kt 👍🏻

@joragua joragua changed the title [FEATURE REQUEST] Take advantage of the search_min_lenght capability [FEATURE REQUEST] Take advantage of the search_min_lenght capability Mar 10, 2026
@joragua joragua changed the title [FEATURE REQUEST] Take advantage of the search_min_lenght capability [FEATURE REQUEST] Take advantage of the search_min_lenght capability Mar 10, 2026
Comment on lines +138 to +143
val minSearchLength = capabilities?.getFilesSharingSearchMinLength()
?: OCCapability.DEFAULT_FILES_SHARING_SEARCH_MIN_LENGTH

if (userQuery.length < minSearchLength) {
return MatrixCursor(COLUMNS)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could yo try to refactor this? Detekt workflow (link) is failing in the CI system because the method searchUsersAndGroups exceeds 100 lines

@joragua joragua changed the title [FEATURE REQUEST] Take advantage of the search_min_lenght capability [FEATURE REQUEST] Take advantage of the search_min_length capability Mar 10, 2026
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.

[FEATURE REQUEST] Take advantage of the search_min_length capability

4 participants