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

api.cpp « ugc - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7ef72cc9ed70a11ccc55aca191f0a0137a43b7fb (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "ugc/api.hpp"

#include "platform/platform.hpp"

#include <chrono>

using namespace std;
using namespace ugc;

namespace ugc
{
namespace
{
Time FromDaysAgo(Time time, uint32_t days)
{
  return time - std::chrono::hours(days * 24);
}
}  // namespace

Api::Api(std::string const & filename) : m_storage(filename) {}

void Api::GetUGC(FeatureID const & id, UGCCallback callback)
{
  m_thread.Push([=] { GetUGCImpl(id, callback); });
}

void Api::GetUGCUpdate(FeatureID const & id, UGCUpdateCallback callback)
{
  m_thread.Push([=] { GetUGCUpdateImpl(id, callback); });
}

void Api::SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc)
{
  m_thread.Push([=] { SetUGCUpdate(id, ugc); });
}

// static
UGC Api::MakeTestUGC1(Time now)
{
  Rating rating;
  rating.m_ratings.emplace_back("food" /* key */, 4.0 /* value */);
  rating.m_ratings.emplace_back("service" /* key */, 5.0 /* value */);
  rating.m_ratings.emplace_back("music" /* key */, 5.0 /* value */);
  rating.m_aggValue = 4.5;

  vector<Review> reviews;
  reviews.emplace_back(20 /* id */, Text("Damn good coffee", StringUtf8Multilang::kEnglishCode),
                       Author(UID(987654321 /* hi */, 123456789 /* lo */), "Cole"),
                       5.0 /* rating */, Sentiment::Positive, FromDaysAgo(now, 10));
  reviews.emplace_back(67812 /* id */,
                       Text("Clean place, reasonably priced", StringUtf8Multilang::kDefaultCode),
                       Author(UID(0 /* hi */, 315 /* lo */), "Cooper"), 5.0 /* rating */,
                       Sentiment::Positive, FromDaysAgo(now, 1));

  vector<Attribute> attributes;
  attributes.emplace_back("best-drink", "Coffee");

  return UGC(rating, reviews, attributes);
}

// static
UGC Api::MakeTestUGC2(Time now)
{
  Rating rating;
  rating.m_ratings.emplace_back("food" /* key */, 5.0 /* value */);
  rating.m_ratings.emplace_back("service" /* key */, 5.0 /* value */);
  rating.m_ratings.emplace_back("music" /* key */, 5.0 /* value */);
  rating.m_aggValue = 5.0;

  vector<Review> reviews;
  reviews.emplace_back(119 /* id */,
                       Text("This pie's so good it is a crime", StringUtf8Multilang::kDefaultCode),
                       Author(UID(0 /* hi */, 315 /* lo */), "Cooper"), 5.0 /* rating */,
                       Sentiment::Positive, FromDaysAgo(now, 1));

  vector<Attribute> attributes;
  attributes.emplace_back("best-drink", "Coffee");
  attributes.emplace_back("best-meal", "Cherry Pie");

  return UGC(rating, reviews, attributes);
}

void Api::GetUGCImpl(FeatureID const & id, UGCCallback callback)
{
  // TODO (@y, @mgsergio): retrieve static UGC
  UGC ugc(Rating({}, {}), {}, {});

  if (!id.IsValid())
  {
    GetPlatform().RunOnGuiThread([ugc, callback] { callback(ugc); });
    return;
  }

  ugc = MakeTestUGC1();

  GetPlatform().RunOnGuiThread([ugc, callback] { callback(ugc); });
}

void Api::GetUGCUpdateImpl(FeatureID const & /* id */, UGCUpdateCallback callback)
{
  // TODO (@y, @mgsergio): retrieve dynamic UGC
  UGCUpdate ugc(Rating({}, {}),
                Attribute({}, {}),
                ReviewAbuse({}, {}),
                ReviewFeedback({}, {}));
  GetPlatform().RunOnGuiThread([ugc, callback] { callback(ugc); });
}

void Api::SetUGCUpdateImpl(FeatureID const & id, UGCUpdate const & ugc)
{
  m_storage.SetUGCUpdate(id, ugc);
}
}  // namespace ugc