This commit is contained in:
@@ -327,7 +327,7 @@ Internal workings:
|
||||
One enum list of NotificationType for any possible notification that can be processed
|
||||
Notify type is divided by actual type and then by actual delivery method
|
||||
No delivery schedule anymore, let user decide how to handle at their device end, not our concern, just deliver immediately always
|
||||
Notify BEfore shoudl support multiple time frames, not just one
|
||||
Notify BEfore should support multiple time frames, not just one
|
||||
Users not involved should not be notified, have choice on that`
|
||||
e.g. if a user is not booked on a workorder and is just a lowly tech they don't care about other workorder status changes
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace AyaNova.Biz
|
||||
// ENSURE USER HAS IN APP NOTIFICATION
|
||||
//
|
||||
//
|
||||
public static async Task<NotifySubscription> EnsureDefaultInAppUserNotificationSubscriptionExists(long userId, AyContext ct)
|
||||
public static async Task EnsureDefaultInAppUserNotificationSubscriptionExists(long userId, AyContext ct)
|
||||
{
|
||||
var defaultsub = await ct.NotifySubscription.FirstOrDefaultAsync(z => z.EventType == NotifyEventType.GeneralNotification && z.UserId == userId && z.DeliveryMethod == NotifyDeliveryMethod.App);
|
||||
if (defaultsub == null)
|
||||
@@ -42,7 +42,7 @@ namespace AyaNova.Biz
|
||||
await ct.NotifySubscription.AddAsync(defaultsub);
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
return defaultsub;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -325,8 +325,7 @@ namespace AyaNova.Biz
|
||||
using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext)
|
||||
{
|
||||
|
||||
//General notification goes to a specific user only
|
||||
//no need to consult subscriptions
|
||||
//General notification goes to one specific user only
|
||||
if (eventType == NotifyEventType.GeneralNotification)
|
||||
{
|
||||
if (userId == 0)
|
||||
@@ -340,16 +339,19 @@ namespace AyaNova.Biz
|
||||
var UserName = await ct.User.AsNoTracking().Where(z => z.Id == userId).Select(z => z.Name).FirstOrDefaultAsync();
|
||||
|
||||
//if they don't have a regular inapp subscription create one now
|
||||
NotifySubscription defaultsub = await EnsureDefaultInAppUserNotificationSubscriptionExists(userId, ct);
|
||||
await EnsureDefaultInAppUserNotificationSubscriptionExists(userId, ct);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
name = UserName;
|
||||
}
|
||||
|
||||
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = userId, Message = message, NotifySubscriptionId = defaultsub.Id, Name = name };
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
await ct.SaveChangesAsync();
|
||||
var gensubs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.GeneralNotification && z.UserId == userId).ToListAsync();
|
||||
foreach (var sub in gensubs)
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = userId, Message = message, NotifySubscriptionId = sub.Id, Name = name };
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
}
|
||||
if (gensubs.Count > 0)
|
||||
await ct.SaveChangesAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -493,7 +493,6 @@ namespace AyaNova.Biz
|
||||
|
||||
bool isNew = currentObj == null;
|
||||
|
||||
|
||||
//STANDARD EVENTS FOR ALL OBJECTS
|
||||
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
|
||||
|
||||
@@ -513,47 +512,54 @@ namespace AyaNova.Biz
|
||||
//it not completed yet and not overdue already (which could indicate an import or something)
|
||||
if (r.CompletedDate == null && r.DueDate > DateTime.UtcNow)
|
||||
{
|
||||
var userNotifySub = await NotifyEventHelper.EnsureDefaultInAppUserNotificationSubscriptionExists(r.UserId, ct);
|
||||
NotifySubscription supervisorNotifySub = null;
|
||||
//Notify user
|
||||
await NotifyEventHelper.EnsureDefaultInAppUserNotificationSubscriptionExists(r.UserId, ct);
|
||||
{
|
||||
var gensubs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.GeneralNotification && z.UserId == r.UserId).ToListAsync();
|
||||
foreach (var sub in gensubs)
|
||||
{
|
||||
var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.UserId);
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.GeneralNotification,
|
||||
UserId = r.UserId,
|
||||
ObjectId = proposedObj.Id,
|
||||
AyaType = AyaType.Review,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
Name = $"{eventNameTranslated} - {proposedObj.Name}",
|
||||
EventDate = r.DueDate
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
}
|
||||
if (gensubs.Count > 0)
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
|
||||
//Notify supervisor
|
||||
if (r.UserId != r.AssignedByUserId)
|
||||
{
|
||||
supervisorNotifySub = await NotifyEventHelper.EnsureDefaultInAppUserNotificationSubscriptionExists(r.AssignedByUserId, ct);
|
||||
}
|
||||
|
||||
{
|
||||
var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.UserId);
|
||||
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
await NotifyEventHelper.EnsureDefaultInAppUserNotificationSubscriptionExists(r.AssignedByUserId, ct);
|
||||
var gensubs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.GeneralNotification && z.UserId == r.AssignedByUserId).ToListAsync();
|
||||
foreach (var sub in gensubs)
|
||||
{
|
||||
EventType = NotifyEventType.GeneralNotification,
|
||||
UserId = r.UserId,
|
||||
ObjectId = proposedObj.Id,
|
||||
AyaType = AyaType.Review,
|
||||
NotifySubscriptionId = userNotifySub.Id,
|
||||
Name = $"{eventNameTranslated} - {proposedObj.Name}",
|
||||
EventDate = r.DueDate
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.AssignedByUserId);
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.GeneralNotification,
|
||||
UserId = r.AssignedByUserId,
|
||||
ObjectId = proposedObj.Id,
|
||||
AyaType = AyaType.Review,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
Name = $"{eventNameTranslated} - {proposedObj.Name}",
|
||||
EventDate = r.DueDate
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
}
|
||||
if (gensubs.Count > 0)
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
|
||||
if (supervisorNotifySub != null)
|
||||
{
|
||||
var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.AssignedByUserId);
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.GeneralNotification,
|
||||
UserId = r.AssignedByUserId,
|
||||
ObjectId = proposedObj.Id,
|
||||
AyaType = AyaType.Review,
|
||||
NotifySubscriptionId = supervisorNotifySub.Id,
|
||||
Name = $"{eventNameTranslated} - {proposedObj.Name}",
|
||||
EventDate = r.DueDate
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
}
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}//overdue event
|
||||
}//custom events for created / modified
|
||||
|
||||
Reference in New Issue
Block a user