Skip to content

Commit

Permalink
Merge pull request #2371 from brave/fix-4180
Browse files Browse the repository at this point in the history
Ads first launch notification timer no longer fires after notification dismissal
  • Loading branch information
ryanml authored May 7, 2019
2 parents af57319 + 6234b9b commit ce56ba1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions components/brave_ads/browser/ads_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ void AdsServiceFactory::RegisterProfilePrefs(
registry->RegisterBooleanPref(
prefs::kBraveAdShouldShowFirstLaunchNotification,
true);
registry->RegisterBooleanPref(
prefs::kBraveAdsHasRemovedFirstLaunchNotification,
false);

auto now = static_cast<uint64_t>(
(base::Time::Now() - base::Time()).InSeconds());
Expand Down
17 changes: 16 additions & 1 deletion components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ void AdsServiceImpl::MaybeShowFirstLaunchNotification() {
!ShouldShowFirstLaunchNotification() ||
!profile_->GetPrefs()->GetBoolean(
brave_rewards::prefs::kBraveRewardsEnabled)) {
StartFirstLaunchNotificationTimer();
MaybeStartFirstLaunchNotificationTimer();
return;
}

Expand Down Expand Up @@ -471,6 +471,9 @@ void AdsServiceImpl::RemoveFirstLaunchNotification() {
rewards_service->GetNotificationService();
rewards_notification_service->DeleteNotification(
kRewardsNotificationAdsLaunch);

profile_->GetPrefs()->SetBoolean(
prefs::kBraveAdsHasRemovedFirstLaunchNotification, true);
}

void AdsServiceImpl::ShowFirstLaunchNotification() {
Expand All @@ -489,6 +492,18 @@ void AdsServiceImpl::ShowFirstLaunchNotification() {
prefs::kBraveAdShouldShowFirstLaunchNotification, false);
}

void AdsServiceImpl::MaybeStartFirstLaunchNotificationTimer() {
bool has_removed_notification =
profile_->GetPrefs()->GetBoolean(
prefs::kBraveAdsHasRemovedFirstLaunchNotification);

if (has_removed_notification) {
return;
}

StartFirstLaunchNotificationTimer();
}

void AdsServiceImpl::StartFirstLaunchNotificationTimer() {
uint64_t timer_offset_in_seconds;

Expand Down
1 change: 1 addition & 0 deletions components/brave_ads/browser/ads_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class AdsServiceImpl : public AdsService,
bool ShouldShowFirstLaunchNotification();
void RemoveFirstLaunchNotification();
void ShowFirstLaunchNotification();
void MaybeStartFirstLaunchNotificationTimer();
void StartFirstLaunchNotificationTimer();
uint64_t GetFirstLaunchNotificationTimeout();
uint64_t GetFirstLaunchNotificationTimerOffset();
Expand Down
2 changes: 2 additions & 0 deletions components/brave_ads/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const char kBraveAdShouldShowFirstLaunchNotification[] =
"brave.brave_ads.should_show_first_launch_notification";
const char kBraveAdsLaunchNotificationTimestamp[] =
"brave.brave_ads.launch_notification_timestamp";
const char kBraveAdsHasRemovedFirstLaunchNotification[] =
"brave.brave_ads.has_removed_first_launch_notification";

const int kBraveAdsPrefsDefaultVersion = 1;
const int kBraveAdsPrefsCurrentVersion = 2;
Expand Down
1 change: 1 addition & 0 deletions components/brave_ads/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern const char kBraveAdsIdleThreshold[];

extern const char kBraveAdShouldShowFirstLaunchNotification[];
extern const char kBraveAdsLaunchNotificationTimestamp[];
extern const char kBraveAdsHasRemovedFirstLaunchNotification[];

extern const int kBraveAdsPrefsDefaultVersion;
extern const int kBraveAdsPrefsCurrentVersion;
Expand Down

0 comments on commit ce56ba1

Please sign in to comment.