Skip to content

Commit 0ca092b

Browse files
Always load seen notification ids.
1 parent b644e28 commit 0ca092b

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.tracking.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ internal sealed partial class NotifoMobilePushImplementation
1919
{
2020
private const int Capacity = 500;
2121
private readonly SemaphoreSlim semaphoreSlim = new (1);
22-
private SlidingSet<Guid>? seenNotifications;
2322

2423
public async Task<HashSet<Guid>> GetSeenNotificationsAsync()
2524
{
2625
await semaphoreSlim.WaitAsync();
2726
try
2827
{
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();
3030

31-
return set.ToHashSet();
31+
return loaded.ToHashSet();
3232
}
3333
catch (Exception ex)
3434
{
@@ -51,14 +51,15 @@ public async Task TrackNotificationsAsync(params Guid[] ids)
5151
await semaphoreSlim.WaitAsync();
5252
try
5353
{
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();
5556

5657
// Store the seen notifications immediately as a cache, if the actual command to the server fails.
5758
await seenNotificationsStore.AddSeenNotificationIdsAsync(Capacity, ids);
5859

5960
foreach (var id in ids)
6061
{
61-
set.Add(id, Capacity);
62+
loaded.Add(id, Capacity);
6263
}
6364

6465
// Track all notifications with one HTTP request.
@@ -74,11 +75,5 @@ public async Task TrackNotificationsAsync(params Guid[] ids)
7475
semaphoreSlim.Release();
7576
}
7677
}
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-
}
8378
}
8479
}

sdk/Notifo.SDK/NotifoMobilePush/TrackSeenCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal sealed class TrackSeenCommand : ICommand
1919
{
2020
public HashSet<Guid> Ids { get; set; }
2121

22-
public string Token { get; set; }
22+
public string? Token { get; set; }
2323

2424
public async ValueTask ExecuteAsync(
2525
CancellationToken ct)

0 commit comments

Comments
 (0)