forked from organicmaps/organicmaps
Add dynamic ugc storage.
This commit is contained in:
parent
a291aa1b62
commit
6e4a15c49e
8 changed files with 39 additions and 15 deletions
|
@ -495,6 +495,7 @@ place_page::Info & Framework::GetPlacePageInfo()
|
|||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
void Framework::RequestBookingMinPrice(JNIEnv * env, jobject policy,
|
||||
string const & hotelId, string const & currencyCode,
|
||||
booking::GetMinPriceCallback const & callback)
|
||||
|
|
|
@ -1459,7 +1459,8 @@ void Framework::InitCountryInfoGetter()
|
|||
void Framework::InitUGC()
|
||||
{
|
||||
ASSERT(!m_ugcApi.get(), ("InitUGC() must be called only once."));
|
||||
m_ugcApi = make_unique<ugc::Api>(m_model.GetIndex());
|
||||
|
||||
m_ugcApi = make_unique<ugc::Api>(m_model.GetIndex(), "FILENAME_PLACEHOLDER");
|
||||
}
|
||||
|
||||
void Framework::InitSearchEngine()
|
||||
|
|
|
@ -804,7 +804,7 @@ public:
|
|||
|
||||
bool CreateMapObject(m2::PointD const & mercator, uint32_t const featureType, osm::EditableMapObject & emo) const;
|
||||
/// @returns false if feature is invalid or can't be edited.
|
||||
bool GetEditableMapObject(FeatureID const & fid, osm:: EditableMapObject & emo) const;
|
||||
bool GetEditableMapObject(FeatureID const & fid, osm::EditableMapObject & emo) const;
|
||||
osm::Editor::SaveResult SaveEditedMapObject(osm::EditableMapObject emo);
|
||||
void DeleteFeature(FeatureID const & fid) const;
|
||||
osm::NewFeatureCategories GetEditorCategories() const;
|
||||
|
|
|
@ -5,6 +5,8 @@ set(
|
|||
api.cpp
|
||||
api.hpp
|
||||
serdes.hpp
|
||||
storage.cpp
|
||||
storage.hpp
|
||||
types.hpp
|
||||
)
|
||||
|
||||
|
|
25
ugc/api.cpp
25
ugc/api.cpp
|
@ -1,15 +1,12 @@
|
|||
#include "ugc/api.hpp"
|
||||
|
||||
#include "indexer/feature_decl.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
using namespace std;
|
||||
using namespace ugc;
|
||||
|
||||
namespace ugc
|
||||
{
|
||||
namespace
|
||||
{
|
||||
chrono::hours FromDays(uint32_t days)
|
||||
|
@ -18,16 +15,23 @@ chrono::hours FromDays(uint32_t days)
|
|||
}
|
||||
} // namespace
|
||||
|
||||
Api::Api(Index const & index) : m_index(index) {}
|
||||
namespace ugc
|
||||
{
|
||||
Api::Api(Index const & index, std::string const & filename) : m_index(index), m_storage(filename) {}
|
||||
|
||||
void Api::GetUGC(FeatureID const & id, UGCCallback callback)
|
||||
{
|
||||
m_thread.Push([=]() { GetUGCImpl(id, callback); });
|
||||
m_thread.Push([=] { GetUGCImpl(id, callback); });
|
||||
}
|
||||
|
||||
void Api::GetUGCUpdate(FeatureID const & id, UGCUpdateCallback callback)
|
||||
{
|
||||
m_thread.Push([=]() { GetUGCUpdateImpl(id, callback); });
|
||||
m_thread.Push([=] { GetUGCUpdateImpl(id, callback); });
|
||||
}
|
||||
|
||||
void Api::SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc)
|
||||
{
|
||||
m_thread.Push([=] { SetUGCUpdate(id, ugc); });
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -86,7 +90,7 @@ void Api::GetUGCImpl(FeatureID const & id, UGCCallback callback)
|
|||
ugc = MakeTestUGC1();
|
||||
else if (r == 2)
|
||||
ugc = MakeTestUGC2();
|
||||
|
||||
|
||||
GetPlatform().RunOnGuiThread([ugc, callback] { callback(ugc); });
|
||||
}
|
||||
|
||||
|
@ -99,4 +103,9 @@ void Api::GetUGCUpdateImpl(FeatureID const & /* id */, UGCUpdateCallback callbac
|
|||
ReviewFeedback({}, {}));
|
||||
GetPlatform().RunOnGuiThread([ugc, callback] { callback(ugc); });
|
||||
}
|
||||
|
||||
void Api::SetUGCUpdateImpl(FeatureID const & id, UGCUpdate const & ugc)
|
||||
{
|
||||
m_storage.SetUGCUpdate(id, ugc);
|
||||
}
|
||||
} // namespace ugc
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "base/worker_thread.hpp"
|
||||
|
||||
#include "ugc/storage.hpp"
|
||||
#include "ugc/types.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
@ -17,11 +18,13 @@ public:
|
|||
using UGCCallback = std::function<void(UGC const &)>;
|
||||
using UGCUpdateCallback = std::function<void(UGCUpdate const &)>;
|
||||
|
||||
explicit Api(Index const & index);
|
||||
explicit Api(Index const & index, std::string const & filename);
|
||||
|
||||
void GetUGC(FeatureID const & id, UGCCallback callback);
|
||||
void GetUGCUpdate(FeatureID const & id, UGCUpdateCallback callback);
|
||||
|
||||
void SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc);
|
||||
|
||||
static UGC MakeTestUGC1();
|
||||
static UGC MakeTestUGC2();
|
||||
|
||||
|
@ -29,7 +32,10 @@ private:
|
|||
void GetUGCImpl(FeatureID const & id, UGCCallback callback);
|
||||
void GetUGCUpdateImpl(FeatureID const & id, UGCUpdateCallback callback);
|
||||
|
||||
void SetUGCUpdateImpl(FeatureID const & id, UGCUpdate const & ugc);
|
||||
|
||||
Index const & m_index;
|
||||
base::WorkerThread m_thread;
|
||||
Storage m_storage;
|
||||
};
|
||||
} // namespace ugc
|
||||
|
|
|
@ -271,25 +271,28 @@ struct UGC
|
|||
|
||||
struct ReviewFeedback
|
||||
{
|
||||
ReviewFeedback() = default;
|
||||
ReviewFeedback(Sentiment const sentiment, Time const & time)
|
||||
: m_sentiment(sentiment), m_time(time)
|
||||
{
|
||||
}
|
||||
|
||||
Sentiment m_sentiment;
|
||||
Time m_time;
|
||||
Sentiment m_sentiment{};
|
||||
Time m_time{};
|
||||
};
|
||||
|
||||
struct ReviewAbuse
|
||||
{
|
||||
ReviewAbuse() = default;
|
||||
ReviewAbuse(std::string const & reason, Time const & time) : m_reason(reason), m_time(time) {}
|
||||
|
||||
std::string m_reason;
|
||||
Time m_time;
|
||||
std::string m_reason{};
|
||||
Time m_time{};
|
||||
};
|
||||
|
||||
struct UGCUpdate
|
||||
{
|
||||
UGCUpdate() = default;
|
||||
UGCUpdate(Rating ratings, Attribute attribute, ReviewAbuse abuses, ReviewFeedback feedbacks)
|
||||
: m_ratings(ratings), m_attribute(attribute), m_abuses(abuses), m_feedbacks(feedbacks)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,9 @@ include($$ROOT_DIR/common.pri)
|
|||
HEADERS += \
|
||||
api.hpp \
|
||||
serdes.hpp \
|
||||
storage.hpp \
|
||||
types.hpp \
|
||||
|
||||
SOURCES += \
|
||||
api.cpp \
|
||||
storage.cpp \
|
||||
|
|
Loading…
Add table
Reference in a new issue