Skip to content

Commit 55313dc

Browse files
committed
CU-8687aj3gt Added logic for department code in Notification pushes
1 parent c376755 commit 55313dc

File tree

10 files changed

+45
-30
lines changed

10 files changed

+45
-30
lines changed

Core/Resgrid.Model/Services/ICommunicationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Task<bool> SendUnitCallAsync(Call call, CallDispatchUnit dispatch, string depart
5555
/// <param name="title">The title.</param>
5656
/// <param name="profile">The profile.</param>
5757
/// <returns>Task&lt;System.Boolean&gt;.</returns>
58-
Task<bool> SendNotificationAsync(string userId, int departmentId, string message, string departmentNumber,
58+
Task<bool> SendNotificationAsync(string userId, int departmentId, string message, string departmentNumber, Department department,
5959
string title = "Notification", UserProfile profile = null);
6060

6161
/// <summary>

Core/Resgrid.Services/CalendarService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ public async Task<bool> NotifyNewCalendarItemAsync(CalendarItem calendarItem)
487487
foreach (var member in group.Members)
488488
{
489489
if (profiles.ContainsKey(member.UserId))
490-
await _communicationService.SendNotificationAsync(member.UserId, calendarItem.DepartmentId, message, departmentNumber, title, profiles[member.UserId]);
490+
await _communicationService.SendNotificationAsync(member.UserId, calendarItem.DepartmentId, message, departmentNumber, department, title, profiles[member.UserId]);
491491
else
492-
await _communicationService.SendNotificationAsync(member.UserId, calendarItem.DepartmentId, message, departmentNumber, title, null);
492+
await _communicationService.SendNotificationAsync(member.UserId, calendarItem.DepartmentId, message, departmentNumber, department, title, null);
493493
}
494494
}
495495
}

Core/Resgrid.Services/CommunicationService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public async Task<bool> SendUnitCallAsync(Call call, CallDispatchUnit dispatch,
290290
return true;
291291
}
292292

293-
public async Task<bool> SendNotificationAsync(string userId, int departmentId, string message, string departmentNumber, string title = "Notification", UserProfile profile = null)
293+
public async Task<bool> SendNotificationAsync(string userId, int departmentId, string message, string departmentNumber, Department department, string title = "Notification", UserProfile profile = null)
294294
{
295295
if (Config.SystemBehaviorConfig.DoNotBroadcast && !Config.SystemBehaviorConfig.BypassDoNotBroadcastDepartments.Contains(departmentId))
296296
return false;
@@ -319,6 +319,7 @@ public async Task<bool> SendNotificationAsync(string userId, int departmentId, s
319319
var spm = new StandardPushMessage();
320320
spm.Title = "Notification";
321321
spm.SubTitle = $"{title} {message}";
322+
spm.DepartmentCode = department?.Code;
322323

323324
try
324325
{

Core/Resgrid.Services/TrainingService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ public async Task<bool> SendInitialTrainingNoticeAsync(Training training)
180180
else
181181
message = string.Format("Training ({0}) assigned to you", training.Name);
182182

183-
await _communicationService.SendNotificationAsync(user.UserId, training.DepartmentId, message, "New Training");
183+
var department = await _departmentService.GetDepartmentByIdAsync(training.DepartmentId);
184+
185+
await _communicationService.SendNotificationAsync(user.UserId, training.DepartmentId, message, "New Training", department);
184186
}
185187

186188
return true;

Providers/Resgrid.Providers.Messaging/NovuProvider.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private async Task<bool> CreateSubscriber(string id, int departmentId, string em
2121
{
2222
var requestUrl = $"{ChatConfig.NovuBackendUrl}/v2/subscribers";
2323
httpClient.DefaultRequestHeaders.Add("idempotency-key", Guid.NewGuid().ToString());
24-
httpClient.DefaultRequestHeaders.Add("Authorization", Config.ChatConfig.NovuSecretKey);
24+
httpClient.DefaultRequestHeaders.Add("Authorization", $"ApiKey {ChatConfig.NovuSecretKey}");
2525

2626
var payload = new
2727
{
@@ -45,7 +45,8 @@ private async Task<bool> CreateSubscriber(string id, int departmentId, string em
4545
payload.data.Add(item.Key, item.Value);
4646
}
4747
}
48-
string jsonContent = JsonConvert.SerializeObject(payload);
48+
49+
string jsonContent = JsonConvert.SerializeObject(payload, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
4950

5051
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
5152

@@ -115,7 +116,7 @@ private async Task<bool> UpdateSubscriberFcm(string id, string token, string fcm
115116
},
116117
integrationIdentifier = fcmId
117118
};
118-
string jsonContent = JsonConvert.SerializeObject(payload);
119+
string jsonContent = JsonConvert.SerializeObject(payload, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
119120

120121
request.Content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
121122
HttpResponseMessage response = await client.SendAsync(request);
@@ -151,7 +152,7 @@ private async Task<bool> UpdateSubscriberApns(string id, string token, string ap
151152
},
152153
integrationIdentifier = apnsId
153154
};
154-
string jsonContent = JsonConvert.SerializeObject(payload);
155+
string jsonContent = JsonConvert.SerializeObject(payload, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
155156

156157
request.Content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
157158
HttpResponseMessage response = await client.SendAsync(request);
@@ -272,10 +273,12 @@ private async Task<bool> SendNotification(string title, string body, string reci
272273
};
273274

274275
var content = new StringContent(
275-
JsonConvert.SerializeObject(payload),
276+
JsonConvert.SerializeObject(payload, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }),
276277
Encoding.UTF8,
277278
"application/json");
278279

280+
281+
279282
var result = await httpClient.PostAsync("v1/events/trigger", content);
280283

281284
return result.IsSuccessStatusCode;

Workers/Resgrid.Workers.Framework/Logic/CalendarNotifierLogic.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public async Task<Tuple<bool,string>> Process(CalendarNotifierQueueItem item)
5757
foreach (var person in item.CalendarItem.Attendees)
5858
{
5959
var profile = profiles.FirstOrDefault(x => x.UserId == person.UserId);
60-
await _communicationService.SendNotificationAsync(person.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, title, profile);
60+
await _communicationService.SendNotificationAsync(person.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, department, title, profile);
6161
}
6262
}
6363
}
@@ -96,7 +96,7 @@ public async Task<Tuple<bool,string>> Process(CalendarNotifierQueueItem item)
9696
// Notify the entire department
9797
foreach (var profile in profiles)
9898
{
99-
await _communicationService.SendNotificationAsync(profile.Key, item.CalendarItem.DepartmentId, message, departmentNumber, title, profile.Value);
99+
await _communicationService.SendNotificationAsync(profile.Key, item.CalendarItem.DepartmentId, message, departmentNumber, department, title, profile.Value);
100100
}
101101
}
102102
else
@@ -114,9 +114,9 @@ public async Task<Tuple<bool,string>> Process(CalendarNotifierQueueItem item)
114114
foreach (var member in group.Members)
115115
{
116116
if (profiles.ContainsKey(member.UserId))
117-
await _communicationService.SendNotificationAsync(member.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, title, profiles[member.UserId]);
117+
await _communicationService.SendNotificationAsync(member.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, department, title, profiles[member.UserId]);
118118
else
119-
await _communicationService.SendNotificationAsync(member.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, title, null);
119+
await _communicationService.SendNotificationAsync(member.UserId, item.CalendarItem.DepartmentId, message, departmentNumber, department, title, null);
120120
}
121121
}
122122
}

Workers/Resgrid.Workers.Framework/Logic/NotificationBroadcastLogic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static async Task<bool> ProcessNotificationItem(NotificationItem ni, stri
7070
if (!_notificationService.AllowToSendViaSms(notification.Type))
7171
profile.SendNotificationSms = false;
7272

73-
await _communicationService.SendNotificationAsync(user, notification.DepartmentId, text, queueItem.DepartmentTextNumber, "Notification", profile);
73+
await _communicationService.SendNotificationAsync(user, notification.DepartmentId, text, queueItem.DepartmentTextNumber, queueItem.Department, "Notification", profile);
7474
}
7575
}
7676
}

Workers/Resgrid.Workers.Framework/Logic/ShiftNotificationLogic.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public static async Task<bool> ProcessShiftQueueItem(ShiftQueueItem sqi)
1717
var _shiftsService = Bootstrapper.GetKernel().Resolve<IShiftsService>();
1818
var _communicationService = Bootstrapper.GetKernel().Resolve<ICommunicationService>();
1919
var _userProfileService = Bootstrapper.GetKernel().Resolve<IUserProfileService>();
20+
var _departmentService = Bootstrapper.GetKernel().Resolve<IDepartmentsService>();
21+
22+
var department = await _departmentService.GetDepartmentByIdAsync(sqi.DepartmentId, false);
2023

2124
if (sqi.Type == (int)ShiftQueueTypes.TradeRequested)
2225
{
@@ -28,7 +31,7 @@ public static async Task<bool> ProcessShiftQueueItem(ShiftQueueItem sqi)
2831
foreach (var user in tradeRequest.Users)
2932
{
3033
UserProfile profile = userProfiles.FirstOrDefault(x => x.UserId == user.UserId);
31-
await _communicationService.SendNotificationAsync(user.UserId, tradeRequest.SourceShiftSignup.Shift.DepartmentId, text, sqi.DepartmentNumber,
34+
await _communicationService.SendNotificationAsync(user.UserId, tradeRequest.SourceShiftSignup.Shift.DepartmentId, text, sqi.DepartmentNumber, department,
3235
tradeRequest.SourceShiftSignup.Shift.Name, profile);
3336
}
3437
}
@@ -40,7 +43,7 @@ await _communicationService.SendNotificationAsync(user.UserId, tradeRequest.Sour
4043

4144
var text = _shiftsService.GenerateShiftTradeRejectionText(targetUserProfile, tradeRequest);
4245

43-
await _communicationService.SendNotificationAsync(sourceUserProfile.UserId, tradeRequest.SourceShiftSignup.Shift.DepartmentId, text, sqi.DepartmentNumber,
46+
await _communicationService.SendNotificationAsync(sourceUserProfile.UserId, tradeRequest.SourceShiftSignup.Shift.DepartmentId, text, sqi.DepartmentNumber, department,
4447
tradeRequest.SourceShiftSignup.Shift.Name, sourceUserProfile);
4548
}
4649
else if (sqi.Type == (int)ShiftQueueTypes.TradeProposed && !String.IsNullOrWhiteSpace(sqi.SourceUserId))
@@ -51,7 +54,7 @@ await _communicationService.SendNotificationAsync(sourceUserProfile.UserId, trad
5154

5255
var text = _shiftsService.GenerateShiftTradeProposedText(proposedUserProfile, tradeRequest);
5356

54-
await _communicationService.SendNotificationAsync(sourceUserProfile.UserId, tradeRequest.SourceShiftSignup.Shift.DepartmentId, text, sqi.DepartmentNumber,
57+
await _communicationService.SendNotificationAsync(sourceUserProfile.UserId, tradeRequest.SourceShiftSignup.Shift.DepartmentId, text, sqi.DepartmentNumber, department,
5558
tradeRequest.SourceShiftSignup.Shift.Name, sourceUserProfile);
5659
}
5760
else if (sqi.Type == (int)ShiftQueueTypes.TradeFilled && !String.IsNullOrWhiteSpace(sqi.SourceUserId))
@@ -62,7 +65,7 @@ await _communicationService.SendNotificationAsync(sourceUserProfile.UserId, trad
6265

6366
var text = _shiftsService.GenerateShiftTradeFilledText(sourceUserProfile, tradeRequest);
6467

65-
await _communicationService.SendNotificationAsync(proposedUserProfile.UserId, tradeRequest.SourceShiftSignup.Shift.DepartmentId, text, sqi.DepartmentNumber,
68+
await _communicationService.SendNotificationAsync(proposedUserProfile.UserId, tradeRequest.SourceShiftSignup.Shift.DepartmentId, text, sqi.DepartmentNumber, department,
6669
tradeRequest.SourceShiftSignup.Shift.Name, proposedUserProfile);
6770
}
6871
else if (sqi.Type == (int)ShiftQueueTypes.ShiftCreated)
@@ -74,7 +77,7 @@ await _communicationService.SendNotificationAsync(proposedUserProfile.UserId, tr
7477

7578
foreach (var profile in profiles.Select(x => x.Value))
7679
{
77-
await _communicationService.SendNotificationAsync(profile.UserId, sqi.DepartmentId, text, sqi.DepartmentNumber, "New Shift", profile);
80+
await _communicationService.SendNotificationAsync(profile.UserId, sqi.DepartmentId, text, sqi.DepartmentNumber, department, "New Shift", profile);
7881
}
7982
}
8083
else if (sqi.Type == (int)ShiftQueueTypes.ShiftUpdated)
@@ -87,9 +90,9 @@ await _communicationService.SendNotificationAsync(proposedUserProfile.UserId, tr
8790
foreach (var profile in shift.Personnel)
8891
{
8992
if (profiles.ContainsKey(profile.UserId))
90-
await _communicationService.SendNotificationAsync(profile.UserId, sqi.DepartmentId, text, sqi.DepartmentNumber, shift.Name, profiles[profile.UserId]);
93+
await _communicationService.SendNotificationAsync(profile.UserId, sqi.DepartmentId, text, sqi.DepartmentNumber, department, shift.Name, profiles[profile.UserId]);
9194
else
92-
await _communicationService.SendNotificationAsync(profile.UserId, sqi.DepartmentId, text, sqi.DepartmentNumber, shift.Name);
95+
await _communicationService.SendNotificationAsync(profile.UserId, sqi.DepartmentId, text, sqi.DepartmentNumber, department, shift.Name);
9396
}
9497
}
9598
else if (sqi.Type == (int)ShiftQueueTypes.ShiftDaysAdded)
@@ -104,9 +107,9 @@ await _communicationService.SendNotificationAsync(proposedUserProfile.UserId, tr
104107
foreach (var profile in shift.Personnel)
105108
{
106109
if (profiles.ContainsKey(profile.UserId))
107-
await _communicationService.SendNotificationAsync(profile.UserId, sqi.DepartmentId, text, sqi.DepartmentNumber, shift.Name, profiles[profile.UserId]);
110+
await _communicationService.SendNotificationAsync(profile.UserId, sqi.DepartmentId, text, sqi.DepartmentNumber, department, shift.Name, profiles[profile.UserId]);
108111
else
109-
await _communicationService.SendNotificationAsync(profile.UserId, sqi.DepartmentId, text, sqi.DepartmentNumber, shift.Name);
112+
await _communicationService.SendNotificationAsync(profile.UserId, sqi.DepartmentId, text, sqi.DepartmentNumber, department, shift.Name);
110113
}
111114
}
112115
}

Workers/Resgrid.Workers.Framework/Logic/ShiftNotifierLogic.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ public class ShiftNotifierLogic
1414
private IShiftsService _shiftsService;
1515
private ICommunicationService _communicationService;
1616
private IDepartmentSettingsService _departmentSettingsService;
17+
private IDepartmentsService _departmentsService;
1718

1819
public ShiftNotifierLogic()
1920
{
2021
_shiftsService = Bootstrapper.GetKernel().Resolve<IShiftsService>();
2122
_communicationService = Bootstrapper.GetKernel().Resolve<ICommunicationService>();
2223
_departmentSettingsService = Bootstrapper.GetKernel().Resolve<IDepartmentSettingsService>();
24+
_departmentsService = Bootstrapper.GetKernel().Resolve<IDepartmentsService>();
2325
}
2426

2527
public async Task<Tuple<bool, string>> Process(ShiftNotifierQueueItem item)
@@ -31,6 +33,7 @@ public async Task<Tuple<bool, string>> Process(ShiftNotifierQueueItem item)
3133
{
3234
var text = _shiftsService.GenerateShiftNotificationText(item.Shift);
3335
string departmentNumber = await _departmentSettingsService.GetTextToCallNumberForDepartmentAsync(item.Shift.DepartmentId);
36+
var department = await _departmentsService.GetDepartmentByIdAsync(item.Shift.DepartmentId, false);
3437

3538
if (ConfigHelper.CanTransmit(item.Shift.DepartmentId))
3639
{
@@ -39,7 +42,7 @@ public async Task<Tuple<bool, string>> Process(ShiftNotifierQueueItem item)
3942
foreach (var person in item.Shift.Personnel)
4043
{
4144
UserProfile profile = item.Profiles.FirstOrDefault(x => x.UserId == person.UserId);
42-
await _communicationService.SendNotificationAsync(person.UserId, item.Shift.DepartmentId, text, departmentNumber,
45+
await _communicationService.SendNotificationAsync(person.UserId, item.Shift.DepartmentId, text, departmentNumber, department,
4346
item.Shift.Name, profile);
4447
}
4548
}
@@ -53,26 +56,26 @@ await _communicationService.SendNotificationAsync(person.UserId, item.Shift.Depa
5356
if (!String.IsNullOrWhiteSpace(signup.Trade.UserId))
5457
{
5558
UserProfile profile = item.Profiles.FirstOrDefault(x => x.UserId == signup.Trade.UserId);
56-
await _communicationService.SendNotificationAsync(signup.Trade.UserId, item.Shift.DepartmentId, text, departmentNumber,
59+
await _communicationService.SendNotificationAsync(signup.Trade.UserId, item.Shift.DepartmentId, text, departmentNumber, department,
5760
item.Shift.Name, profile);
5861
}
5962
else if (signup.GetTradeType() == ShiftTradeTypes.Source)
6063
{
6164
UserProfile profile = item.Profiles.FirstOrDefault(x => x.UserId == signup.Trade.TargetShiftSignup.UserId);
62-
await _communicationService.SendNotificationAsync(signup.Trade.TargetShiftSignup.UserId, item.Shift.DepartmentId, text, departmentNumber,
65+
await _communicationService.SendNotificationAsync(signup.Trade.TargetShiftSignup.UserId, item.Shift.DepartmentId, text, departmentNumber, department,
6366
item.Shift.Name, profile);
6467
}
6568
else if (signup.GetTradeType() == ShiftTradeTypes.Target)
6669
{
6770
UserProfile profile = item.Profiles.FirstOrDefault(x => x.UserId == signup.Trade.SourceShiftSignup.UserId);
68-
await _communicationService.SendNotificationAsync(signup.Trade.SourceShiftSignup.UserId, item.Shift.DepartmentId, text, departmentNumber,
71+
await _communicationService.SendNotificationAsync(signup.Trade.SourceShiftSignup.UserId, item.Shift.DepartmentId, text, departmentNumber, department,
6972
item.Shift.Name, profile);
7073
}
7174
}
7275
else
7376
{
7477
UserProfile profile = item.Profiles.FirstOrDefault(x => x.UserId == signup.UserId);
75-
await _communicationService.SendNotificationAsync(signup.UserId, item.Shift.DepartmentId, text, departmentNumber,
78+
await _communicationService.SendNotificationAsync(signup.UserId, item.Shift.DepartmentId, text, departmentNumber, department,
7679
item.Shift.Name, profile);
7780
}
7881
}

Workers/Resgrid.Workers.Framework/Logic/TrainingNotifierLogic.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public class TrainingNotifierLogic
1414
private ICommunicationService _communicationService;
1515
private IUserProfileService _userProfileService;
1616
private IDepartmentSettingsService _departmentSettingsService;
17+
private IDepartmentsService _departmentsService;
1718

1819
public TrainingNotifierLogic()
1920
{
2021
_trainingService = Bootstrapper.GetKernel().Resolve<ITrainingService>();
2122
_communicationService = Bootstrapper.GetKernel().Resolve<ICommunicationService>();
2223
_userProfileService = Bootstrapper.GetKernel().Resolve<IUserProfileService>();
2324
_departmentSettingsService = Bootstrapper.GetKernel().Resolve<IDepartmentSettingsService>();
25+
_departmentsService = Bootstrapper.GetKernel().Resolve<IDepartmentsService>();
2426
}
2527

2628
public async Task<Tuple<bool, string>> Process(TrainingNotifierQueueItem item)
@@ -34,6 +36,7 @@ public async Task<Tuple<bool, string>> Process(TrainingNotifierQueueItem item)
3436
var title = String.Empty;
3537
var profiles = await _userProfileService.GetSelectedUserProfilesAsync(item.Training.Users.Select(x => x.UserId).ToList());
3638
var departmentNumber = await _departmentSettingsService.GetTextToCallNumberForDepartmentAsync(item.Training.DepartmentId);
39+
var department = await _departmentsService.GetDepartmentByIdAsync(item.Training.DepartmentId, false);
3740

3841
if (ConfigHelper.CanTransmit(item.Training.DepartmentId))
3942
{
@@ -57,7 +60,7 @@ public async Task<Tuple<bool, string>> Process(TrainingNotifierQueueItem item)
5760
var profile = profiles.FirstOrDefault(x => x.UserId == person.UserId);
5861

5962
if (!item.Training.Notified.HasValue || !person.Complete)
60-
await _communicationService.SendNotificationAsync(person.UserId, item.Training.DepartmentId, message, departmentNumber, title, profile);
63+
await _communicationService.SendNotificationAsync(person.UserId, item.Training.DepartmentId, message, departmentNumber, department, title, profile);
6164

6265
title = "Training Due Notice";
6366
}

0 commit comments

Comments
 (0)