Skip to content

Commit

Permalink
Fixes publisher list being called twice
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Sep 5, 2019
1 parent da51459 commit ce57c1b
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ void PublisherServerList::OnDownload(
void PublisherServerList::OnParsePublisherList(
const ledger::Result result,
DownloadServerPublisherListCallback callback) {
bool retry_after_error = result != ledger::Result::LEDGER_OK;
SetTimer(retry_after_error);

uint64_t new_time = 0ull;
if (result == ledger::Result::LEDGER_OK) {
ledger_->ContributeUnverifiedPublishers();
Expand All @@ -102,6 +99,10 @@ void PublisherServerList::OnParsePublisherList(
}

ledger_->SetUint64State(ledger::kStateServerPublisherListStamp, new_time);

bool retry_after_error = result != ledger::Result::LEDGER_OK;
SetTimer(retry_after_error);

callback(result);
}

Expand Down Expand Up @@ -260,15 +261,21 @@ ledger::PublisherBannerPtr PublisherServerList::ParsePublisherBanner(
}

auto banner = ledger::PublisherBanner::New();

bool empty = true;
auto* title = dictionary->FindKey("title");
if (title && title->is_string()) {
banner->title = title->GetString();
if (!banner->title.empty()) {
empty = false;
}
}

auto* description = dictionary->FindKey("description");
if (description && description->is_string()) {
banner->description = description->GetString();
if (!banner->description.empty()) {
empty = false;
}
}

auto* background = dictionary->FindKey("backgroundUrl");
Expand All @@ -277,6 +284,7 @@ ledger::PublisherBannerPtr PublisherServerList::ParsePublisherBanner(

if (!banner->background.empty()) {
banner->background = "chrome://rewards-image/" + banner->background;
empty = false;
}
}

Expand All @@ -286,6 +294,7 @@ ledger::PublisherBannerPtr PublisherServerList::ParsePublisherBanner(

if (!banner->logo.empty()) {
banner->logo = "chrome://rewards-image/" + banner->logo;
empty = false;
}
}

Expand All @@ -294,13 +303,25 @@ ledger::PublisherBannerPtr PublisherServerList::ParsePublisherBanner(
for (const auto& it : amounts->GetList()) {
banner->amounts.push_back(it.GetInt());
}

if (banner->amounts.size() != 0) {
empty = false;
}
}

auto* links = dictionary->FindKey("socialLinks");
if (links && links->is_dict()) {
for (const auto& it : links->DictItems()) {
banner->links.insert(std::make_pair(it.first, it.second.GetString()));
}

if (banner->links.size() != 0) {
empty = false;
}
}

if (empty) {
return nullptr;
}

return banner;
Expand Down

0 comments on commit ce57c1b

Please sign in to comment.