export function addVersionCompatibilityToFilters()

in src/amo/searchUtils.js [43:93]


export function addVersionCompatibilityToFilters({
  filters,
  userAgentInfo,
} = {}) {
  invariant(filters, 'filters are required');
  invariant(userAgentInfo, 'userAgentInfo is required');

  const newFilters = { ...filters };

  // If the browser is Firefox or Firefox for Android and we're searching for
  // extensions, send the appversion param to get extensions marked as
  // compatible with this version.
  if (
    userAgentInfo.browser.name === 'Firefox' &&
    userAgentInfo.os.name !== USER_AGENT_OS_IOS
  ) {
    const browserVersion = parseInt(userAgentInfo.browser.version, 10);

    log.debug(oneLine`Setting "compatibleWithVersion" to current application
      version (Firefox ${browserVersion}) so only relevant extensions are
      displayed.`);
    newFilters.compatibleWithVersion = userAgentInfo.browser.version;
  }

  // This adds a filter to return only Android compatible add-ons. We cannot
  // add this fix to `fixFiltersForClientApp()` because we need to override
  // `newFilters.compatibleWithVersion`.
  if (newFilters.clientApp === CLIENT_APP_ANDROID) {
    // On Android, we only have extensions.
    log.debug(oneLine`Setting "addonType" to "extension" for Android.`);
    newFilters.addonType = ADDON_TYPE_EXTENSION;

    // If the browser is not Firefox for Android, we want to filter out
    // extensions to only the limited set, so we force-set the value of
    // `compatibleWithVersion`. This should be removed after General
    // Avaibility.
    //
    // This will apply even to Firefox Desktop browsing Android pages.
    if (
      userAgentInfo.browser.name !== 'Firefox' ||
      userAgentInfo.os.name !== USER_AGENT_OS_ANDROID
    ) {
      log.debug(oneLine`Setting "compatibleWithVersion" to
          "${APPVERSION_FOR_ANDROID}" for Android because the browser is not
          Firefox for Android.`);
      newFilters.compatibleWithVersion = APPVERSION_FOR_ANDROID;
    }
  }

  return newFilters;
}