Welcome to mirror list, hosted at ThFree Co, Russian Federation.

catalog_headers_provider.cpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4d16b2c79eb286beaf698850861e215542f5c758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "map/catalog_headers_provider.hpp"

#include "map/bookmark_manager.hpp"

#include <random>
#include <set>

CatalogHeadersProvider::CatalogHeadersProvider(PositionProvider const & positionProvider,
                                               storage::Storage const & storage)
  : m_positionProvider(positionProvider)
  , m_storage(storage)
{
}

void CatalogHeadersProvider::SetBookmarkManager(BookmarkManager const * bookmarkManager)
{
  ASSERT(bookmarkManager != nullptr, ());

  m_bookmarkManager = bookmarkManager;
}

platform::HttpClient::Headers CatalogHeadersProvider::GetHeaders()
{
  web_api::HeadersParams params;
  params.m_currentPosition = m_positionProvider.GetCurrentPosition();

  storage::CountriesVec localMaps;
  m_storage.GetLocalRealMaps(localMaps);
  auto const & countryToCity = m_storage.GetMwmTopCityGeoIds();
  std::set<base::GeoObjectId> countries;
  auto & cities = params.m_cityGeoIds;
  for (auto const & id : localMaps)
  {
    auto const countryIds = m_storage.GetTopCountryGeoIds(id);
    countries.insert(countryIds.cbegin(), countryIds.cend());

    auto const cityIt = countryToCity.find(id);
    if (cityIt != countryToCity.cend())
      cities.push_back(cityIt->second);
  }
  params.m_countryGeoIds.assign(countries.cbegin(), countries.cend());

  auto ids = m_bookmarkManager->GetAllPaidCategoriesIds();
  if (m_bookmarkManager != nullptr && !ids.empty())
  {
    size_t constexpr kMaxCountOfGuides = 30;
    if (ids.size() > kMaxCountOfGuides)
    {
      static std::mt19937 generator(std::random_device{}());
      std::shuffle(ids.begin(), ids.end(), generator);
      ids.resize(kMaxCountOfGuides);
    }
    params.m_downloadedGuidesIds = std::move(ids);
  }

  return web_api::GetCatalogHeaders(params);
}

std::optional<platform::HttpClient::Header> CatalogHeadersProvider::GetPositionHeader()
{
  if (!m_positionProvider.GetCurrentPosition())
    return {};

  return web_api::GetPositionHeader(*m_positionProvider.GetCurrentPosition());
}