Skip to content

Commit 3ef34e7

Browse files
committed
RE1-T114 PR#390 fixes
1 parent 67385c0 commit 3ef34e7

3 files changed

Lines changed: 43 additions & 15 deletions

File tree

Core/Resgrid.Model/Services/IDepartmentSettingsService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,6 @@ Task<DepartmentSetting> SetUnitCallStatusOverridesByUnitTypeAsync(int department
313313
/// </summary>
314314
Task<DepartmentSetting> GetSettingByTypeAsync(int departmentId, DepartmentSettingTypes type);
315315

316-
Task<bool> GetModernNotificationsEnabledAsync(int departmentId);
316+
Task<bool> GetModernNotificationsEnabledAsync(int departmentId, bool bypassCache = false);
317317
}
318318
}

Core/Resgrid.Services/DepartmentSettingsService.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class DepartmentSettingsService : IDepartmentSettingsService
2121
private static string StaffingSupressInfo = "DSetStaffingSupress_{0}";
2222
private static string TtsLanguageCacheKey = "DSetTtsLanguage_{0}";
2323
private static string PersonnelOnUnitSetUnitStatusCacheKey = "DSetPersonnelOnUnitSetUnitStatus_{0}";
24+
private static string ModernNotificationsCacheKey = "DSetModernNotifications_{0}";
2425
private static TimeSpan LongCacheLength = TimeSpan.FromDays(14);
2526
private static TimeSpan ThatsNotLongThisIsLongCacheLength = TimeSpan.FromDays(365);
2627
private static TimeSpan TwoYearCacheLength = TimeSpan.FromDays(730);
@@ -72,6 +73,9 @@ public DepartmentSettingsService(IDepartmentSettingsRepository departmentSetting
7273
case DepartmentSettingTypes.PersonnelOnUnitSetUnitStatus:
7374
await _cacheProvider.RemoveAsync(string.Format(PersonnelOnUnitSetUnitStatusCacheKey, departmentId));
7475
break;
76+
case DepartmentSettingTypes.EnableModernNotifications:
77+
await _cacheProvider.RemoveAsync(string.Format(ModernNotificationsCacheKey, departmentId));
78+
break;
7579
}
7680

7781
savedSetting.Setting = setting;
@@ -924,14 +928,21 @@ public async Task<DepartmentSetting> GetSettingByTypeAsync(int departmentId, Dep
924928
return await GetSettingByDepartmentIdType(departmentId, type);
925929
}
926930

927-
public async Task<bool> GetModernNotificationsEnabledAsync(int departmentId)
931+
public async Task<bool> GetModernNotificationsEnabledAsync(int departmentId, bool bypassCache = false)
928932
{
929-
var s = await GetSettingByDepartmentIdType(departmentId, DepartmentSettingTypes.EnableModernNotifications);
933+
async Task<string> getSetting()
934+
{
935+
var s = await GetSettingByDepartmentIdType(departmentId, DepartmentSettingTypes.EnableModernNotifications);
936+
return s?.Setting ?? "false";
937+
}
930938

931-
if (s != null && bool.TryParse(s.Setting, out bool result))
932-
return result;
939+
if (Config.SystemBehaviorConfig.CacheEnabled && !bypassCache)
940+
{
941+
var cachedValue = await _cacheProvider.RetrieveAsync<string>(string.Format(ModernNotificationsCacheKey, departmentId), getSetting, LongCacheLength);
942+
return bool.Parse(cachedValue);
943+
}
933944

934-
return false;
945+
return bool.Parse(await getSetting());
935946
}
936947

937948
private static string GetDefaultTtsLanguage()

Core/Resgrid.Services/PushService.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,14 @@ public async Task<bool> PushCall(StandardPushCall call, string userId, UserProfi
184184
if (profile == null)
185185
profile = await _userProfileService.GetProfileByUserIdAsync(userId);
186186

187-
string color = null;
188-
if (priority != null)
189-
color = priority.Color;
190-
191-
bool useModern = call.DepartmentId.HasValue && await _departmentSettingsService.GetModernNotificationsEnabledAsync(call.DepartmentId.Value);
192-
string soundType = ConvertCallPriorityToSound((int)call.Priority, priority, useModern);
193-
194187
if (profile != null && profile.SendPush)
195188
{
189+
string color = null;
190+
if (priority != null)
191+
color = priority.Color;
192+
193+
string soundType = await GetCallSoundTypeAsync(call, priority);
194+
196195
// Legacy Push Notifications (Azure)
197196
try
198197
{
@@ -228,8 +227,7 @@ public async Task<bool> PushCallUnit(StandardPushCall call, int unitId, Departme
228227
if (priority != null)
229228
color = priority.Color;
230229

231-
bool useModern = call.DepartmentId.HasValue && await _departmentSettingsService.GetModernNotificationsEnabledAsync(call.DepartmentId.Value);
232-
string soundType = ConvertCallPriorityToSound((int)call.Priority, priority, useModern);
230+
string soundType = await GetCallSoundTypeAsync(call, priority);
233231

234232
try
235233
{
@@ -262,6 +260,25 @@ private async Task<string> GetSoundTypeAsync(int? departmentId, PushSoundTypes l
262260
return ((int)legacyType).ToString();
263261
}
264262

263+
private async Task<string> GetCallSoundTypeAsync(StandardPushCall call, DepartmentCallPriority priority)
264+
{
265+
bool useModern = false;
266+
267+
if (call.DepartmentId.HasValue)
268+
{
269+
try
270+
{
271+
useModern = await _departmentSettingsService.GetModernNotificationsEnabledAsync(call.DepartmentId.Value);
272+
}
273+
catch (Exception ex)
274+
{
275+
Framework.Logging.LogException(ex);
276+
}
277+
}
278+
279+
return ConvertCallPriorityToSound((int)call.Priority, priority, useModern);
280+
}
281+
265282
private string ConvertCallPriorityToSound(int priority, DepartmentCallPriority callPriority, bool useModern)
266283
{
267284
if (priority > 3 && callPriority != null)

0 commit comments

Comments
 (0)