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

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr.kuznetsov <r.kuznetsov@corp.mail.ru>2017-11-10 14:24:27 +0300
committerArsentiy Milchakov <milcars@mapswithme.com>2017-11-10 14:33:24 +0300
commitdd3ab518b416d5e45f0eaca9f9f9fda47f4f43fe (patch)
treece4d2d0377b1fd88dc5d9fe1d6bb80145a2c4e53
parent9d51002a904c288a7d911377ba2faee21c86d1f5 (diff)
Added user’s reviews filtering
-rw-r--r--android/jni/com/mapswithme/maps/Framework.cpp2
-rw-r--r--iphone/Maps/UI/PlacePage/MWMPlacePageData.mm2
-rw-r--r--map/framework.cpp23
-rw-r--r--map/framework.hpp4
-rw-r--r--map/user.cpp4
-rw-r--r--map/user.hpp1
-rw-r--r--ugc/api.cpp4
-rw-r--r--ugc/api.hpp5
8 files changed, 39 insertions, 6 deletions
diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp
index ec1b6e6a54..ed937d10cc 100644
--- a/android/jni/com/mapswithme/maps/Framework.cpp
+++ b/android/jni/com/mapswithme/maps/Framework.cpp
@@ -584,7 +584,7 @@ void Framework::RequestViatorProducts(JNIEnv * env, jobject policy, std::string
void Framework::RequestUGC(FeatureID const & fid, ugc::Api::UGCCallback const & ugcCallback)
{
- m_work.GetUGCApi()->GetUGC(fid, ugcCallback);
+ m_work.GetUGC(fid, ugcCallback);
}
void Framework::SetUGCUpdate(FeatureID const & fid, ugc::UGCUpdate const & ugc)
diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm
index 38b3ea9f81..c93aa37519 100644
--- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm
+++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm
@@ -119,7 +119,7 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
NSAssert(m_info.ShouldShowUGC(), @"");
__weak auto wself = self;
- GetFramework().GetUGCApi()->GetUGC(
+ GetFramework().GetUGC(
m_info.GetID(), [wself](ugc::UGC const & ugc, ugc::UGCUpdate const & update) {
__strong auto self = wself;
self.ugc = [[MWMUGCViewModel alloc] initWithUGC:ugc update:update];
diff --git a/map/framework.cpp b/map/framework.cpp
index 5223d64195..6d1df75387 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -3338,3 +3338,26 @@ void Framework::UploadUGC(User::CompleteUploadingHandler const & onCompleteUploa
}
});
}
+
+void Framework::GetUGC(FeatureID const & id, ugc::Api::UGCCallback const & callback)
+{
+ m_ugcApi->GetUGC(id, [this, callback](ugc::UGC const & ugc, ugc::UGCUpdate const & update)
+ {
+ ugc::UGC filteredUGC = ugc;
+ filteredUGC.m_reviews = FilterUGCReviews(ugc.m_reviews);
+ callback(filteredUGC, update);
+ });
+}
+
+ugc::Reviews Framework::FilterUGCReviews(ugc::Reviews const & reviews) const
+{
+ ugc::Reviews result;
+ auto const details = m_user.GetDetails();
+ ASSERT(std::is_sorted(details.m_reviewIds.begin(), details.m_reviewIds.end()), ());
+ for (auto const & review : reviews)
+ {
+ if (!std::binary_search(details.m_reviewIds.begin(), details.m_reviewIds.end(), review.m_id))
+ result.push_back(review);
+ }
+ return result;
+}
diff --git a/map/framework.hpp b/map/framework.hpp
index 396079b7ad..8d10a5028e 100644
--- a/map/framework.hpp
+++ b/map/framework.hpp
@@ -816,4 +816,8 @@ private:
public:
// UGC.
void UploadUGC(User::CompleteUploadingHandler const & onCompleteUploading);
+ void GetUGC(FeatureID const & id, ugc::Api::UGCCallback const & callback);
+private:
+ // Filters user's reviews.
+ ugc::Reviews FilterUGCReviews(ugc::Reviews const & reviews) const;
};
diff --git a/map/user.cpp b/map/user.cpp
index 5a695565f0..9f77849c8f 100644
--- a/map/user.cpp
+++ b/map/user.cpp
@@ -143,7 +143,10 @@ void User::Init()
std::string reviewIds;
if (GetPlatform().GetSecureStorage().Load(kReviewIdsKey, reviewIds))
+ {
m_details.m_reviewIds = DeserializeReviewIds(reviewIds);
+ std::sort(m_details.m_reviewIds.begin(), m_details.m_reviewIds.end());
+ }
// Update user details on start up.
auto const status = GetPlatform().ConnectionStatus();
@@ -249,6 +252,7 @@ void User::RequestUserDetails()
GetPlatform().GetSecureStorage().Save(kReviewIdsKey, response);
std::lock_guard<std::mutex> lock(m_mutex);
m_details.m_reviewIds = reviewIds;
+ std::sort(m_details.m_reviewIds.begin(), m_details.m_reviewIds.end());
}
});
});
diff --git a/map/user.hpp b/map/user.hpp
index e730e17173..0c19176c87 100644
--- a/map/user.hpp
+++ b/map/user.hpp
@@ -21,6 +21,7 @@ public:
struct Details
{
using ReviewId = uint64_t;
+ // m_reviewIds must be sorted.
std::vector<ReviewId> m_reviewIds;
};
enum SocialTokenType
diff --git a/ugc/api.cpp b/ugc/api.cpp
index d6b42c4071..65f77af714 100644
--- a/ugc/api.cpp
+++ b/ugc/api.cpp
@@ -14,7 +14,7 @@ Api::Api(Index const & index) : m_storage(index), m_loader(index)
m_thread.Push([this] { m_storage.Load(); });
}
-void Api::GetUGC(FeatureID const & id, UGCCallback const & callback)
+void Api::GetUGC(FeatureID const & id, UGCCallbackUnsafe const & callback)
{
m_thread.Push([=] { GetUGCImpl(id, callback); });
}
@@ -44,7 +44,7 @@ void Api::SaveUGCOnDisk()
m_thread.Push([this] { SaveUGCOnDiskImpl(); });
}
-void Api::GetUGCImpl(FeatureID const & id, UGCCallback const & callback)
+void Api::GetUGCImpl(FeatureID const & id, UGCCallbackUnsafe const & callback)
{
CHECK(callback, ());
if (!id.IsValid())
diff --git a/ugc/api.hpp b/ugc/api.hpp
index b507ac1f95..9af3ef365a 100644
--- a/ugc/api.hpp
+++ b/ugc/api.hpp
@@ -19,12 +19,13 @@ class Api
{
public:
using UGCCallback = platform::SafeCallback<void(UGC const & ugc, UGCUpdate const & update)>;
+ using UGCCallbackUnsafe = std::function<void(UGC const & ugc, UGCUpdate const & update)>;
using UGCJsonToSendCallback = std::function<void(std::string && jsonStr)>;
using OnResultCallback = platform::SafeCallback<void(Storage::SettingResult const result)>;
explicit Api(Index const & index);
- void GetUGC(FeatureID const & id, UGCCallback const & callback);
+ void GetUGC(FeatureID const & id, UGCCallbackUnsafe const & callback);
void SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc,
OnResultCallback const & callback = nullptr);
void GetUGCToSend(UGCJsonToSendCallback const & callback);
@@ -32,7 +33,7 @@ public:
void SaveUGCOnDisk();
private:
- void GetUGCImpl(FeatureID const & id, UGCCallback const & callback);
+ void GetUGCImpl(FeatureID const & id, UGCCallbackUnsafe const & callback);
Storage::SettingResult SetUGCUpdateImpl(FeatureID const & id, UGCUpdate const & ugc);
void GetUGCToSendImpl(UGCJsonToSendCallback const & callback);
void SendingCompletedImpl();