Skip to content

Commit 835f6a0

Browse files
Add pull refresh options.
1 parent 9c384a0 commit 835f6a0

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

sdk/Notifo.SDK/NotifoIO.ios.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ public static async Task DidReceiveNotificationRequestAsync(UNNotificationReques
3131
/// <summary>
3232
/// Method for pulling pending notifications.
3333
/// </summary>
34+
/// <param name="options">The options for handling the pending notifications pull refresh request.</param>
3435
/// <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)
3637
{
3738
if (Current is NotifoMobilePushImplementation notifoMobilePush)
3839
{
39-
await notifoMobilePush.DidReceivePullRefreshRequestAsync();
40+
await notifoMobilePush.DidReceivePullRefreshRequestAsync(options);
4041
}
4142
}
4243

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,29 @@ public async Task DidReceiveNotificationRequestAsync(UNNotificationRequest reque
4848
await EnrichNotificationContentAsync(bestAttemptContent, notification);
4949
}
5050

51-
public async Task DidReceivePullRefreshRequestAsync()
51+
public async Task DidReceivePullRefreshRequestAsync(PullRefreshOptions? options = null)
5252
{
53-
var notifications = await GetPendingNotificationsAsync();
53+
options ??= new PullRefreshOptions();
54+
55+
var notifications = await GetPendingNotificationsAsync(options.Take, options.Period);
5456

5557
foreach (var notification in notifications)
5658
{
57-
var eventArgs = new NotificationEventArgs(notification);
58-
OnReceived(eventArgs);
59+
if (options.RaiseEvent)
60+
{
61+
var eventArgs = new NotificationEventArgs(notification);
62+
OnReceived(eventArgs);
63+
}
5964

6065
if (notification.Silent)
6166
{
6267
continue;
6368
}
6469

65-
await ShowLocalNotificationAsync(notification);
70+
if (options.PresentNotification)
71+
{
72+
await ShowLocalNotificationAsync(notification);
73+
}
6674
}
6775

6876
await TrackNotificationsAsync(notifications);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,19 @@ private void UnsubscribeEventsFromCurrentProvider()
256256
receivedNotificationEvents.Clear();
257257
}
258258

259-
private async Task<ICollection<NotificationDto>> GetPendingNotificationsAsync()
259+
private async Task<ICollection<NotificationDto>> GetPendingNotificationsAsync(int take, TimeSpan period)
260260
{
261261
try
262262
{
263-
var allNotifications = await Notifications.GetNotificationsAsync();
263+
var allNotifications = await Notifications.GetNotificationsAsync(take: take);
264264
var seenNotifications = settings.GetSeenNotifications();
265+
266+
var utcNow = DateTimeOffset.UtcNow;
267+
265268
var pendingNotifications = allNotifications
266269
.Items
267270
.Where(x => !seenNotifications.Contains(x.Id))
271+
.Where(x => (utcNow - x.Created.UtcDateTime) <= period)
268272
.OrderBy(x => x.Created)
269273
.ToArray();
270274

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

0 commit comments

Comments
 (0)