Skip to content

Commit

Permalink
Merge pull request #1436 from brave/send-pending-rewards-notifications
Browse files Browse the repository at this point in the history
Send pending rewards notifications after registering listener
  • Loading branch information
bridiver authored Jan 25, 2019
2 parents adf9ea8 + 2fa44ba commit afd51a3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class RewardsNotificationService {
};

typedef std::vector<RewardsNotification> RewardsNotificationsList;
typedef std::map<RewardsNotificationID, RewardsNotification>
RewardsNotificationsMap;

virtual void AddNotification(RewardsNotificationType type,
RewardsNotificationArgs args,
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,19 @@ 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);
}
OnGetAllNotifications(rewards_notifications_list);
}

const RewardsNotificationService::RewardsNotificationsMap&
RewardsNotificationServiceImpl::GetAllNotifications() const {
return rewards_notifications_;
}

RewardsNotificationServiceImpl::RewardsNotificationID
RewardsNotificationServiceImpl::GenerateRewardsNotificationID() const {
return base::StringPrintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<base::ListValue>);
Expand Down Expand Up @@ -75,7 +76,7 @@ class RewardsNotificationServiceImpl
RewardsNotificationTimestamp GenerateRewardsNotificationTimestamp() const;

Profile* profile_;
std::map<RewardsNotificationID, RewardsNotification> rewards_notifications_;
RewardsNotificationsMap rewards_notifications_;
std::vector<RewardsNotificationID> rewards_notifications_displayed_;
#if BUILDFLAG(ENABLE_EXTENSIONS)
std::unique_ptr<ExtensionRewardsNotificationServiceObserver>
Expand Down

0 comments on commit afd51a3

Please sign in to comment.