This commit is contained in:
@@ -97,28 +97,49 @@ namespace AyaNova.Biz
|
||||
|
||||
//All items have an event date, for non time delayed events it's just the moment it was created
|
||||
//which will predate this moment now if it's pre-existing
|
||||
var items = await ct.NotifyEvent.Include(z => z.NotifySubscription).ToListAsync();
|
||||
|
||||
var events = await ct.NotifyEvent.Include(z => z.NotifySubscription).ToListAsync();
|
||||
log.LogTrace($"Found {events.Count} NotifyEvents to examine for potential delivery");
|
||||
//iterate and deliver
|
||||
foreach(var item in items){
|
||||
//Time delayed ones:
|
||||
//when to deliver formula: NotifyEvent "EventDate"+NotifySubscription.AgeValue timespan - NotifySubscription AdvanceNotice timespan > utcNow
|
||||
if(item.)
|
||||
|
||||
//Immediate delivery items
|
||||
//
|
||||
if(item.EventDate)
|
||||
foreach (var notifyevent in events)
|
||||
{
|
||||
//TIME DELAYED AGED EVENT?
|
||||
//when to time delay deliver formula:If sub.agevalue!= timespan.zero then deliver on =
|
||||
//NotifyEvent "EventDate"+NotifySubscription.AgeValue timespan - NotifySubscription AdvanceNotice timespan > utcNow
|
||||
//Is it time delayed?
|
||||
if (notifyevent.NotifySubscription.AgeValue != TimeSpan.Zero)
|
||||
{
|
||||
var deliverAfter = notifyevent.EventDate + notifyevent.NotifySubscription.AgeValue - notifyevent.NotifySubscription.AdvanceNotice;
|
||||
if (deliverAfter > DateTime.UtcNow)
|
||||
{
|
||||
if (notifyevent.NotifySubscription.DeliveryMethod == NotifyDeliveryMethod.App)
|
||||
{
|
||||
await DeliverInApp(notifyevent, ct);
|
||||
}
|
||||
if (notifyevent.NotifySubscription.DeliveryMethod == NotifyDeliveryMethod.SMTP)
|
||||
{
|
||||
await DeliverSMTP(notifyevent, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//NORMAL IMMEDIATE DELIVERY EVENT
|
||||
if (notifyevent.NotifySubscription.DeliveryMethod == NotifyDeliveryMethod.App)
|
||||
{
|
||||
await DeliverInApp(notifyevent, ct);
|
||||
}
|
||||
if (notifyevent.NotifySubscription.DeliveryMethod == NotifyDeliveryMethod.SMTP)
|
||||
{
|
||||
await DeliverSMTP(notifyevent, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//turn notifyEvent records into notifications for in app and deliver smtp
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
log.LogError(ex, $"Error processing notification event");
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -129,6 +150,20 @@ namespace AyaNova.Biz
|
||||
|
||||
}
|
||||
|
||||
private static async Task DeliverInApp(NotifyEvent ne, AyContext ct)
|
||||
{
|
||||
log.LogTrace($"DeliverInApp deliving notify event: {ne}");
|
||||
await ct.Notification.AddAsync(new Notification() { UserId = ne.UserId, AyaType = ne.AyaType, ObjectId = ne.ObjectId, EventType = ne.EventType, NotifySubscriptionId = ne.NotifySubscriptionId, Message = ne.Message });
|
||||
ct.NotifyEvent.Remove(ne);
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private static async Task DeliverSMTP(NotifyEvent ne, AyContext ct)
|
||||
{
|
||||
log.LogTrace($"DeliverSMTP deliving notify event: {ne}");
|
||||
throw new System.NotImplementedException("DeliverSMTP: NOT IMPLEMENTED YET");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user