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

Commit

Permalink
Refactors restore flow
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Dec 5, 2018
1 parent da589d2 commit fde913e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 2 additions & 0 deletions include/bat/ledger/ledger_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ using GetNicewareListCallback =
using RecurringDonationCallback = std::function<void(const PublisherInfoList&)>;
using RecurringRemoveCallback = std::function<void(Result)>;
using FetchIconCallback = std::function<void(bool, const std::string&)>;
using OnRestoreCallback = std::function<void(bool)>;

class LEDGER_EXPORT LedgerClient {
public:
Expand Down Expand Up @@ -153,6 +154,7 @@ class LEDGER_EXPORT LedgerClient {
const char* file,
int line,
const ledger::LogLevel log_level) const = 0;
virtual void OnRestorePublishers(ledger::OnRestoreCallback callback) = 0;
};

} // namespace ledger
Expand Down
33 changes: 13 additions & 20 deletions src/bat_publishers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,28 +372,21 @@ void BatPublishers::onSetPanelExcludeInternal(ledger::PUBLISHER_EXCLUDE exclude,
OnExcludedSitesChanged(publisherKey);
}

// TODO refactor
void BatPublishers::restorePublishers() {
uint64_t currentReconcileStamp = ledger_->GetReconcileStamp();
auto filter = CreateActivityFilter("",
ledger::ACTIVITY_MONTH::ANY,
-1,
ledger::EXCLUDE_FILTER::FILTER_EXCLUDED,
false,
currentReconcileStamp);
ledger_->GetActivityInfoList(0, 0, filter, std::bind(&BatPublishers::onRestorePublishersInternal,
this, _1, _2));
void BatPublishers::RestorePublishers() {
ledger_->OnRestorePublishers(
std::bind(&BatPublishers::OnRestorePublishersInternal,
this,
_1));
}

void BatPublishers::onRestorePublishersInternal(const ledger::PublisherInfoList& publisherInfoList, uint32_t /* next_record */) {
if (publisherInfoList.size() == 0) {
return;
}

for (size_t i = 0; i < publisherInfoList.size(); i++) {
// Set to PUBLISHER_EXCLUDE::DEFAULT (0)
setExclude(publisherInfoList[i].id,
ledger::PUBLISHER_EXCLUDE::DEFAULT);
void BatPublishers::OnRestorePublishersInternal(bool success) {
if (success) {
setNumExcludedSites(0);
OnExcludedSitesChanged();
} else {
ledger_->Log(__func__,
ledger::LogLevel::LOG_ERROR,
{"Could not restore publishers."});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/bat_publishers.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
void setPanelExclude(const std::string& publisher_id,
const ledger::PUBLISHER_EXCLUDE& exclude, uint64_t windowId);

void restorePublishers();
void RestorePublishers();

void setPublisherAllowNonVerified(const bool& allow);
void setPublisherAllowVideos(const bool& allow);
Expand Down Expand Up @@ -168,7 +168,7 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> publisher_info);

void onRestorePublishersInternal(const ledger::PublisherInfoList& publisherInfoList, uint32_t /* next_record */);
void OnRestorePublishersInternal(bool success);

double concaveScore(const uint64_t& duration);

Expand Down
6 changes: 5 additions & 1 deletion src/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ void LedgerImpl::SetPublisherPanelExclude(const std::string& publisher_id,
}

void LedgerImpl::RestorePublishers() {
bat_publishers_->restorePublishers();
bat_publishers_->RestorePublishers();
}

void LedgerImpl::OnRestorePublishers(ledger::OnRestoreCallback callback) {
ledger_client_->OnRestorePublishers(callback);
}

void LedgerImpl::LoadNicewareList(ledger::GetNicewareListCallback callback) {
Expand Down
1 change: 1 addition & 0 deletions src/ledger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class LedgerImpl : public ledger::Ledger,
const ledger::PUBLISHER_EXCLUDE& exclude, uint64_t windowId) override;

void RestorePublishers() override;
void OnRestorePublishers(ledger::OnRestoreCallback callback);
bool IsWalletCreated() const override;
void GetPublisherActivityFromUrl(uint64_t windowId, const ledger::VisitData& visit_data) override;
void GetMediaActivityFromUrl(uint64_t windowId,
Expand Down

0 comments on commit fde913e

Please sign in to comment.