File tree Expand file tree Collapse file tree 4 files changed +59
-9
lines changed Expand file tree Collapse file tree 4 files changed +59
-9
lines changed Original file line number Diff line number Diff line change @@ -31,12 +31,13 @@ public static async Task DidReceiveNotificationRequestAsync(UNNotificationReques
31
31
/// <summary>
32
32
/// Method for pulling pending notifications.
33
33
/// </summary>
34
+ /// <param name="options">The options for handling the pending notifications pull refresh request.</param>
34
35
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
35
- public static async Task DidReceivePullRefreshRequestAsync ( )
36
+ public static async Task DidReceivePullRefreshRequestAsync ( PullRefreshOptions ? options = null )
36
37
{
37
38
if ( Current is NotifoMobilePushImplementation notifoMobilePush )
38
39
{
39
- await notifoMobilePush . DidReceivePullRefreshRequestAsync ( ) ;
40
+ await notifoMobilePush . DidReceivePullRefreshRequestAsync ( options ) ;
40
41
}
41
42
}
42
43
Original file line number Diff line number Diff line change @@ -48,21 +48,29 @@ public async Task DidReceiveNotificationRequestAsync(UNNotificationRequest reque
48
48
await EnrichNotificationContentAsync ( bestAttemptContent , notification ) ;
49
49
}
50
50
51
- public async Task DidReceivePullRefreshRequestAsync ( )
51
+ public async Task DidReceivePullRefreshRequestAsync ( PullRefreshOptions ? options = null )
52
52
{
53
- var notifications = await GetPendingNotificationsAsync ( ) ;
53
+ options ??= new PullRefreshOptions ( ) ;
54
+
55
+ var notifications = await GetPendingNotificationsAsync ( options . Take , options . Period ) ;
54
56
55
57
foreach ( var notification in notifications )
56
58
{
57
- var eventArgs = new NotificationEventArgs ( notification ) ;
58
- OnReceived ( eventArgs ) ;
59
+ if ( options . RaiseEvent )
60
+ {
61
+ var eventArgs = new NotificationEventArgs ( notification ) ;
62
+ OnReceived ( eventArgs ) ;
63
+ }
59
64
60
65
if ( notification . Silent )
61
66
{
62
67
continue ;
63
68
}
64
69
65
- await ShowLocalNotificationAsync ( notification ) ;
70
+ if ( options . PresentNotification )
71
+ {
72
+ await ShowLocalNotificationAsync ( notification ) ;
73
+ }
66
74
}
67
75
68
76
await TrackNotificationsAsync ( notifications ) ;
Original file line number Diff line number Diff line change @@ -256,15 +256,19 @@ private void UnsubscribeEventsFromCurrentProvider()
256
256
receivedNotificationEvents . Clear ( ) ;
257
257
}
258
258
259
- private async Task < ICollection < NotificationDto > > GetPendingNotificationsAsync ( )
259
+ private async Task < ICollection < NotificationDto > > GetPendingNotificationsAsync ( int take , TimeSpan period )
260
260
{
261
261
try
262
262
{
263
- var allNotifications = await Notifications . GetNotificationsAsync ( ) ;
263
+ var allNotifications = await Notifications . GetNotificationsAsync ( take : take ) ;
264
264
var seenNotifications = settings . GetSeenNotifications ( ) ;
265
+
266
+ var utcNow = DateTimeOffset . UtcNow ;
267
+
265
268
var pendingNotifications = allNotifications
266
269
. Items
267
270
. Where ( x => ! seenNotifications . Contains ( x . Id ) )
271
+ . Where ( x => ( utcNow - x . Created . UtcDateTime ) <= period )
268
272
. OrderBy ( x => x . Created )
269
273
. ToArray ( ) ;
270
274
Original file line number Diff line number Diff line change
1
+ // ==========================================================================
2
+ // Notifo.io
3
+ // ==========================================================================
4
+ // Copyright (c) Sebastian Stehle
5
+ // All rights reserved. Licensed under the MIT license.
6
+ // ==========================================================================
7
+
8
+ using System ;
9
+
10
+ namespace Notifo . SDK
11
+ {
12
+ /// <summary>
13
+ /// Options for handling the pending notifications pull refresh request.
14
+ /// </summary>
15
+ public class PullRefreshOptions
16
+ {
17
+ /// <summary>
18
+ /// The pull refresh request should raise the received event. Default: true.
19
+ /// </summary>
20
+ public bool RaiseEvent { get ; set ; } = true ;
21
+
22
+ /// <summary>
23
+ /// The pull refresh request should present a local notification. Default: true.
24
+ /// </summary>
25
+ public bool PresentNotification { get ; set ; } = true ;
26
+
27
+ /// <summary>
28
+ /// The pull refresh request pending notifications period. Default: 3 days.
29
+ /// </summary>
30
+ public TimeSpan Period { get ; set ; } = TimeSpan . FromDays ( 3 ) ;
31
+
32
+ /// <summary>
33
+ /// The pull refresh request pending notifications limit. Default: 20.
34
+ /// </summary>
35
+ public int Take { get ; set ; } = 20 ;
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments