Skip to content

Commit

Permalink
Merge pull request #13475 from brave/maxk-update-publisher-info
Browse files Browse the repository at this point in the history
[Rewards] Update publisher info when name or url change.
  • Loading branch information
mkarolin authored May 26, 2022
2 parents 882689c + 94cd8cd commit cf82401
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,18 @@ const handleSavePublisherVisit = (tabId: number, mediaType: string, data: SavePu

chrome.braveRewards.getPublisherInfo(
data.publisherKey, (result: RewardsExtension.Result, info?: RewardsExtension.Publisher) => {
let shouldUpdate = false
if (result === 0 && info) {
getPublisherPanelInfo(tabId, data.publisherKey)
return
shouldUpdate = (info.name !== data.publisherName || info.url !== data.url)
if (!shouldUpdate) {
getPublisherPanelInfo(tabId, data.publisherKey)
return
}
}

// Failed to find publisher info corresponding to this key, so save it now
if (result === 9) {
// Failed to find the publisher info corresponding to this key or the
// publisher info needs to be updated, so save the info now
if (result === 9 || shouldUpdate) {
savePublisherInfo(
tabId,
mediaType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,14 @@ void Publisher::SaveVisitInternal(
bool is_verified = IsConnectedOrVerified(status);

bool new_publisher = false;
bool updated_publisher = false;
if (!publisher_info) {
new_publisher = true;
publisher_info = type::PublisherInfo::New();
publisher_info->id = publisher_key;
} else if (publisher_info->name != visit_data.name ||
publisher_info->url != visit_data.url) {
updated_publisher = true;
}

std::string fav_icon = visit_data.favicon_url;
Expand Down Expand Up @@ -337,22 +341,18 @@ void Publisher::SaveVisitInternal(
bool verified_new = !allow_non_verified && !is_verified;
bool verified_old = allow_non_verified || is_verified;

if (new_publisher &&
(excluded ||
!ledger_->state()->GetAutoContributeEnabled() ||
min_duration_new ||
verified_new)) {
if ((new_publisher || updated_publisher) &&
(excluded || !ledger_->state()->GetAutoContributeEnabled() ||
min_duration_new || verified_new)) {
panel_info = publisher_info->Clone();

auto callback = std::bind(&Publisher::OnPublisherInfoSaved,
this,
_1);

ledger_->database()->SavePublisherInfo(std::move(publisher_info), callback);
} else if (!excluded &&
ledger_->state()->GetAutoContributeEnabled() &&
min_duration_ok &&
verified_old) {
} else if (!excluded && ledger_->state()->GetAutoContributeEnabled() &&
min_duration_ok && verified_old) {
if (first_visit) {
publisher_info->visits += 1;
}
Expand Down

0 comments on commit cf82401

Please sign in to comment.