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

Commit 064a3dc

Browse files
committed
Refactors restore flow
1 parent d57b757 commit 064a3dc

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

include/bat/ledger/ledger_client.h

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ using GetNicewareListCallback =
4646
using RecurringDonationCallback = std::function<void(const PublisherInfoList&)>;
4747
using RecurringRemoveCallback = std::function<void(Result)>;
4848
using FetchIconCallback = std::function<void(bool, const std::string&)>;
49+
using OnRestoreCallback = std::function<void(bool)>;
4950

5051
class LEDGER_EXPORT LedgerClient {
5152
public:
@@ -141,6 +142,8 @@ class LEDGER_EXPORT LedgerClient {
141142

142143
// Log debug information
143144
virtual void Log(ledger::LogLevel level, const std::string& text) = 0;
145+
146+
virtual void OnRestorePublishers(ledger::OnRestoreCallback callback) = 0;
144147
};
145148

146149
} // namespace ledger

src/bat_publishers.cc

+13-20
Original file line numberDiff line numberDiff line change
@@ -368,28 +368,21 @@ void BatPublishers::onSetPanelExcludeInternal(ledger::PUBLISHER_EXCLUDE exclude,
368368
OnExcludedSitesChanged();
369369
}
370370

371-
// TODO refactor
372-
void BatPublishers::restorePublishers() {
373-
uint64_t currentReconcileStamp = ledger_->GetReconcileStamp();
374-
auto filter = CreateActivityFilter("",
375-
ledger::ACTIVITY_MONTH::ANY,
376-
-1,
377-
ledger::EXCLUDE_FILTER::FILTER_EXCLUDED,
378-
false,
379-
currentReconcileStamp);
380-
ledger_->GetActivityInfoList(0, 0, filter, std::bind(&BatPublishers::onRestorePublishersInternal,
381-
this, _1, _2));
371+
void BatPublishers::RestorePublishers() {
372+
ledger_->OnRestorePublishers(
373+
std::bind(&BatPublishers::OnRestorePublishersInternal,
374+
this,
375+
_1));
382376
}
383377

384-
void BatPublishers::onRestorePublishersInternal(const ledger::PublisherInfoList& publisherInfoList, uint32_t /* next_record */) {
385-
if (publisherInfoList.size() == 0) {
386-
return;
387-
}
388-
389-
for (size_t i = 0; i < publisherInfoList.size(); i++) {
390-
// Set to PUBLISHER_EXCLUDE::DEFAULT (0)
391-
setExclude(publisherInfoList[i].id,
392-
ledger::PUBLISHER_EXCLUDE::DEFAULT);
378+
void BatPublishers::OnRestorePublishersInternal(bool success) {
379+
if (success) {
380+
setNumExcludedSites(0);
381+
OnExcludedSitesChanged();
382+
} else {
383+
ledger_->Log(__func__,
384+
ledger::LogLevel::LOG_ERROR,
385+
{"Could not restore publishers."});
393386
}
394387
}
395388

src/bat_publishers.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
5656
void setPanelExclude(const std::string& publisher_id,
5757
const ledger::PUBLISHER_EXCLUDE& exclude, uint64_t windowId);
5858

59-
void restorePublishers();
59+
void RestorePublishers();
6060

6161
void setPublisherAllowNonVerified(const bool& allow);
6262
void setPublisherAllowVideos(const bool& allow);
@@ -168,7 +168,7 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
168168
ledger::Result result,
169169
std::unique_ptr<ledger::PublisherInfo> publisher_info);
170170

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

173173
double concaveScore(const uint64_t& duration);
174174

src/ledger_impl.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,11 @@ void LedgerImpl::SetPublisherPanelExclude(const std::string& publisher_id,
320320
}
321321

322322
void LedgerImpl::RestorePublishers() {
323-
bat_publishers_->restorePublishers();
323+
bat_publishers_->RestorePublishers();
324+
}
325+
326+
void LedgerImpl::OnRestorePublishers(ledger::OnRestoreCallback callback) {
327+
ledger_client_->OnRestorePublishers(callback);
324328
}
325329

326330
void LedgerImpl::LoadNicewareList(ledger::GetNicewareListCallback callback) {

src/ledger_impl.h

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class LedgerImpl : public ledger::Ledger,
161161
const ledger::PUBLISHER_EXCLUDE& exclude, uint64_t windowId) override;
162162

163163
void RestorePublishers() override;
164+
void OnRestorePublishers(ledger::OnRestoreCallback callback);
164165
bool IsWalletCreated() const override;
165166
void GetPublisherActivityFromUrl(uint64_t windowId, const ledger::VisitData& visit_data) override;
166167
void GetMediaActivityFromUrl(uint64_t windowId,

0 commit comments

Comments
 (0)