Add first visit support to UpdateMediaDuration
This commit is contained in:
@@ -97,7 +97,8 @@ BraveRewardsUpdateMediaDurationFunction::Run() {
|
||||
rewards_service->UpdateMediaDuration(
|
||||
params->window_id,
|
||||
params->publisher_key,
|
||||
params->duration);
|
||||
params->duration,
|
||||
params->first_visit);
|
||||
|
||||
return RespondNow(NoArguments());
|
||||
}
|
||||
|
||||
@@ -385,6 +385,10 @@
|
||||
{
|
||||
"name": "duration",
|
||||
"type": "integer"
|
||||
},
|
||||
{
|
||||
"name": "firstVisit",
|
||||
"type": "boolean"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -142,10 +142,11 @@ class MockRewardsService : public RewardsService {
|
||||
void(const std::string&,
|
||||
const std::map<std::string, std::string>&,
|
||||
brave_rewards::SaveMediaInfoCallback));
|
||||
MOCK_METHOD3(UpdateMediaDuration, void(
|
||||
MOCK_METHOD4(UpdateMediaDuration, void(
|
||||
const uint64_t,
|
||||
const std::string&,
|
||||
const uint64_t duration));
|
||||
const uint64_t,
|
||||
const bool));
|
||||
MOCK_METHOD2(GetPublisherInfo, void(
|
||||
const std::string&,
|
||||
brave_rewards::GetPublisherInfoCallback callback));
|
||||
|
||||
@@ -277,7 +277,8 @@ class RewardsService : public KeyedService {
|
||||
virtual void UpdateMediaDuration(
|
||||
const uint64_t window_id,
|
||||
const std::string& publisher_key,
|
||||
const uint64_t duration) = 0;
|
||||
const uint64_t duration,
|
||||
const bool firstVisit) = 0;
|
||||
|
||||
virtual void GetPublisherInfo(
|
||||
const std::string& publisher_key,
|
||||
|
||||
@@ -1920,12 +1920,17 @@ void RewardsServiceImpl::SaveInlineMediaInfo(
|
||||
void RewardsServiceImpl::UpdateMediaDuration(
|
||||
const uint64_t window_id,
|
||||
const std::string& publisher_key,
|
||||
const uint64_t duration) {
|
||||
const uint64_t duration,
|
||||
const bool first_visit) {
|
||||
if (!Connected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bat_ledger_->UpdateMediaDuration(window_id, publisher_key, duration);
|
||||
bat_ledger_->UpdateMediaDuration(
|
||||
window_id,
|
||||
publisher_key,
|
||||
duration,
|
||||
first_visit);
|
||||
}
|
||||
|
||||
void RewardsServiceImpl::GetPublisherInfo(
|
||||
|
||||
@@ -241,7 +241,8 @@ class RewardsServiceImpl : public RewardsService,
|
||||
void UpdateMediaDuration(
|
||||
const uint64_t window_id,
|
||||
const std::string& publisher_key,
|
||||
const uint64_t duration) override;
|
||||
const uint64_t duration,
|
||||
const bool first_visit) override;
|
||||
|
||||
void GetPublisherInfo(
|
||||
const std::string& publisher_key,
|
||||
|
||||
+2
-1
@@ -12,6 +12,7 @@ interface GreaselionError {
|
||||
interface MediaDurationMetadata {
|
||||
mediaKey: string
|
||||
duration: number
|
||||
firstVisit: boolean
|
||||
}
|
||||
|
||||
interface RegisterOnCompletedWebRequest {
|
||||
@@ -50,7 +51,7 @@ const handleMediaDurationMetadata = (tabId: number, mediaType: string, data: Med
|
||||
return
|
||||
}
|
||||
|
||||
chrome.braveRewards.updateMediaDuration(tabId, publisherKey, data.duration)
|
||||
chrome.braveRewards.updateMediaDuration(tabId, publisherKey, data.duration, data.firstVisit)
|
||||
}
|
||||
|
||||
const handleRegisterOnCompletedWebRequest = (tabId: number, mediaType: string, data: RegisterOnCompletedWebRequest) => {
|
||||
|
||||
Vendored
+1
-1
@@ -65,7 +65,7 @@ declare namespace chrome.settingsPrivate {
|
||||
declare namespace chrome.braveRewards {
|
||||
const createWallet: () => {}
|
||||
const getRewardsParameters: (callback: (properties: RewardsExtension.RewardsParameters) => void) => {}
|
||||
const updateMediaDuration: (tabId: number, publisherKey: string, duration: number) => {}
|
||||
const updateMediaDuration: (tabId: number, publisherKey: string, duration: number, firstVisit: boolean) => {}
|
||||
const getPublisherInfo: (publisherKey: string, callback: (result: RewardsExtension.Result, properties: RewardsExtension.PublisherInfo) => void) => {}
|
||||
const getPublisherPanelInfo: (publisherKey: string, callback: (result: RewardsExtension.Result, properties: RewardsExtension.PublisherInfo) => void) => {}
|
||||
const savePublisherInfo: (windowId: number, mediaType: string, url: string, publisherKey: string, publisherName: string, favIconUrl: string, callback: (result: RewardsExtension.Result) => void) => {}
|
||||
|
||||
@@ -604,8 +604,9 @@ void BatLedgerImpl::SaveMediaInfo(
|
||||
void BatLedgerImpl::UpdateMediaDuration(
|
||||
const uint64_t window_id,
|
||||
const std::string& publisher_key,
|
||||
const uint64_t duration) {
|
||||
ledger_->UpdateMediaDuration(window_id, publisher_key, duration);
|
||||
const uint64_t duration,
|
||||
const bool first_visit) {
|
||||
ledger_->UpdateMediaDuration(window_id, publisher_key, duration, first_visit);
|
||||
}
|
||||
|
||||
// static
|
||||
|
||||
@@ -163,7 +163,8 @@ class BatLedgerImpl :
|
||||
void UpdateMediaDuration(
|
||||
const uint64_t window_id,
|
||||
const std::string& publisher_key,
|
||||
const uint64_t duration) override;
|
||||
const uint64_t duration,
|
||||
const bool first_visit) override;
|
||||
|
||||
void GetPublisherInfo(
|
||||
const std::string& publisher_key,
|
||||
|
||||
@@ -110,7 +110,7 @@ interface BatLedger {
|
||||
SaveMediaInfo(string type, map<string, string> args) =>
|
||||
(ledger.mojom.Result result, ledger.mojom.PublisherInfo? publisher_info);
|
||||
|
||||
UpdateMediaDuration(uint64 window_id, string publisher_key, uint64 duration);
|
||||
UpdateMediaDuration(uint64 window_id, string publisher_key, uint64 duration, bool first_visit);
|
||||
|
||||
GetPublisherInfo(string publisher_key) => (ledger.mojom.Result result, ledger.mojom.PublisherInfo? info);
|
||||
|
||||
|
||||
+2
-1
@@ -302,7 +302,8 @@ class LEDGER_EXPORT Ledger {
|
||||
virtual void UpdateMediaDuration(
|
||||
const uint64_t window_id,
|
||||
const std::string& publisher_key,
|
||||
const uint64_t duration) = 0;
|
||||
const uint64_t duration,
|
||||
const bool first_visit) = 0;
|
||||
|
||||
virtual void GetPublisherInfo(
|
||||
const std::string& publisher_key,
|
||||
|
||||
@@ -302,6 +302,7 @@ void LedgerImpl::OnHide(uint32_t tab_id, const uint64_t& current_time) {
|
||||
iter->second.tld,
|
||||
iter->second,
|
||||
duration,
|
||||
true,
|
||||
0,
|
||||
[](type::Result, type::PublisherInfoPtr){});
|
||||
}
|
||||
@@ -632,8 +633,13 @@ void LedgerImpl::SaveMediaInfo(
|
||||
void LedgerImpl::UpdateMediaDuration(
|
||||
const uint64_t window_id,
|
||||
const std::string& publisher_key,
|
||||
const uint64_t duration) {
|
||||
publisher()->UpdateMediaDuration(window_id, publisher_key, duration);
|
||||
const uint64_t duration,
|
||||
const bool first_visit) {
|
||||
publisher()->UpdateMediaDuration(
|
||||
window_id,
|
||||
publisher_key,
|
||||
duration,
|
||||
first_visit);
|
||||
}
|
||||
|
||||
void LedgerImpl::GetPublisherInfo(
|
||||
|
||||
@@ -258,7 +258,8 @@ class LedgerImpl : public ledger::Ledger {
|
||||
void UpdateMediaDuration(
|
||||
const uint64_t window_id,
|
||||
const std::string& publisher_key,
|
||||
const uint64_t duration) override;
|
||||
const uint64_t duration,
|
||||
const bool first_visit) override;
|
||||
|
||||
void GetPublisherInfo(
|
||||
const std::string& publisher_key,
|
||||
|
||||
@@ -406,6 +406,7 @@ void GitHub::SavePublisherInfo(
|
||||
publisher_key,
|
||||
visit_data,
|
||||
duration,
|
||||
true,
|
||||
window_id,
|
||||
callback);
|
||||
|
||||
|
||||
@@ -336,6 +336,7 @@ void Reddit::SavePublisherInfo(
|
||||
publisher_key,
|
||||
*visit_data,
|
||||
0,
|
||||
true,
|
||||
window_id,
|
||||
callback);
|
||||
|
||||
|
||||
@@ -650,6 +650,7 @@ void Twitch::SavePublisherInfo(const uint64_t duration,
|
||||
key,
|
||||
new_visit_data,
|
||||
duration,
|
||||
true,
|
||||
window_id,
|
||||
[](ledger::type::Result, ledger::type::PublisherInfoPtr) {});
|
||||
|
||||
|
||||
@@ -386,6 +386,7 @@ void Twitter::SavePublisherInfo(
|
||||
publisher_key,
|
||||
*visit_data,
|
||||
duration,
|
||||
true,
|
||||
window_id,
|
||||
callback);
|
||||
|
||||
|
||||
@@ -672,6 +672,7 @@ void Vimeo::SavePublisherInfo(
|
||||
key,
|
||||
visit_data,
|
||||
duration,
|
||||
true,
|
||||
window_id,
|
||||
[](ledger::type::Result, ledger::type::PublisherInfoPtr) {});
|
||||
|
||||
|
||||
@@ -437,6 +437,7 @@ void YouTube::OnMediaPublisherInfo(
|
||||
id,
|
||||
new_visit_data,
|
||||
duration,
|
||||
true,
|
||||
window_id,
|
||||
[](ledger::type::Result, ledger::type::PublisherInfoPtr) {});
|
||||
}
|
||||
@@ -561,6 +562,7 @@ void YouTube::SavePublisherInfo(const uint64_t duration,
|
||||
publisher_id,
|
||||
new_visit_data,
|
||||
duration,
|
||||
true,
|
||||
window_id,
|
||||
[](ledger::type::Result, ledger::type::PublisherInfoPtr) {});
|
||||
|
||||
|
||||
@@ -126,7 +126,8 @@ bool ignoreMinTime(const std::string& publisher_id) {
|
||||
void Publisher::SaveVisit(
|
||||
const std::string& publisher_key,
|
||||
const type::VisitData& visit_data,
|
||||
const uint64_t& duration,
|
||||
const uint64_t duration,
|
||||
const bool first_visit,
|
||||
uint64_t window_id,
|
||||
const ledger::PublisherInfoCallback callback) {
|
||||
if (!ledger_->state()->GetRewardsMainEnabled()) {
|
||||
@@ -138,8 +139,16 @@ void Publisher::SaveVisit(
|
||||
return;
|
||||
}
|
||||
|
||||
auto on_server_info = std::bind(&Publisher::OnSaveVisitServerPublisher,
|
||||
this, _1, publisher_key, visit_data, duration, window_id, callback);
|
||||
auto on_server_info =
|
||||
std::bind(&Publisher::OnSaveVisitServerPublisher,
|
||||
this,
|
||||
_1,
|
||||
publisher_key,
|
||||
visit_data,
|
||||
duration,
|
||||
first_visit,
|
||||
window_id,
|
||||
callback);
|
||||
|
||||
ledger_->database()->SearchPublisherPrefixList(
|
||||
publisher_key,
|
||||
@@ -156,13 +165,20 @@ void Publisher::SaveVideoVisit(
|
||||
const std::string& publisher_id,
|
||||
const type::VisitData& visit_data,
|
||||
uint64_t duration,
|
||||
const bool first_visit,
|
||||
uint64_t window_id,
|
||||
ledger::PublisherInfoCallback callback) {
|
||||
if (!ledger_->state()->GetPublisherAllowVideos()) {
|
||||
duration = 0;
|
||||
}
|
||||
|
||||
SaveVisit(publisher_id, visit_data, duration, window_id, callback);
|
||||
SaveVisit(
|
||||
publisher_id,
|
||||
visit_data,
|
||||
duration,
|
||||
first_visit,
|
||||
window_id,
|
||||
callback);
|
||||
}
|
||||
|
||||
type::ActivityInfoFilterPtr Publisher::CreateActivityFilter(
|
||||
@@ -191,7 +207,8 @@ void Publisher::OnSaveVisitServerPublisher(
|
||||
type::ServerPublisherInfoPtr server_info,
|
||||
const std::string& publisher_key,
|
||||
const type::VisitData& visit_data,
|
||||
uint64_t duration,
|
||||
const uint64_t duration,
|
||||
const bool first_visit,
|
||||
uint64_t window_id,
|
||||
const ledger::PublisherInfoCallback callback) {
|
||||
auto filter = CreateActivityFilter(
|
||||
@@ -215,6 +232,7 @@ void Publisher::OnSaveVisitServerPublisher(
|
||||
publisher_key,
|
||||
visit_data,
|
||||
duration,
|
||||
first_visit,
|
||||
window_id,
|
||||
callback,
|
||||
_1,
|
||||
@@ -254,7 +272,8 @@ void Publisher::SaveVisitInternal(
|
||||
const type::PublisherStatus status,
|
||||
const std::string& publisher_key,
|
||||
const type::VisitData& visit_data,
|
||||
uint64_t duration,
|
||||
const uint64_t duration,
|
||||
const bool first_visit,
|
||||
uint64_t window_id,
|
||||
const ledger::PublisherInfoCallback callback,
|
||||
type::Result result,
|
||||
@@ -269,9 +288,9 @@ void Publisher::SaveVisitInternal(
|
||||
|
||||
bool is_verified = IsConnectedOrVerified(status);
|
||||
|
||||
bool new_visit = false;
|
||||
bool new_publisher = false;
|
||||
if (!publisher_info) {
|
||||
new_visit = true;
|
||||
new_publisher = true;
|
||||
publisher_info = type::PublisherInfo::New();
|
||||
publisher_info->id = publisher_key;
|
||||
}
|
||||
@@ -319,7 +338,7 @@ void Publisher::SaveVisitInternal(
|
||||
bool verified_new = !allow_non_verified && !is_verified;
|
||||
bool verified_old = allow_non_verified || is_verified;
|
||||
|
||||
if (new_visit &&
|
||||
if (new_publisher &&
|
||||
(excluded ||
|
||||
!ledger_->state()->GetAutoContributeEnabled() ||
|
||||
min_duration_new ||
|
||||
@@ -335,7 +354,9 @@ void Publisher::SaveVisitInternal(
|
||||
ledger_->state()->GetAutoContributeEnabled() &&
|
||||
min_duration_ok &&
|
||||
verified_old) {
|
||||
publisher_info->visits += 1;
|
||||
if (first_visit) {
|
||||
publisher_info->visits += 1;
|
||||
}
|
||||
publisher_info->duration += duration;
|
||||
publisher_info->score += concaveScore(duration);
|
||||
publisher_info->reconcile_stamp = ledger_->state()->GetReconcileStamp();
|
||||
@@ -686,7 +707,7 @@ void Publisher::OnPanelPublisherInfo(
|
||||
_1,
|
||||
_2);
|
||||
|
||||
SaveVisit(visit_data.domain, visit_data, 0, windowId, callback);
|
||||
SaveVisit(visit_data.domain, visit_data, 0, true, windowId, callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,7 +816,8 @@ void Publisher::OnServerPublisherInfoLoaded(
|
||||
void Publisher::UpdateMediaDuration(
|
||||
const uint64_t window_id,
|
||||
const std::string& publisher_key,
|
||||
const uint64_t duration) {
|
||||
const uint64_t duration,
|
||||
const bool first_visit) {
|
||||
BLOG(1, "Media duration: " << duration);
|
||||
ledger_->database()->GetPublisherInfo(publisher_key,
|
||||
std::bind(&Publisher::OnGetPublisherInfoForUpdateMediaDuration,
|
||||
@@ -803,14 +825,16 @@ void Publisher::UpdateMediaDuration(
|
||||
_1,
|
||||
_2,
|
||||
window_id,
|
||||
duration));
|
||||
duration,
|
||||
first_visit));
|
||||
}
|
||||
|
||||
void Publisher::OnGetPublisherInfoForUpdateMediaDuration(
|
||||
type::Result result,
|
||||
type::PublisherInfoPtr info,
|
||||
const uint64_t window_id,
|
||||
const uint64_t duration) {
|
||||
const uint64_t duration,
|
||||
const bool first_visit) {
|
||||
if (result != type::Result::LEDGER_OK) {
|
||||
BLOG(0, "Failed to retrieve publisher info while updating media duration");
|
||||
return;
|
||||
@@ -826,6 +850,7 @@ void Publisher::OnGetPublisherInfoForUpdateMediaDuration(
|
||||
info->id,
|
||||
visit_data,
|
||||
duration,
|
||||
first_visit,
|
||||
0,
|
||||
[](type::Result, type::PublisherInfoPtr) {});
|
||||
}
|
||||
@@ -884,6 +909,7 @@ void Publisher::SavePublisherInfo(
|
||||
publisher_info->id,
|
||||
visit_data,
|
||||
0,
|
||||
true,
|
||||
window_id,
|
||||
[callback](auto result, type::PublisherInfoPtr publisher_info) {
|
||||
callback(result);
|
||||
|
||||
@@ -43,7 +43,8 @@ class Publisher {
|
||||
|
||||
void SaveVisit(const std::string& publisher_key,
|
||||
const type::VisitData& visit_data,
|
||||
const uint64_t& duration,
|
||||
const uint64_t duration,
|
||||
const bool first_visit,
|
||||
uint64_t window_id,
|
||||
const ledger::PublisherInfoCallback callback);
|
||||
|
||||
@@ -51,6 +52,7 @@ class Publisher {
|
||||
const std::string& publisher_id,
|
||||
const type::VisitData& visit_data,
|
||||
uint64_t duration,
|
||||
const bool first_visit,
|
||||
uint64_t window_id,
|
||||
ledger::PublisherInfoCallback callback);
|
||||
|
||||
@@ -99,7 +101,8 @@ class Publisher {
|
||||
void UpdateMediaDuration(
|
||||
const uint64_t window_id,
|
||||
const std::string& publisher_key,
|
||||
const uint64_t duration);
|
||||
const uint64_t duration,
|
||||
const bool first_visit);
|
||||
|
||||
void GetPublisherPanelInfo(
|
||||
const std::string& publisher_key,
|
||||
@@ -115,7 +118,8 @@ class Publisher {
|
||||
type::Result result,
|
||||
type::PublisherInfoPtr info,
|
||||
const uint64_t window_id,
|
||||
const uint64_t duration);
|
||||
const uint64_t duration,
|
||||
const bool first_visit);
|
||||
|
||||
void OnGetPanelPublisherInfo(
|
||||
const type::Result result,
|
||||
@@ -137,7 +141,8 @@ class Publisher {
|
||||
const type::PublisherStatus,
|
||||
const std::string& publisher_key,
|
||||
const type::VisitData& visit_data,
|
||||
uint64_t duration,
|
||||
const uint64_t duration,
|
||||
const bool first_visit,
|
||||
uint64_t window_id,
|
||||
const ledger::PublisherInfoCallback callback,
|
||||
type::Result result,
|
||||
@@ -147,7 +152,8 @@ class Publisher {
|
||||
type::ServerPublisherInfoPtr server_info,
|
||||
const std::string& publisher_key,
|
||||
const type::VisitData& visit_data,
|
||||
uint64_t duration,
|
||||
const uint64_t duration,
|
||||
const bool first_visit,
|
||||
uint64_t window_id,
|
||||
const ledger::PublisherInfoCallback callback);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user