From 94cd8cd52a34beb088b296f0a6a2b16822f49de9 Mon Sep 17 00:00:00 2001 From: mkarolin Date: Wed, 25 May 2022 18:11:06 -0400 Subject: [PATCH] [Rewards] Update publisher info when name or url change. --- .../brave_extension/background/greaselion.ts | 13 +++++++++---- .../bat/ledger/internal/publisher/publisher.cc | 18 +++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/components/brave_extension/extension/brave_extension/background/greaselion.ts b/components/brave_extension/extension/brave_extension/background/greaselion.ts index b23c9a222c5c..f2ce146ab84a 100644 --- a/components/brave_extension/extension/brave_extension/background/greaselion.ts +++ b/components/brave_extension/extension/brave_extension/background/greaselion.ts @@ -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, diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/publisher/publisher.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/publisher/publisher.cc index 353af853f83f..12c63e24898b 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/publisher/publisher.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/publisher/publisher.cc @@ -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; @@ -337,11 +341,9 @@ 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, @@ -349,10 +351,8 @@ void Publisher::SaveVisitInternal( _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; }