File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed
sdk/Notifo.SDK/NotifoMobilePush Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ public async Task DidReceivePullRefreshRequestAsync(PullRefreshOptions? options
52
52
{
53
53
options ??= new PullRefreshOptions ( ) ;
54
54
55
+ // iOS does not maintain a queue of undelivered notifications, therefore we have to query here.
55
56
var notifications = await GetPendingNotificationsAsync ( options . Take , options . Period ) ;
56
57
57
58
foreach ( var notification in notifications )
@@ -89,6 +90,7 @@ private async Task<IEnumerable<UserNotificationDto>> GetPendingNotificationsAsyn
89
90
var currentSeen = await GetSeenNotificationsAsync ( ) ;
90
91
var currentTime = DateTimeOffset . UtcNow ;
91
92
93
+ // Only take the recent notifications into account (default: 3 days).
92
94
bool IsRecent ( DateTimeOffset date )
93
95
{
94
96
return ( currentTime - date . UtcDateTime ) <= maxAge ;
Original file line number Diff line number Diff line change @@ -53,13 +53,15 @@ public async Task TrackNotificationsAsync(params Guid[] ids)
53
53
{
54
54
var set = await LoadSeenNotificationsAsync ( ) ;
55
55
56
+ // Store the seen notifications immediately as a cache, if the actual command to the server fails.
56
57
await seenNotificationsStore . AddSeenNotificationIdsAsync ( Capacity , ids ) ;
57
58
58
59
foreach ( var id in ids )
59
60
{
60
61
set . Add ( id , Capacity ) ;
61
62
}
62
63
64
+ // Track all notifications with one HTTP request.
63
65
commandQueue . Run ( new TrackSeenCommand { Ids = ids . ToHashSet ( ) , Token = token } ) ;
64
66
}
65
67
catch ( Exception ex )
@@ -75,12 +77,8 @@ public async Task TrackNotificationsAsync(params Guid[] ids)
75
77
76
78
private async Task < SlidingSet < Guid > > LoadSeenNotificationsAsync ( )
77
79
{
78
- if ( seenNotifications == null )
79
- {
80
- seenNotifications = await seenNotificationsStore . GetSeenNotificationIdsAsync ( ) ;
81
- }
82
-
83
- return seenNotifications ;
80
+ // Only query the notifications once and then hold everything in-memory.
81
+ return seenNotifications ??= await seenNotificationsStore . GetSeenNotificationIdsAsync ( ) ;
84
82
}
85
83
}
86
84
}
You can’t perform that action at this time.
0 commit comments