@@ -190,39 +190,38 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
190190 // bool negativeAction = eventFlags & static_cast<uint8_t>(EventFlags::NegativeAction);
191191
192192 // If notification was removed, we remove it from the notifications map
193- if (ancsNotif.eventId == static_cast <uint8_t >(EventIds::Removed) && sessionNotificationUids.contains (ancsNotif.uuid )) {
194- sessionNotificationUids.erase (ancsNotif.uuid );
195- if (notifications.contains (ancsNotif.uuid )) {
196- notifications.erase (ancsNotif.uuid );
197- }
193+ if (ancsNotif.eventId == static_cast <uint8_t >(EventIds::Removed) && notifications.contains (ancsNotif.uuid )) {
194+ notifications.erase (ancsNotif.uuid );
198195 NRF_LOG_INFO (" ANCS Notification removed: %d" , ancsNotif.uuid );
199196 return ;
200197 }
201198
202199 // If the notification is pre-existing, or if it is a silent notification, we do not add it to the list
203- if (sessionNotificationUids.contains (ancsNotif.uuid )) {
200+ if (notifications.contains (ancsNotif.uuid ) ||
201+ (ancsNotif.eventFlags & static_cast <uint8_t >(EventFlags::Silent)) != 0 ||
202+ (ancsNotif.eventFlags & static_cast <uint8_t >(EventFlags::PreExisting)) != 0 ) {
204203 return ;
205204 }
206205
207- // If new notification, add it to the sessionNotificationUids
206+ // If new notification, add it to the notifications
208207 if (ancsNotif.eventId == static_cast <uint8_t >(EventIds::Added) && (ancsNotif.eventFlags & static_cast <uint8_t >(EventFlags::Silent)) == 0 ) {
209- sessionNotificationUids .insert ({ancsNotif.uuid , false });
208+ notifications .insert ({ancsNotif.uuid , ancsNotif });
210209 } else {
211210 // If the notification is not added, we ignore it
212211 NRF_LOG_INFO (" ANCS Notification not added, ignoring: %d" , ancsNotif.uuid );
213212 return ;
214213 }
215214
216215 // The 6 is from TotalNbNotifications in NotificationManager.h + 1
217- while (notifications.size () > 6 ) {
216+ while (notifications.size () > 100 ) {
218217 notifications.erase (notifications.begin ());
219218 }
220219
221- if (notifications.contains (ancsNotif.uuid )) {
222- notifications[ancsNotif.uuid ] = ancsNotif;
223- } else {
224- notifications.insert ({ancsNotif.uuid , ancsNotif});
225- }
220+ // if (notifications.contains(ancsNotif.uuid)) {
221+ // notifications[ancsNotif.uuid] = ancsNotif;
222+ // } else {
223+ // notifications.insert({ancsNotif.uuid, ancsNotif});
224+ // }
226225
227226 // Request ANCS more info
228227 // The +4 is for the "..." at the end of the string
@@ -262,8 +261,8 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
262261 ancsNotif.uuid = 0 ;
263262
264263 // Check if the notification is in the session
265- if (sessionNotificationUids .contains (notificationUid)) {
266- if (sessionNotificationUids [notificationUid]) {
264+ if (notifications .contains (notificationUid)) {
265+ if (notifications [notificationUid]. isProcessed ) {
267266 // If the notification is already processed, we ignore it
268267 NRF_LOG_INFO (" Notification with UID %d already processed, ignoring" , notificationUid);
269268 return ;
@@ -288,6 +287,9 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
288287
289288 std::string decodedMessage = DecodeUtf8String (event->notify_rx .om , messageSize, 8 + titleSize + 1 + 2 + subTitleSize + 1 + 2 );
290289
290+ // Debug event ids ands flags by putting them at front of message (in int format)
291+ // decodedMessage = std::to_string(ancsNotif.uuid) + " " + decodedMessage;
292+
291293 NRF_LOG_INFO (" Decoded Title: %s" , decodedTitle.c_str ());
292294 NRF_LOG_INFO (" Decoded SubTitle: %s" , decodedSubTitle.c_str ());
293295
@@ -363,13 +365,14 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
363365 }
364366 notificationManager.Push (std::move (notif));
365367
366- // Mark the notification as processed in the session
367- sessionNotificationUids[notificationUid] = true ;
368-
369- // Only ping the system task if the notification was added
370- if (ancsNotif.eventId == static_cast <uint8_t >(EventIds::Added) && (ancsNotif.eventFlags & static_cast <uint8_t >(EventFlags::Silent)) == 0 ) {
368+ // Only ping the system task if the notification was added and ignore pre-existing notifications
369+ if (ancsNotif.isProcessed == false && (ancsNotif.eventFlags & static_cast <uint8_t >(EventFlags::Silent)) == 0 &&
370+ (ancsNotif.eventFlags & static_cast <uint8_t >(EventFlags::PreExisting)) == 0 ) {
371371 systemTask.PushMessage (Pinetime::System::Messages::OnNewNotification);
372372 }
373+
374+ // Mark the notification as processed in the session
375+ notifications[notificationUid].isProcessed = true ;
373376 }
374377}
375378
@@ -441,7 +444,6 @@ void AppleNotificationCenterClient::Reset() {
441444 isDataDescriptorFound = false ;
442445
443446 notifications.clear ();
444- sessionNotificationUids.clear ();
445447}
446448
447449void AppleNotificationCenterClient::Discover (uint16_t connectionHandle, std::function<void (uint16_t )> onServiceDiscovered) {
0 commit comments