This commit is contained in:
2020-12-24 23:04:32 +00:00
parent eddf7189b9
commit cbab5f21f4
6 changed files with 59 additions and 9 deletions

View File

@@ -108,12 +108,12 @@ 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 events = await ct.NotifyEvent.Include(z => z.NotifySubscription).ToListAsync();
var events = await ct.NotifyEvent.Include(z => z.User).Include(z => z.NotifySubscription).AsNoTracking().ToListAsync();
log.LogTrace($"Found {events.Count} NotifyEvents to examine for potential delivery");
//cache translations
//Get all subscription unique userId's that aren't inapp deliveries
var usersNeedingTranslations = events.Where(z => z.NotifySubscription.DeliveryMethod != NotifyDeliveryMethod.App).Select(z => z.NotifySubscription.UserId).ToList().Distinct();
var usersNeedingTranslations = events.Where(z => z.NotifySubscription.DeliveryMethod != NotifyDeliveryMethod.App && z.User.Active).Select(z => z.NotifySubscription.UserId).ToList().Distinct();
foreach (long userid in usersNeedingTranslations)
{
long transId = (await ct.UserOptions.SingleAsync(z => z.UserId == userid)).TranslationId;
@@ -126,6 +126,14 @@ namespace AyaNova.Biz
//iterate and deliver
foreach (var notifyevent in events)
{
//no notifications for inactive users, just delete it as if it was delivered
if (!notifyevent.User.Active)
{
log.LogTrace($"Inactive user {notifyevent.User.Name}, removing notify rather than delivering it: {notifyevent}");
ct.NotifyEvent.Remove(notifyevent);
await ct.SaveChangesAsync();
continue;
}
//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
@@ -150,7 +158,7 @@ namespace AyaNova.Biz
}
else
{
//COULD BE TIME DELAYED BUT WITHOUT AGE, i.e. EventDate takes precedence?
//NORMAL IMMEDIATE DELIVERY EVENT
@@ -249,15 +257,15 @@ namespace AyaNova.Biz
if (ne.ObjectId != 0 || ne.EventType == NotifyEventType.BackupStatus)
{
body = OpenObjectUrlBuilder(ne.AyaType, ne.ObjectId, ne.EventType) + "\n";
body = OpenObjectUrlBuilder(ne.AyaType, ne.ObjectId, ne.EventType) + "\n";
}
body += ne.Message;
//Add link to subscription
//http://localhost:8080/open/51/1 //add subscription link, notifysub is object type 51
if (!body.EndsWith('\n'))
body += "\n";
if (!body.EndsWith('\n'))
body += "\n";
body += $"-----\n({SubscriptionTypeName}: {OpenSubscriptionUrlBuilder(ne.NotifySubscriptionId)} )\n";
if (!ServerGlobalOpsSettingsCache.Notify.SmtpDeliveryActive)
@@ -369,7 +377,7 @@ namespace AyaNova.Biz
return "OPS ERROR NO SERVER URL CONFIGURED";
}
ServerUrl = ServerUrl.Trim().TrimEnd('/');
//default is to open the object in question directly
return $"{ServerUrl}/open/{(int)AyaType.NotifySubscription}/{id}";
}