Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for non-verified flag #1042

Merged
merged 1 commit into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions browser/ui/webui/brave_rewards_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,18 +540,22 @@ void RewardsDOMHandler::SaveSetting(const base::ListValue* args) {

if (key == "contributionMinTime") {
rewards_service_->SetPublisherMinVisitTime(std::stoull(value));
OnContentSiteUpdated(rewards_service_);
}

if (key == "contributionMinVisits") {
rewards_service_->SetPublisherMinVisits(std::stoul(value));
OnContentSiteUpdated(rewards_service_);
}

if (key == "contributionNonVerified") {
rewards_service_->SetPublisherAllowNonVerified(value == "true");
OnContentSiteUpdated(rewards_service_);
}

if (key == "contributionVideos") {
rewards_service_->SetPublisherAllowVideos(value == "true");
OnContentSiteUpdated(rewards_service_);
}

if (key == "enabledContribute") {
Expand Down
4 changes: 4 additions & 0 deletions components/brave_rewards/browser/publisher_info_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ std::string PublisherInfoDatabase::BuildClauses(int start,
clauses += " AND ai.percent >= ?";
}

if (!filter.non_verified) {
clauses += " AND pi.verified = 1";
}

for (const auto& it : filter.order_by) {
clauses += " ORDER BY " + it.first;
clauses += (it.second ? " ASC" : " DESC");
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ void RewardsServiceImpl::GetCurrentContributeList(
filter.excluded =
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL_EXCEPT_EXCLUDED;
filter.percent = 1;
filter.non_verified = ledger_->GetPublisherAllowNonVerified();

ledger_->GetPublisherInfoList(
start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ LEDGER_EXPORT struct PublisherInfoFilter {
std::vector<std::pair<std::string, bool>> order_by;
unsigned int min_duration;
uint64_t reconcile_stamp;
bool non_verified;
};

LEDGER_EXPORT struct ContributionInfo {
Expand Down
6 changes: 4 additions & 2 deletions vendor/bat-native-ledger/src/bat/ledger/ledger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ PublisherInfoFilter::PublisherInfoFilter() :
excluded(PUBLISHER_EXCLUDE_FILTER::FILTER_DEFAULT),
percent(0),
min_duration(0),
reconcile_stamp(0) {}
reconcile_stamp(0),
non_verified(true) {}
PublisherInfoFilter::PublisherInfoFilter(const PublisherInfoFilter& filter) :
id(filter.id),
category(filter.category),
Expand All @@ -100,7 +101,8 @@ PublisherInfoFilter::PublisherInfoFilter(const PublisherInfoFilter& filter) :
percent(filter.percent),
order_by(filter.order_by),
min_duration(filter.min_duration),
reconcile_stamp(filter.reconcile_stamp) {}
reconcile_stamp(filter.reconcile_stamp),
non_verified(filter.non_verified) {}
PublisherInfoFilter::~PublisherInfoFilter() {}

PublisherBanner::PublisherBanner() {}
Expand Down
3 changes: 2 additions & 1 deletion vendor/bat-native-ledger/src/bat_contribution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ void BatContribution::StartAutoContribute() {
-1,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL_EXCEPT_EXCLUDED,
true,
current_reconcile_stamp);
current_reconcile_stamp,
ledger_->GetPublisherAllowNonVerified());
ledger_->GetPublisherInfoList(
0,
0,
Expand Down
6 changes: 4 additions & 2 deletions vendor/bat-native-ledger/src/bat_get_media.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ void BatGetMedia::onFetchFavIcon(const std::string& publisher_key,
-1,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
false,
currentReconcileStamp);
currentReconcileStamp,
true);
ledger_->GetPublisherInfo(filter,
std::bind(&BatGetMedia::onFetchFavIconDBResponse,
this, _1, _2, favicon_url));
Expand Down Expand Up @@ -660,7 +661,8 @@ void BatGetMedia::fetchPublisherDataFromDB(uint64_t windowId,
visit_data.local_year,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
false,
ledger_->GetReconcileStamp());
ledger_->GetReconcileStamp(),
true);
ledger_->GetPublisherInfo(filter,
std::bind(&BatGetMedia::onFetchPublisherFromDBResponse,
this, _1, _2, windowId, visit_data, providerType, publisher_key));
Expand Down
42 changes: 30 additions & 12 deletions vendor/bat-native-ledger/src/bat_publishers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ void BatPublishers::saveVisit(const std::string& publisher_id,
visit_data.local_year,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
false,
ledger_->GetReconcileStamp());
ledger_->GetReconcileStamp(),
true);

ledger::PublisherInfoCallback callbackGetPublishers = std::bind(&BatPublishers::saveVisitInternal, this,
publisher_id,
Expand All @@ -130,7 +131,8 @@ ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
year,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
true,
0);
0,
true);
}

ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
Expand All @@ -145,7 +147,8 @@ ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
year,
excluded,
true,
0);
0,
true);
}

ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
Expand All @@ -160,7 +163,8 @@ ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
year,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
min_duration,
0);
0,
true);
}

ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
Expand All @@ -170,7 +174,8 @@ ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
int year,
ledger::PUBLISHER_EXCLUDE_FILTER excluded,
bool min_duration,
const uint64_t& currentReconcileStamp) {
const uint64_t& currentReconcileStamp,
bool non_verified) {
ledger::PublisherInfoFilter filter;
filter.id = publisher_id;
filter.category = category;
Expand All @@ -179,6 +184,7 @@ ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
filter.excluded = excluded;
filter.min_duration = min_duration ? getPublisherMinVisitTime() : 0;
filter.reconcile_stamp = currentReconcileStamp;
filter.non_verified = non_verified;

return filter;
}
Expand Down Expand Up @@ -230,6 +236,12 @@ void BatPublishers::saveVisitInternal(
return;
}

bool verified = isVerified(publisher_id);

if (!ledger_->GetPublisherAllowNonVerified() && !verified) {
return;
}

bool new_visit = false;
if (!publisher_info.get()) {
new_visit = true;
Expand Down Expand Up @@ -257,7 +269,7 @@ void BatPublishers::saveVisitInternal(
}
}
publisher_info->score += concaveScore(duration);
publisher_info->verified = isVerified(publisher_info->id);
publisher_info->verified = verified;
publisher_info->reconcile_stamp = ledger_->GetReconcileStamp();

auto media_info = std::make_unique<ledger::PublisherInfo>(*publisher_info);
Expand Down Expand Up @@ -293,7 +305,8 @@ void BatPublishers::setExclude(const std::string& publisher_id, const ledger::PU
-1,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
false,
currentReconcileStamp);
currentReconcileStamp,
true);
ledger_->GetPublisherInfo(filter, std::bind(&BatPublishers::onSetExcludeInternal,
this, exclude, _1, _2));
}
Expand All @@ -307,7 +320,8 @@ void BatPublishers::setPanelExclude(const std::string& publisher_id,
-1,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
false,
currentReconcileStamp);
currentReconcileStamp,
true);
ledger_->GetPublisherInfo(filter, std::bind(
&BatPublishers::onSetPanelExcludeInternal,
this, exclude, windowId, _1, _2));
Expand Down Expand Up @@ -394,7 +408,8 @@ void BatPublishers::restorePublishers() {
-1,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_EXCLUDED,
false,
currentReconcileStamp);
currentReconcileStamp,
true);
ledger_->GetPublisherInfoList(0, 0, filter, std::bind(&BatPublishers::onRestorePublishersInternal,
this, _1, _2));
}
Expand Down Expand Up @@ -560,7 +575,8 @@ void BatPublishers::synopsisNormalizer(const ledger::PublisherInfo& info) {
info.year,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL_EXCEPT_EXCLUDED,
true,
ledger_->GetReconcileStamp());
ledger_->GetReconcileStamp(),
ledger_->GetPublisherAllowNonVerified());
// TODO SZ: We pull the whole list currently, I don't think it consumes lots of RAM, but could.
// We need to limit it and iterate.
ledger_->GetPublisherInfoList(0, 0, filter, std::bind(&BatPublishers::synopsisNormalizerInternal, this,
Expand Down Expand Up @@ -788,7 +804,8 @@ void BatPublishers::getPublisherActivityFromUrl(uint64_t windowId, const ledger:
visit_data.local_year,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
false,
ledger_->GetReconcileStamp());
ledger_->GetReconcileStamp(),
true);

ledger::VisitData new_data;
new_data.domain = visit_data.domain;
Expand Down Expand Up @@ -885,7 +902,8 @@ void BatPublishers::getPublisherBanner(const std::string& publisher_id,
-1,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
false,
currentReconcileStamp);
currentReconcileStamp,
true);

ledger::PublisherInfoCallback callbackGetPublisher = std::bind(&BatPublishers::onPublisherBanner,
this,
Expand Down
3 changes: 2 additions & 1 deletion vendor/bat-native-ledger/src/bat_publishers.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
int year,
ledger::PUBLISHER_EXCLUDE_FILTER excluded,
bool min_duration,
const uint64_t& currentReconcileStamp);
const uint64_t& currentReconcileStamp,
bool non_verified);

void clearAllBalanceReports();
void NormalizeContributeWinners(
Expand Down
29 changes: 16 additions & 13 deletions vendor/bat-native-ledger/src/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -805,20 +805,23 @@ void LedgerImpl::OnRemovedRecurring(ledger::Result result) {
}
}

ledger::PublisherInfoFilter LedgerImpl::CreatePublisherFilter(const std::string& publisher_id,
ledger::PUBLISHER_CATEGORY category,
ledger::PUBLISHER_MONTH month,
int year,
ledger::PUBLISHER_EXCLUDE_FILTER excluded,
bool min_duration,
const uint64_t& currentReconcileStamp) {
ledger::PublisherInfoFilter LedgerImpl::CreatePublisherFilter(
const std::string& publisher_id,
ledger::PUBLISHER_CATEGORY category,
ledger::PUBLISHER_MONTH month,
int year,
ledger::PUBLISHER_EXCLUDE_FILTER excluded,
bool min_duration,
const uint64_t& currentReconcileStamp,
bool non_verified) {
return bat_publishers_->CreatePublisherFilter(publisher_id,
category,
month,
year,
excluded,
min_duration,
currentReconcileStamp);
category,
month,
year,
excluded,
min_duration,
currentReconcileStamp,
non_verified);
}


Expand Down
6 changes: 4 additions & 2 deletions vendor/bat-native-ledger/src/ledger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,15 @@ class LedgerImpl : public ledger::Ledger,
const uint32_t date) override;
void GetRecurringDonations(ledger::PublisherInfoListCallback callback);
void RemoveRecurring(const std::string& publisher_key) override;
ledger::PublisherInfoFilter CreatePublisherFilter(const std::string& publisher_id,
ledger::PublisherInfoFilter CreatePublisherFilter(
const std::string& publisher_id,
ledger::PUBLISHER_CATEGORY category,
ledger::PUBLISHER_MONTH month,
int year,
ledger::PUBLISHER_EXCLUDE_FILTER excluded,
bool min_duration,
const uint64_t& currentReconcileStamp);
const uint64_t& currentReconcileStamp,
bool non_verified);
std::unique_ptr<ledger::LogStream> Log(
const char* file,
int line,
Expand Down