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

Commit

Permalink
Merge pull request #117 from ryanml/feature-115
Browse files Browse the repository at this point in the history
Adding numExcludedSites to publisher state
  • Loading branch information
NejcZdovc authored Oct 2, 2018
2 parents f0a310d + 9981360 commit ca5d4b6
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/bat/ledger/ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class LEDGER_EXPORT Ledger {
virtual bool GetRewardsMainEnabled() const = 0;
virtual uint64_t GetPublisherMinVisitTime() const = 0; // In milliseconds
virtual unsigned int GetPublisherMinVisits() const = 0;
virtual unsigned int GetNumExcludedSites() const = 0;
virtual bool GetPublisherAllowNonVerified() const = 0;
virtual bool GetPublisherAllowVideos() const = 0;
virtual double GetContributionAmount() const = 0;
Expand Down
1 change: 1 addition & 0 deletions include/bat/ledger/ledger_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class LEDGER_EXPORT LedgerClient {
virtual void OnPublisherActivity(Result result,
std::unique_ptr<ledger::PublisherInfo>,
uint64_t windowId) = 0;
virtual void OnExcludedSitesChanged() = 0;

//uint64_t time_offset (input): timer offset in seconds.
//uint32_t timer_id (output) : 0 in case of failure
Expand Down
1 change: 1 addition & 0 deletions include/bat/ledger/publisher_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ LEDGER_EXPORT enum PUBLISHER_MONTH {
};

LEDGER_EXPORT enum PUBLISHER_EXCLUDE {
ALL = -1,
DEFAULT = 0, // this tell us that user did not manually changed exclude state
EXCLUDED = 1, // user manually changed it to exclude
INCLUDED = 2 // user manually changed it to include and is overriding server flags
Expand Down
7 changes: 7 additions & 0 deletions src/bat_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,15 @@ static bool ignore_ = false;
PUBLISHER_STATE_ST::PUBLISHER_STATE_ST():
min_pubslisher_duration_(braveledger_ledger::_default_min_pubslisher_duration),
min_visits_(1),
num_excluded_sites_(0),
allow_non_verified_(true),
pubs_load_timestamp_ (0ull),
allow_videos_(true) {}

PUBLISHER_STATE_ST::PUBLISHER_STATE_ST(const PUBLISHER_STATE_ST& state) {
min_pubslisher_duration_ = state.min_pubslisher_duration_;
min_visits_ = state.min_visits_;
num_excluded_sites_ = state.num_excluded_sites_;
allow_non_verified_ = state.allow_non_verified_;
pubs_load_timestamp_ = state.pubs_load_timestamp_;
allow_videos_ = state.allow_videos_;
Expand All @@ -802,6 +804,7 @@ static bool ignore_ = false;
if (false == error) {
error = !(d.HasMember("min_pubslisher_duration") && d["min_pubslisher_duration"].IsUint() &&
d.HasMember("min_visits") && d["min_visits"].IsUint() &&
d.HasMember("num_excluded_sites") && d["num_excluded_sites"].IsUint() &&
d.HasMember("allow_non_verified") && d["allow_non_verified"].IsBool() &&
d.HasMember("pubs_load_timestamp") && d["pubs_load_timestamp"].IsUint64() &&
d.HasMember("allow_videos") && d["allow_videos"].IsBool() &&
Expand All @@ -812,6 +815,7 @@ static bool ignore_ = false;
if (false == error) {
min_pubslisher_duration_ = d["min_pubslisher_duration"].GetUint();
min_visits_ = d["min_visits"].GetUint();
num_excluded_sites_ = d["num_excluded_sites"].GetUint();
allow_non_verified_ = d["allow_non_verified"].GetBool();
pubs_load_timestamp_ = d["pubs_load_timestamp"].GetUint64();
allow_videos_ = d["allow_videos"].GetBool();
Expand Down Expand Up @@ -861,6 +865,9 @@ static bool ignore_ = false;
writer.String("min_visits");
writer.Uint(data.min_visits_);

writer.String("num_excluded_sites");
writer.Uint(data.num_excluded_sites_);

writer.String("allow_non_verified");
writer.Bool(data.allow_non_verified_);

Expand Down
1 change: 1 addition & 0 deletions src/bat_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ namespace braveledger_bat_helper {

uint64_t min_pubslisher_duration_ = braveledger_ledger::_default_min_pubslisher_duration; // In seconds
unsigned int min_visits_ = 1u;
unsigned int num_excluded_sites_ = 0;
bool allow_non_verified_ = true;
uint64_t pubs_load_timestamp_ = 0ull; //last publishers list load timestamp (seconds)
bool allow_videos_ = true;
Expand Down
23 changes: 23 additions & 0 deletions src/bat_publishers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ void onVisitSavedDummy(ledger::Result result,
// onPublisherInfoUpdated will always be called by LedgerImpl so do nothing
}

void BatPublishers::setNumExcludedSitesInternal(ledger::PUBLISHER_EXCLUDE exclude) {
unsigned int previousNum = getNumExcludedSites();
setNumExcludedSites((exclude == ledger::PUBLISHER_EXCLUDE::EXCLUDED)
? ++previousNum
: --previousNum);
}

void BatPublishers::makePaymentInternal(
ledger::PaymentData payment_data,
ledger::Result result,
Expand Down Expand Up @@ -275,9 +282,11 @@ void BatPublishers::onSetExcludeInternal(ledger::PUBLISHER_EXCLUDE exclude,
publisher_info->year = -1;
publisher_info->excluded = exclude;
publisher_info->month = ledger::PUBLISHER_MONTH::ANY;
setNumExcludedSitesInternal(exclude);

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

void BatPublishers::restorePublishers() {
Expand Down Expand Up @@ -317,6 +326,11 @@ void BatPublishers::setPublishersLastRefreshTimestamp(uint64_t ts) {
saveState();
}

void BatPublishers::setNumExcludedSites(const unsigned int& amount) {
state_->num_excluded_sites_ = amount;
saveState();
}

void BatPublishers::setPublisherAllowNonVerified(const bool& allow) {
state_->allow_non_verified_ = allow;
saveState();
Expand All @@ -338,10 +352,15 @@ unsigned int BatPublishers::getPublisherMinVisits() const {
bool BatPublishers::getPublisherAllowNonVerified() const {
return state_->allow_non_verified_;
}

uint64_t BatPublishers::getLastPublishersListLoadTimestamp() const {
return state_->pubs_load_timestamp_;
}

unsigned int BatPublishers::getNumExcludedSites() const {
return state_->num_excluded_sites_;
}

bool BatPublishers::getPublisherAllowVideos() const {
return state_->allow_videos_;
}
Expand Down Expand Up @@ -671,4 +690,8 @@ void BatPublishers::onPublisherActivity(ledger::Result result,
ledger_->OnPublisherActivity(result, std::move(info), windowId);
}

void BatPublishers::OnExcludedSitesChanged() {
ledger_->OnExcludedSitesChanged();
}

} // namespace braveledger_bat_publisher
7 changes: 7 additions & 0 deletions src/bat_publishers.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class BatPublishers : public ledger::LedgerCallbackHandler {

void setPublishersLastRefreshTimestamp(uint64_t ts);

void setNumExcludedSites(const unsigned int& amount);

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

Expand All @@ -67,6 +69,7 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
unsigned int getPublisherMinVisits() const;
bool getPublisherAllowNonVerified() const;
uint64_t getLastPublishersListLoadTimestamp() const;
unsigned int getNumExcludedSites() const;
bool getPublisherAllowVideos() const;

std::vector<braveledger_bat_helper::WINNERS_ST> winners(const unsigned int& ballots);
Expand Down Expand Up @@ -131,6 +134,8 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> publisher_info);

void setNumExcludedSitesInternal(ledger::PUBLISHER_EXCLUDE exclude);

void makePaymentInternal(
ledger::PaymentData payment_data,
ledger::Result result,
Expand Down Expand Up @@ -159,6 +164,8 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
uint64_t windowId,
const std::string& publisherKey);

void OnExcludedSitesChanged();

bat_ledger::LedgerImpl* ledger_; // NOT OWNED

std::vector<braveledger_bat_helper::PUBLISHER_ST> topN();
Expand Down
8 changes: 8 additions & 0 deletions src/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ unsigned int LedgerImpl::GetPublisherMinVisits() const {
return bat_publishers_->getPublisherMinVisits();
}

unsigned int LedgerImpl::GetNumExcludedSites() const {
return bat_publishers_->getNumExcludedSites();
}

bool LedgerImpl::GetPublisherAllowNonVerified() const {
return bat_publishers_->getPublisherAllowNonVerified();
}
Expand Down Expand Up @@ -647,4 +651,8 @@ void LedgerImpl::OnPublisherActivity(ledger::Result result,
ledger_client_->OnPublisherActivity(result, std::move(info), windowId);
}

void LedgerImpl::OnExcludedSitesChanged() {
ledger_client_->OnExcludedSitesChanged();
}

} // namespace bat_ledger
2 changes: 2 additions & 0 deletions src/ledger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class LedgerImpl : public ledger::Ledger,
bool GetRewardsMainEnabled() const override;
uint64_t GetPublisherMinVisitTime() const override; // In milliseconds
unsigned int GetPublisherMinVisits() const override;
unsigned int GetNumExcludedSites() const override;
bool GetPublisherAllowNonVerified() const override;
bool GetPublisherAllowVideos() const override;
double GetContributionAmount() const override;
Expand Down Expand Up @@ -151,6 +152,7 @@ class LedgerImpl : public ledger::Ledger,
void OnPublisherActivity(ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> info,
uint64_t windowId);
void OnExcludedSitesChanged();

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

0 comments on commit ca5d4b6

Please sign in to comment.