From 4eda5949567114b1b76c9a635851f9ecb27985a0 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Thu, 22 Nov 2018 09:03:23 +0100 Subject: [PATCH] Adds custom loader for the panel --- include/bat/ledger/ledger_client.h | 2 + src/bat_get_media.cc | 2 +- src/bat_publishers.cc | 63 ++++++++++++++++++------------ src/ledger_impl.cc | 7 ++++ src/ledger_impl.h | 2 + 5 files changed, 51 insertions(+), 25 deletions(-) diff --git a/include/bat/ledger/ledger_client.h b/include/bat/ledger/ledger_client.h index 8981eb8..2040c50 100644 --- a/include/bat/ledger/ledger_client.h +++ b/include/bat/ledger/ledger_client.h @@ -95,6 +95,8 @@ class LEDGER_EXPORT LedgerClient { PublisherInfoCallback callback) = 0; virtual void LoadActivityInfo(ActivityInfoFilter filter, PublisherInfoCallback callback) = 0; + virtual void LoadPanelPublisherInfo(ActivityInfoFilter filter, + PublisherInfoCallback callback) = 0; virtual void LoadMediaPublisherInfo(const std::string& media_key, PublisherInfoCallback callback) = 0; virtual void SaveMediaPublisherInfo(const std::string& media_key, diff --git a/src/bat_get_media.cc b/src/bat_get_media.cc index 5dd60c6..c9cecf1 100644 --- a/src/bat_get_media.cc +++ b/src/bat_get_media.cc @@ -654,7 +654,7 @@ void BatGetMedia::fetchPublisherDataFromDB(uint64_t windowId, ledger::EXCLUDE_FILTER::FILTER_ALL, false, ledger_->GetReconcileStamp()); - ledger_->GetActivityInfo(filter, + ledger_->GetPanelPublisherInfo(filter, std::bind(&BatGetMedia::onFetchPublisherFromDBResponse, this, _1, _2, windowId, visit_data, providerType, publisher_key)); } diff --git a/src/bat_publishers.cc b/src/bat_publishers.cc index 19a7beb..7a00436 100644 --- a/src/bat_publishers.cc +++ b/src/bat_publishers.cc @@ -96,7 +96,7 @@ void onVisitSavedDummy(ledger::Result result, void BatPublishers::saveVisit(const std::string& publisher_id, const ledger::VisitData& visit_data, const uint64_t& duration) { - if (!saveVisitAllowed() || publisher_id.empty()) { + if (!ledger_->GetRewardsMainEnabled() || publisher_id.empty()) { return; } @@ -228,34 +228,50 @@ void BatPublishers::saveVisitInternal( visit_data.local_year)); } - if (!ignoreMinTime(publisher_id) && duration < getPublisherMinVisitTime()) { - duration = 0; - } - publisher_info->favicon_url = visit_data.favicon_url; publisher_info->name = visit_data.name; publisher_info->provider = visit_data.provider; publisher_info->url = visit_data.url; - publisher_info->visits += 1; - if (!isExcluded(publisher_info->id, publisher_info->excluded)) { - publisher_info->duration += duration; - } else { + publisher_info->verified = isVerified(publisher_info->id); + + bool excluded = isExcluded(publisher_info->id, publisher_info->excluded); + bool ignore_time = ignoreMinTime(publisher_id); + if (duration == 0) { + ignore_time = false; + } + std::unique_ptr panel_info = nullptr; + + if (excluded) { publisher_info->excluded = ledger::PUBLISHER_EXCLUDE::EXCLUDED; - if (new_visit) { - publisher_info->duration = 0; // don't log auto-excluded - } } - publisher_info->score += concaveScore(duration); - publisher_info->verified = isVerified(publisher_info->id); - publisher_info->reconcile_stamp = ledger_->GetReconcileStamp(); - auto media_info = std::make_unique(*publisher_info); + // for new visits that are excluded or are not long enough or ac is off + if (new_visit && + (excluded || + !saveVisitAllowed() || + (duration < getPublisherMinVisitTime() && + !ignore_time))) { + panel_info = std::make_unique(*publisher_info); + ledger_->SetPublisherInfo(std::move(publisher_info), + std::bind(&onVisitSavedDummy, _1, _2)); + } else if (!excluded && + saveVisitAllowed() && + (duration > getPublisherMinVisitTime() || ignore_time)) { + publisher_info->visits += 1; + publisher_info->duration += duration; + publisher_info->score += concaveScore(duration); + publisher_info->reconcile_stamp = ledger_->GetReconcileStamp(); - ledger_->SetActivityInfo(std::move(publisher_info), - std::bind(&onVisitSavedDummy, _1, _2)); + panel_info = std::make_unique(*publisher_info); + ledger_->SetActivityInfo(std::move(publisher_info), + std::bind(&onVisitSavedDummy, _1, _2)); + } - if (window_id > 0) { - onPublisherActivity(ledger::Result::LEDGER_OK, std::move(media_info), window_id, visit_data); + if (panel_info && window_id > 0) { + onPublisherActivity(ledger::Result::LEDGER_OK, + std::move(panel_info), + window_id, + visit_data); } } @@ -384,9 +400,8 @@ void BatPublishers::OnRestorePublishersInternal(bool success) { setNumExcludedSites(0); OnExcludedSitesChanged(); } else { - ledger_->Log(__func__, - ledger::LogLevel::LOG_ERROR, - {"Could not restore publishers."}); + BLOG(ledger_, ledger::LogLevel::LOG_ERROR) << + "Could not restore publishers."; } } @@ -778,7 +793,7 @@ void BatPublishers::getPublisherActivityFromUrl(uint64_t windowId, const ledger: new_data.url = visit_data.url; new_data.favicon_url = ""; - ledger_->GetActivityInfo(filter, + ledger_->GetPanelPublisherInfo(filter, std::bind(&BatPublishers::onPublisherActivity, this, _1, _2, windowId, new_data)); } diff --git a/src/ledger_impl.cc b/src/ledger_impl.cc index 1022a68..855903a 100644 --- a/src/ledger_impl.cc +++ b/src/ledger_impl.cc @@ -383,6 +383,13 @@ void LedgerImpl::GetActivityInfo( ledger_client_->LoadActivityInfo(filter, callback); } + +void LedgerImpl::GetPanelPublisherInfo( + const ledger::ActivityInfoFilter& filter, + ledger::PublisherInfoCallback callback) { + ledger_client_->LoadPanelPublisherInfo(filter, callback); +} + void LedgerImpl::GetMediaPublisherInfo(const std::string& media_key, ledger::PublisherInfoCallback callback) { ledger_client_->LoadMediaPublisherInfo(media_key, callback); diff --git a/src/ledger_impl.h b/src/ledger_impl.h index cf8a29f..3cffd9c 100644 --- a/src/ledger_impl.h +++ b/src/ledger_impl.h @@ -65,6 +65,8 @@ class LedgerImpl : public ledger::Ledger, ledger::PublisherInfoCallback callback) override; void GetActivityInfo(const ledger::ActivityInfoFilter& filter, ledger::PublisherInfoCallback callback) override; + void GetPanelPublisherInfo(const ledger::ActivityInfoFilter& filter, + ledger::PublisherInfoCallback callback); void GetMediaPublisherInfo(const std::string& media_key, ledger::PublisherInfoCallback callback) override; void SetMediaPublisherInfo(const std::string& media_key,