This commit is contained in:
2021-06-10 18:43:14 +00:00
parent f67a6d3130
commit 49eeaba5f1
6 changed files with 45 additions and 34 deletions

View File

@@ -98,7 +98,7 @@ namespace AyaNova.Biz
if (Subscription.DeliveryMethod == NotifyDeliveryMethod.App)
await DeliverInApp(notifyevent, Subscription.AgeValue, ct);
else if (Subscription.DeliveryMethod == NotifyDeliveryMethod.SMTP)
await DeliverSMTP(notifyevent, Subscription.AgeValue, Subscription.DeliveryAddress, ct);
await DeliverSMTP(notifyevent, Subscription.AgeValue, Subscription.AdvanceNotice, Subscription.DeliveryAddress, ct);
}
}
}
@@ -128,7 +128,7 @@ namespace AyaNova.Biz
private static async Task DeliverSMTP(NotifyEvent ne, TimeSpan ageValue, string deliveryAddress, AyContext ct)
private static async Task DeliverSMTP(NotifyEvent ne, TimeSpan ageValue, TimeSpan advanceNotice, string deliveryAddress, AyContext ct)
{
try
{
@@ -143,23 +143,26 @@ namespace AyaNova.Biz
List<string> TranslationKeysToFetch = new List<string>();
TranslationKeysToFetch.Add(ne.AyaType.ToString());
TranslationKeysToFetch.Add("NotifySubscription");
TranslationKeysToFetch.Add("NotifySubscriptionLinkText");
if (ne.Name == "~SERVER~")
TranslationKeysToFetch.Add("Server");
var EventTypeTranslationKey = "NotifyEvent" + ne.EventType.ToString();
TranslationKeysToFetch.Add(EventTypeTranslationKey);
if (ageValue != TimeSpan.Zero)
if (ageValue != TimeSpan.Zero || ne.EventType == NotifyEventType.CustomerServiceImminent)
{
TranslationKeysToFetch.Add("TimeSpanDays");
TranslationKeysToFetch.Add("TimeSpanHours");
TranslationKeysToFetch.Add("TimeSpanMinutes");
TranslationKeysToFetch.Add("TimeSpanSeconds");
}
if (ne.EventType == NotifyEventType.CustomerServiceImminent)
TranslationKeysToFetch.Add("NotifyEventCustomerServiceImminentMessage");
//get translations
var transid = await ct.UserOptions.AsNoTracking().Where(x => x.UserId == ne.UserId).Select(x => x.TranslationId).FirstOrDefaultAsync();
var LT = await TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, transid);
var NotifySubscriptionTheWord = LT["NotifySubscription"];
var NotifySubscriptionLinkText = LT["NotifySubscriptionLinkText"];
var name = ne.Name;
if (name == "~SERVER~")
name = LT["Server"];
@@ -172,17 +175,6 @@ namespace AyaNova.Biz
//subscription name translation
var SubscriptionTypeName = LT[EventTypeTranslationKey];
string subject = "";
//Special notification handling
switch (ne.EventType)
{
case NotifyEventType.CustomerServiceImminent:
subject = SubscriptionTypeName;
break;
default:
subject = $"AY:{AyaTypeTranslated}:{name}:{SubscriptionTypeName}";
break;
}
//Age relevant notification
@@ -190,25 +182,37 @@ namespace AyaNova.Biz
if (ageValue != TimeSpan.Zero)
AgeDisplay = $"({AyaNova.Util.DateUtil.FormatTimeSpan(ageValue, LT["TimeSpanDays"], LT["TimeSpanHours"], LT["TimeSpanMinutes"], LT["TimeSpanSeconds"])})\n";
//var test=AyaNova.Util.DateUtil.FormatTimeSpan(new TimeSpan(2,3,4,5), LT["TimeSpanDays"], LT["TimeSpanHours"], LT["TimeSpanMinutes"], LT["TimeSpanSeconds"]);
string subject = "";
IMailer m = AyaNova.Util.ServiceProviderProvider.Mailer;
var body = "";
//NOTE: if need any other exemptions besides backup status make a separate static function "CanOpen(NotifyEventType)"
if (ne.ObjectId != 0 || ne.EventType == NotifyEventType.BackupStatus)
//Special notification handling
switch (ne.EventType)
{
body = $"{AgeDisplay}{AyaTypeTranslated}\n{OpenObjectUrlBuilder(ne.AyaType, ne.ObjectId, ne.EventType)}\n";
case NotifyEventType.CustomerServiceImminent:
subject = SubscriptionTypeName;
body = LT["NotifyEventCustomerServiceImminentMessage"].Replace("{0}", AyaNova.Util.DateUtil.FormatTimeSpan(advanceNotice, LT["TimeSpanDays"], LT["TimeSpanHours"], LT["TimeSpanMinutes"], LT["TimeSpanSeconds"]));
body += $"\n{OpenObjectUrlBuilder(ne.AyaType, ne.ObjectId, ne.EventType)}\n";
break;
default:
subject = $"AY:{AyaTypeTranslated}:{name}:{SubscriptionTypeName}";
if (ne.ObjectId != 0 || ne.EventType == NotifyEventType.BackupStatus)
{
body = $"{AgeDisplay}{AyaTypeTranslated}\n{OpenObjectUrlBuilder(ne.AyaType, ne.ObjectId, ne.EventType)}\n";
}
body += ne.Message;
break;
}
body += ne.Message;
//Add link to subscription
//Add link to subscription, all messages have this regardless of content
//http://localhost:8080/open/51/1 //add subscription link, notifysub is object type 51
if (!body.EndsWith('\n'))
body += "\n";
body += $"-----\n{NotifySubscriptionTheWord}\n{OpenSubscriptionUrlBuilder(ne.NotifySubscriptionId)}\n";
body += $"-----\n{NotifySubscriptionLinkText}\n{OpenSubscriptionUrlBuilder(ne.NotifySubscriptionId)}\n";
if (!ServerGlobalOpsSettingsCache.Notify.SmtpDeliveryActive)
{
@@ -216,9 +220,8 @@ namespace AyaNova.Biz
log.LogInformation($"** WARNING: SMTP notification is currently set to Active=False; unable to deliver email notification, re-routed to in-app notification instead [UserId={ne.UserId}, Notify subscription={ne.NotifySubscriptionId}]. Change this setting or have users remove email delivery notifications if this is permanent **");
}
else
{
await m.SendEmailAsync(deliveryAddress, subject, body, ServerGlobalOpsSettingsCache.Notify);
}
}
}
catch (Exception ex)