This commit is contained in:
@@ -327,7 +327,7 @@ Internal workings:
|
|||||||
One enum list of NotificationType for any possible notification that can be processed
|
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
|
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
|
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`
|
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
|
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
|
// 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);
|
var defaultsub = await ct.NotifySubscription.FirstOrDefaultAsync(z => z.EventType == NotifyEventType.GeneralNotification && z.UserId == userId && z.DeliveryMethod == NotifyDeliveryMethod.App);
|
||||||
if (defaultsub == null)
|
if (defaultsub == null)
|
||||||
@@ -42,7 +42,7 @@ namespace AyaNova.Biz
|
|||||||
await ct.NotifySubscription.AddAsync(defaultsub);
|
await ct.NotifySubscription.AddAsync(defaultsub);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
return defaultsub;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -325,8 +325,7 @@ namespace AyaNova.Biz
|
|||||||
using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext)
|
using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext)
|
||||||
{
|
{
|
||||||
|
|
||||||
//General notification goes to a specific user only
|
//General notification goes to one specific user only
|
||||||
//no need to consult subscriptions
|
|
||||||
if (eventType == NotifyEventType.GeneralNotification)
|
if (eventType == NotifyEventType.GeneralNotification)
|
||||||
{
|
{
|
||||||
if (userId == 0)
|
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();
|
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
|
//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))
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
{
|
|
||||||
name = UserName;
|
name = UserName;
|
||||||
}
|
|
||||||
|
|
||||||
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = userId, Message = message, NotifySubscriptionId = defaultsub.Id, Name = name };
|
var gensubs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.GeneralNotification && z.UserId == userId).ToListAsync();
|
||||||
await ct.NotifyEvent.AddAsync(n);
|
foreach (var sub in gensubs)
|
||||||
await ct.SaveChangesAsync();
|
{
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -493,7 +493,6 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
bool isNew = currentObj == null;
|
bool isNew = currentObj == null;
|
||||||
|
|
||||||
|
|
||||||
//STANDARD EVENTS FOR ALL OBJECTS
|
//STANDARD EVENTS FOR ALL OBJECTS
|
||||||
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
|
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)
|
//it not completed yet and not overdue already (which could indicate an import or something)
|
||||||
if (r.CompletedDate == null && r.DueDate > DateTime.UtcNow)
|
if (r.CompletedDate == null && r.DueDate > DateTime.UtcNow)
|
||||||
{
|
{
|
||||||
var userNotifySub = await NotifyEventHelper.EnsureDefaultInAppUserNotificationSubscriptionExists(r.UserId, ct);
|
//Notify user
|
||||||
NotifySubscription supervisorNotifySub = null;
|
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)
|
if (r.UserId != r.AssignedByUserId)
|
||||||
{
|
{
|
||||||
supervisorNotifySub = await NotifyEventHelper.EnsureDefaultInAppUserNotificationSubscriptionExists(r.AssignedByUserId, ct);
|
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)
|
||||||
{
|
|
||||||
var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.UserId);
|
|
||||||
|
|
||||||
NotifyEvent n = new NotifyEvent()
|
|
||||||
{
|
{
|
||||||
EventType = NotifyEventType.GeneralNotification,
|
var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.AssignedByUserId);
|
||||||
UserId = r.UserId,
|
NotifyEvent n = new NotifyEvent()
|
||||||
ObjectId = proposedObj.Id,
|
{
|
||||||
AyaType = AyaType.Review,
|
EventType = NotifyEventType.GeneralNotification,
|
||||||
NotifySubscriptionId = userNotifySub.Id,
|
UserId = r.AssignedByUserId,
|
||||||
Name = $"{eventNameTranslated} - {proposedObj.Name}",
|
ObjectId = proposedObj.Id,
|
||||||
EventDate = r.DueDate
|
AyaType = AyaType.Review,
|
||||||
};
|
NotifySubscriptionId = sub.Id,
|
||||||
await ct.NotifyEvent.AddAsync(n);
|
Name = $"{eventNameTranslated} - {proposedObj.Name}",
|
||||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
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
|
}//overdue event
|
||||||
}//custom events for created / modified
|
}//custom events for created / modified
|
||||||
|
|||||||
Reference in New Issue
Block a user