Add queued email and Firebase push delivery
This commit is contained in:
1 parent
c96eb155ae
commit
599237dd2c
22 files changed
+497
-8
No files matched your search
@@ -5,7 +5,7 @@ namespace Helpdesk.Domain.Notifications;
|
||||
|
||||
public enum NotificationType { IssueCreated, IssueAssigned, IssueStatusChanged, IssueCommentAdded, IssueReopened, ProposalStatusChanged }
|
||||
public enum DeliveryChannel { Email, Push }
|
||||
public enum DeliveryStatus { Pending, Skipped }
|
||||
public enum DeliveryStatus { Pending, Sent, Failed, Skipped }
|
||||
|
||||
public sealed class Notification : IHasCreatedAt
|
||||
{
|
||||
@@ -46,6 +46,9 @@ public sealed class Notification : IHasCreatedAt
|
||||
public sealed class NotificationDelivery(
|
||||
Notification notification, DeliveryChannel channel, bool enabled, DateTime now)
|
||||
{
|
||||
private static readonly TimeSpan[] RetryDelays =
|
||||
[TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(30), TimeSpan.FromHours(2)];
|
||||
|
||||
private NotificationDelivery() : this(null!, default, false, default) { }
|
||||
|
||||
public int Id { get; private set; }
|
||||
@@ -53,11 +56,45 @@ public sealed class NotificationDelivery(
|
||||
public Notification Notification { get; private set; } = notification;
|
||||
public DeliveryChannel Channel { get; private set; } = channel;
|
||||
public DeliveryStatus Status { get; private set; } = enabled ? DeliveryStatus.Pending : DeliveryStatus.Skipped;
|
||||
public int AttemptCount { get; private set; }
|
||||
public DateTime? NextAttemptAt { get; private set; } = enabled ? now : null;
|
||||
public string? LastError { get; private set; }
|
||||
public DateTime? SentAt { get; private set; }
|
||||
|
||||
public void RecordSent(DateTime now)
|
||||
{
|
||||
AttemptCount++;
|
||||
Status = DeliveryStatus.Sent;
|
||||
SentAt = now;
|
||||
NextAttemptAt = null;
|
||||
LastError = null;
|
||||
}
|
||||
|
||||
public void RecordFailure(DateTime now, string reason, bool retryable)
|
||||
{
|
||||
AttemptCount++;
|
||||
LastError = reason;
|
||||
if (retryable && AttemptCount <= RetryDelays.Length)
|
||||
{
|
||||
NextAttemptAt = now + RetryDelays[AttemptCount - 1];
|
||||
return;
|
||||
}
|
||||
|
||||
Status = DeliveryStatus.Failed;
|
||||
NextAttemptAt = null;
|
||||
}
|
||||
|
||||
public void Skip()
|
||||
{
|
||||
Status = DeliveryStatus.Skipped;
|
||||
NextAttemptAt = null;
|
||||
LastError = null;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class PushDevice
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int UserId { get; private set; }
|
||||
public string FcmToken { get; private set; } = null!;
|
||||
}
|
||||
Reference in new issue
Block a user