Skip to content

Commit cf82401

Browse files
authored
Merge pull request #13475 from brave/maxk-update-publisher-info
[Rewards] Update publisher info when name or url change.
2 parents 882689c + 94cd8cd commit cf82401

File tree

2 files changed

+18
-13
lines changed
  • components/brave_extension/extension/brave_extension/background
  • vendor/bat-native-ledger/src/bat/ledger/internal/publisher

2 files changed

+18
-13
lines changed

components/brave_extension/extension/brave_extension/background/greaselion.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,18 @@ const handleSavePublisherVisit = (tabId: number, mediaType: string, data: SavePu
289289

290290
chrome.braveRewards.getPublisherInfo(
291291
data.publisherKey, (result: RewardsExtension.Result, info?: RewardsExtension.Publisher) => {
292+
let shouldUpdate = false
292293
if (result === 0 && info) {
293-
getPublisherPanelInfo(tabId, data.publisherKey)
294-
return
294+
shouldUpdate = (info.name !== data.publisherName || info.url !== data.url)
295+
if (!shouldUpdate) {
296+
getPublisherPanelInfo(tabId, data.publisherKey)
297+
return
298+
}
295299
}
296300

297-
// Failed to find publisher info corresponding to this key, so save it now
298-
if (result === 9) {
301+
// Failed to find the publisher info corresponding to this key or the
302+
// publisher info needs to be updated, so save the info now
303+
if (result === 9 || shouldUpdate) {
299304
savePublisherInfo(
300305
tabId,
301306
mediaType,

vendor/bat-native-ledger/src/bat/ledger/internal/publisher/publisher.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,14 @@ void Publisher::SaveVisitInternal(
288288
bool is_verified = IsConnectedOrVerified(status);
289289

290290
bool new_publisher = false;
291+
bool updated_publisher = false;
291292
if (!publisher_info) {
292293
new_publisher = true;
293294
publisher_info = type::PublisherInfo::New();
294295
publisher_info->id = publisher_key;
296+
} else if (publisher_info->name != visit_data.name ||
297+
publisher_info->url != visit_data.url) {
298+
updated_publisher = true;
295299
}
296300

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

340-
if (new_publisher &&
341-
(excluded ||
342-
!ledger_->state()->GetAutoContributeEnabled() ||
343-
min_duration_new ||
344-
verified_new)) {
344+
if ((new_publisher || updated_publisher) &&
345+
(excluded || !ledger_->state()->GetAutoContributeEnabled() ||
346+
min_duration_new || verified_new)) {
345347
panel_info = publisher_info->Clone();
346348

347349
auto callback = std::bind(&Publisher::OnPublisherInfoSaved,
348350
this,
349351
_1);
350352

351353
ledger_->database()->SavePublisherInfo(std::move(publisher_info), callback);
352-
} else if (!excluded &&
353-
ledger_->state()->GetAutoContributeEnabled() &&
354-
min_duration_ok &&
355-
verified_old) {
354+
} else if (!excluded && ledger_->state()->GetAutoContributeEnabled() &&
355+
min_duration_ok && verified_old) {
356356
if (first_visit) {
357357
publisher_info->visits += 1;
358358
}

0 commit comments

Comments
 (0)