diff --git a/components/brave_rewards/browser/rewards_notification_service.cc b/components/brave_rewards/browser/rewards_notification_service.cc index 16a0f1fb6d5..3cecd1c937f 100644 --- a/components/brave_rewards/browser/rewards_notification_service.cc +++ b/components/brave_rewards/browser/rewards_notification_service.cc @@ -29,6 +29,12 @@ RewardsNotificationService::RewardsNotification::~RewardsNotification() {} void RewardsNotificationService::AddObserver( RewardsNotificationServiceObserver* observer) { + // Send any pending notifications immediately. + RewardsNotificationsMap notifications = GetAllNotifications(); + for (auto& notification : notifications) { + observer->OnNotificationAdded(this, notification.second); + } + observers_.AddObserver(observer); } diff --git a/components/brave_rewards/browser/rewards_notification_service.h b/components/brave_rewards/browser/rewards_notification_service.h index f16b4e92292..3c882fd52f3 100644 --- a/components/brave_rewards/browser/rewards_notification_service.h +++ b/components/brave_rewards/browser/rewards_notification_service.h @@ -48,6 +48,8 @@ class RewardsNotificationService { }; typedef std::vector RewardsNotificationsList; + typedef std::map + RewardsNotificationsMap; virtual void AddNotification(RewardsNotificationType type, RewardsNotificationArgs args, @@ -56,8 +58,8 @@ class RewardsNotificationService { virtual void DeleteNotification(RewardsNotificationID id) = 0; virtual void DeleteAllNotifications() = 0; virtual void GetNotification(RewardsNotificationID id) = 0; - virtual void GetAllNotifications() = 0; - + virtual void GetNotifications() = 0; + virtual const RewardsNotificationsMap& GetAllNotifications() const = 0; virtual void ReadRewardsNotificationsJSON() = 0; virtual void StoreRewardsNotifications() = 0; diff --git a/components/brave_rewards/browser/rewards_notification_service_impl.cc b/components/brave_rewards/browser/rewards_notification_service_impl.cc index 70ed56c3b3c..f1c32e41ca4 100644 --- a/components/brave_rewards/browser/rewards_notification_service_impl.cc +++ b/components/brave_rewards/browser/rewards_notification_service_impl.cc @@ -102,7 +102,7 @@ void RewardsNotificationServiceImpl::GetNotification(RewardsNotificationID id) { OnGetNotification(rewards_notifications_[id]); } -void RewardsNotificationServiceImpl::GetAllNotifications() { +void RewardsNotificationServiceImpl::GetNotifications() { RewardsNotificationsList rewards_notifications_list; for (auto& item : rewards_notifications_) { rewards_notifications_list.push_back(item.second); @@ -110,6 +110,11 @@ void RewardsNotificationServiceImpl::GetAllNotifications() { OnGetAllNotifications(rewards_notifications_list); } +const RewardsNotificationService::RewardsNotificationsMap& +RewardsNotificationServiceImpl::GetAllNotifications() const { + return rewards_notifications_; +} + RewardsNotificationServiceImpl::RewardsNotificationID RewardsNotificationServiceImpl::GenerateRewardsNotificationID() const { return base::StringPrintf( diff --git a/components/brave_rewards/browser/rewards_notification_service_impl.h b/components/brave_rewards/browser/rewards_notification_service_impl.h index f4f4290c8f7..8eaaa222771 100644 --- a/components/brave_rewards/browser/rewards_notification_service_impl.h +++ b/components/brave_rewards/browser/rewards_notification_service_impl.h @@ -34,7 +34,8 @@ class RewardsNotificationServiceImpl void DeleteNotification(RewardsNotificationID id) override; void DeleteAllNotifications() override; void GetNotification(RewardsNotificationID id) override; - void GetAllNotifications() override; + void GetNotifications() override; + const RewardsNotificationsMap& GetAllNotifications() const override; void ReadRewardsNotificationsJSON() override; void ReadRewardsNotifications(std::unique_ptr); @@ -75,7 +76,7 @@ class RewardsNotificationServiceImpl RewardsNotificationTimestamp GenerateRewardsNotificationTimestamp() const; Profile* profile_; - std::map rewards_notifications_; + RewardsNotificationsMap rewards_notifications_; std::vector rewards_notifications_displayed_; #if BUILDFLAG(ENABLE_EXTENSIONS) std::unique_ptr