Skip to content

Commit

Permalink
Merge pull request #92 from ryanml/publisher-exclude
Browse files Browse the repository at this point in the history
Adding method for publisher exclusion
  • Loading branch information
ryanml authored Sep 10, 2018
2 parents e4339df + 9ca4631 commit 4e07f30
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/bat_publishers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,32 @@ std::unique_ptr<ledger::PublisherInfo> BatPublishers::onPublisherInfoUpdated(
return info;
}

void BatPublishers::setExclude(const std::string& publisher_id, const ledger::PUBLISHER_EXCLUDE& exclude) {
auto filter = CreatePublisherFilter(publisher_id,
ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE,
ledger::PUBLISHER_MONTH::ANY,
-1);
ledger_->GetPublisherInfo(filter, std::bind(&BatPublishers::onSetExcludeInternal,
this, exclude, _1, _2));
}

void BatPublishers::onSetExcludeInternal(ledger::PUBLISHER_EXCLUDE exclude,
ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> publisher_info) {
if (result != ledger::Result::OK &&
result != ledger::Result::NOT_FOUND) {
return;
}


publisher_info->year = -1;
publisher_info->excluded = exclude;
publisher_info->month = ledger::PUBLISHER_MONTH::ANY;

ledger_->SetPublisherInfo(std::move(publisher_info),
std::bind(&onVisitSavedDummy, _1, _2));
}

void BatPublishers::setPublisherMinVisitTime(const uint64_t& duration) { // In seconds
state_->min_pubslisher_duration_ = duration;
saveState();
Expand Down
7 changes: 7 additions & 0 deletions src/bat_publishers.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class BatPublishers : public ledger::LedgerCallbackHandler {

void setPublishersLastRefreshTimestamp(uint64_t ts);

void setExclude(const std::string& publisher_id, const ledger::PUBLISHER_EXCLUDE& exclude);

void setPublisherAllowNonVerified(const bool& allow);
void setPublisherAllowVideos(const bool& allow);
void setBalanceReport(ledger::PUBLISHER_MONTH month,
Expand Down Expand Up @@ -104,6 +106,11 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> publisher_info);

void onSetExcludeInternal(
ledger::PUBLISHER_EXCLUDE exclude,
ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> publisher_info);

double concaveScore(const uint64_t& duration);

void saveState();
Expand Down
4 changes: 4 additions & 0 deletions src/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ void LedgerImpl::SaveMediaVisit(const std::string& publisher_id, const ledger::V
bat_publishers_->saveVisit(publisher_id, visit_data, duration);
}

void LedgerImpl::SetPublisherExclude(const std::string& publisher_id, const ledger::PUBLISHER_EXCLUDE& exclude) {
bat_publishers_->setExclude(publisher_id, exclude);
}

void LedgerImpl::OnSetPublisherInfo(ledger::PublisherInfoCallback callback,
ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> info) {
Expand Down
1 change: 1 addition & 0 deletions src/ledger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class LedgerImpl : public ledger::Ledger,
void RunTask(LedgerTaskRunnerImpl::Task task);
std::string URIEncode(const std::string& value) override;
void SaveMediaVisit(const std::string& publisher_id, const ledger::VisitData& visit_data, const uint64_t& duration) override;
void SetPublisherExclude(const std::string& publisher_id, const ledger::PUBLISHER_EXCLUDE& exclude) override;

private:
void MakePayment(const ledger::PaymentData& payment_data) override;
Expand Down

0 comments on commit 4e07f30

Please sign in to comment.