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 Nov 20, 2018
1 parent d57b757 commit 0c8231a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
3 changes: 3 additions & 0 deletions include/bat/ledger/ledger_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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 @@ -141,6 +142,8 @@ class LEDGER_EXPORT LedgerClient {

// Log debug information
virtual void Log(ledger::LogLevel level, const std::string& text) = 0;

virtual void OnRestorePublishers(ledger::OnRestoreCallback callback) = 0;
};

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

// 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);
}
}

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 @@ -320,7 +320,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 @@ -161,6 +161,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 0c8231a

Please sign in to comment.