@@ -19,16 +19,16 @@ internal sealed partial class NotifoMobilePushImplementation
19
19
{
20
20
private const int Capacity = 500 ;
21
21
private readonly SemaphoreSlim semaphoreSlim = new ( 1 ) ;
22
- private SlidingSet < Guid > ? seenNotifications ;
23
22
24
23
public async Task < HashSet < Guid > > GetSeenNotificationsAsync ( )
25
24
{
26
25
await semaphoreSlim . WaitAsync ( ) ;
27
26
try
28
27
{
29
- var set = await LoadSeenNotificationsAsync ( ) ;
28
+ // Always load the notifications from the preferences, because they could have been modified by the service extension.
29
+ var loaded = await seenNotificationsStore . GetSeenNotificationIdsAsync ( ) ;
30
30
31
- return set . ToHashSet ( ) ;
31
+ return loaded . ToHashSet ( ) ;
32
32
}
33
33
catch ( Exception ex )
34
34
{
@@ -51,14 +51,15 @@ public async Task TrackNotificationsAsync(params Guid[] ids)
51
51
await semaphoreSlim . WaitAsync ( ) ;
52
52
try
53
53
{
54
- var set = await LoadSeenNotificationsAsync ( ) ;
54
+ // Always load the notifications from the preferences, because they could have been modified by the service extension.
55
+ var loaded = await seenNotificationsStore . GetSeenNotificationIdsAsync ( ) ;
55
56
56
57
// Store the seen notifications immediately as a cache, if the actual command to the server fails.
57
58
await seenNotificationsStore . AddSeenNotificationIdsAsync ( Capacity , ids ) ;
58
59
59
60
foreach ( var id in ids )
60
61
{
61
- set . Add ( id , Capacity ) ;
62
+ loaded . Add ( id , Capacity ) ;
62
63
}
63
64
64
65
// Track all notifications with one HTTP request.
@@ -74,11 +75,5 @@ public async Task TrackNotificationsAsync(params Guid[] ids)
74
75
semaphoreSlim . Release ( ) ;
75
76
}
76
77
}
77
-
78
- private async Task < SlidingSet < Guid > > LoadSeenNotificationsAsync ( )
79
- {
80
- // Only query the notifications once and then hold everything in-memory.
81
- return seenNotifications ??= await seenNotificationsStore . GetSeenNotificationIdsAsync ( ) ;
82
- }
83
78
}
84
79
}
0 commit comments