Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit 4eda594

Browse files
committed
Adds custom loader for the panel
1 parent fde913e commit 4eda594

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed

include/bat/ledger/ledger_client.h

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class LEDGER_EXPORT LedgerClient {
9595
PublisherInfoCallback callback) = 0;
9696
virtual void LoadActivityInfo(ActivityInfoFilter filter,
9797
PublisherInfoCallback callback) = 0;
98+
virtual void LoadPanelPublisherInfo(ActivityInfoFilter filter,
99+
PublisherInfoCallback callback) = 0;
98100
virtual void LoadMediaPublisherInfo(const std::string& media_key,
99101
PublisherInfoCallback callback) = 0;
100102
virtual void SaveMediaPublisherInfo(const std::string& media_key,

src/bat_get_media.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ void BatGetMedia::fetchPublisherDataFromDB(uint64_t windowId,
654654
ledger::EXCLUDE_FILTER::FILTER_ALL,
655655
false,
656656
ledger_->GetReconcileStamp());
657-
ledger_->GetActivityInfo(filter,
657+
ledger_->GetPanelPublisherInfo(filter,
658658
std::bind(&BatGetMedia::onFetchPublisherFromDBResponse,
659659
this, _1, _2, windowId, visit_data, providerType, publisher_key));
660660
}

src/bat_publishers.cc

+39-24
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void onVisitSavedDummy(ledger::Result result,
9696
void BatPublishers::saveVisit(const std::string& publisher_id,
9797
const ledger::VisitData& visit_data,
9898
const uint64_t& duration) {
99-
if (!saveVisitAllowed() || publisher_id.empty()) {
99+
if (!ledger_->GetRewardsMainEnabled() || publisher_id.empty()) {
100100
return;
101101
}
102102

@@ -228,34 +228,50 @@ void BatPublishers::saveVisitInternal(
228228
visit_data.local_year));
229229
}
230230

231-
if (!ignoreMinTime(publisher_id) && duration < getPublisherMinVisitTime()) {
232-
duration = 0;
233-
}
234-
235231
publisher_info->favicon_url = visit_data.favicon_url;
236232
publisher_info->name = visit_data.name;
237233
publisher_info->provider = visit_data.provider;
238234
publisher_info->url = visit_data.url;
239-
publisher_info->visits += 1;
240-
if (!isExcluded(publisher_info->id, publisher_info->excluded)) {
241-
publisher_info->duration += duration;
242-
} else {
235+
publisher_info->verified = isVerified(publisher_info->id);
236+
237+
bool excluded = isExcluded(publisher_info->id, publisher_info->excluded);
238+
bool ignore_time = ignoreMinTime(publisher_id);
239+
if (duration == 0) {
240+
ignore_time = false;
241+
}
242+
std::unique_ptr<ledger::PublisherInfo> panel_info = nullptr;
243+
244+
if (excluded) {
243245
publisher_info->excluded = ledger::PUBLISHER_EXCLUDE::EXCLUDED;
244-
if (new_visit) {
245-
publisher_info->duration = 0; // don't log auto-excluded
246-
}
247246
}
248-
publisher_info->score += concaveScore(duration);
249-
publisher_info->verified = isVerified(publisher_info->id);
250-
publisher_info->reconcile_stamp = ledger_->GetReconcileStamp();
251247

252-
auto media_info = std::make_unique<ledger::PublisherInfo>(*publisher_info);
248+
// for new visits that are excluded or are not long enough or ac is off
249+
if (new_visit &&
250+
(excluded ||
251+
!saveVisitAllowed() ||
252+
(duration < getPublisherMinVisitTime() &&
253+
!ignore_time))) {
254+
panel_info = std::make_unique<ledger::PublisherInfo>(*publisher_info);
255+
ledger_->SetPublisherInfo(std::move(publisher_info),
256+
std::bind(&onVisitSavedDummy, _1, _2));
257+
} else if (!excluded &&
258+
saveVisitAllowed() &&
259+
(duration > getPublisherMinVisitTime() || ignore_time)) {
260+
publisher_info->visits += 1;
261+
publisher_info->duration += duration;
262+
publisher_info->score += concaveScore(duration);
263+
publisher_info->reconcile_stamp = ledger_->GetReconcileStamp();
253264

254-
ledger_->SetActivityInfo(std::move(publisher_info),
255-
std::bind(&onVisitSavedDummy, _1, _2));
265+
panel_info = std::make_unique<ledger::PublisherInfo>(*publisher_info);
266+
ledger_->SetActivityInfo(std::move(publisher_info),
267+
std::bind(&onVisitSavedDummy, _1, _2));
268+
}
256269

257-
if (window_id > 0) {
258-
onPublisherActivity(ledger::Result::LEDGER_OK, std::move(media_info), window_id, visit_data);
270+
if (panel_info && window_id > 0) {
271+
onPublisherActivity(ledger::Result::LEDGER_OK,
272+
std::move(panel_info),
273+
window_id,
274+
visit_data);
259275
}
260276
}
261277

@@ -384,9 +400,8 @@ void BatPublishers::OnRestorePublishersInternal(bool success) {
384400
setNumExcludedSites(0);
385401
OnExcludedSitesChanged();
386402
} else {
387-
ledger_->Log(__func__,
388-
ledger::LogLevel::LOG_ERROR,
389-
{"Could not restore publishers."});
403+
BLOG(ledger_, ledger::LogLevel::LOG_ERROR) <<
404+
"Could not restore publishers.";
390405
}
391406
}
392407

@@ -778,7 +793,7 @@ void BatPublishers::getPublisherActivityFromUrl(uint64_t windowId, const ledger:
778793
new_data.url = visit_data.url;
779794
new_data.favicon_url = "";
780795

781-
ledger_->GetActivityInfo(filter,
796+
ledger_->GetPanelPublisherInfo(filter,
782797
std::bind(&BatPublishers::onPublisherActivity, this, _1, _2, windowId, new_data));
783798
}
784799

src/ledger_impl.cc

+7
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ void LedgerImpl::GetActivityInfo(
383383
ledger_client_->LoadActivityInfo(filter, callback);
384384
}
385385

386+
387+
void LedgerImpl::GetPanelPublisherInfo(
388+
const ledger::ActivityInfoFilter& filter,
389+
ledger::PublisherInfoCallback callback) {
390+
ledger_client_->LoadPanelPublisherInfo(filter, callback);
391+
}
392+
386393
void LedgerImpl::GetMediaPublisherInfo(const std::string& media_key,
387394
ledger::PublisherInfoCallback callback) {
388395
ledger_client_->LoadMediaPublisherInfo(media_key, callback);

src/ledger_impl.h

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class LedgerImpl : public ledger::Ledger,
6565
ledger::PublisherInfoCallback callback) override;
6666
void GetActivityInfo(const ledger::ActivityInfoFilter& filter,
6767
ledger::PublisherInfoCallback callback) override;
68+
void GetPanelPublisherInfo(const ledger::ActivityInfoFilter& filter,
69+
ledger::PublisherInfoCallback callback);
6870
void GetMediaPublisherInfo(const std::string& media_key,
6971
ledger::PublisherInfoCallback callback) override;
7072
void SetMediaPublisherInfo(const std::string& media_key,

0 commit comments

Comments
 (0)