-
-
Notifications
You must be signed in to change notification settings - Fork 73
CU-8687aj3gt Adding Apns to Novu provider for Units #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
de413fd
c376755
55313dc
95ecd5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -45,8 +45,8 @@ public string PushLocation | |||||
| { | ||||||
| _pushLocation = value; | ||||||
|
|
||||||
| if (((Platforms)PlatformType) == Platforms.Windows8 || ((Platforms)PlatformType) == Platforms.WindowsPhone7 || ((Platforms)PlatformType) == Platforms.WindowsPhone8 || ((Platforms)PlatformType) == Platforms.UnitWin) | ||||||
| ChannelUri = new Uri(_pushLocation, UriKind.Absolute); | ||||||
| //if (((Platforms)PlatformType) == Platforms.Windows8 || ((Platforms)PlatformType) == Platforms.WindowsPhone7 || ((Platforms)PlatformType) == Platforms.WindowsPhone8 || ((Platforms)PlatformType) == Platforms.UnitWin) | ||||||
| // ChannelUri = new Uri(_pushLocation, UriKind.Absolute); | ||||||
|
Comment on lines
+48
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove commented-out code to maintain code cleanliness Since Windows platform support is being phased out as part of this PR, the commented code should be removed rather than left as comments. This improves code maintainability and clarity. -//if (((Platforms)PlatformType) == Platforms.Windows8 || ((Platforms)PlatformType) == Platforms.WindowsPhone7 || ((Platforms)PlatformType) == Platforms.WindowsPhone8 || ((Platforms)PlatformType) == Platforms.UnitWin)
-// ChannelUri = new Uri(_pushLocation, UriKind.Absolute);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,16 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using DnsClient; | ||
| using FirebaseAdmin.Messaging; | ||
| using Resgrid.Model; | ||
| using Resgrid.Model.Messages; | ||
| using Resgrid.Model.Providers; | ||
| using Resgrid.Model.Services; | ||
| using DnsClient; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Drawing; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Resgrid.Services | ||
| { | ||
|
|
@@ -36,31 +38,18 @@ public async Task<bool> Register(PushUri pushUri) | |
| if (pushUri == null || String.IsNullOrWhiteSpace(pushUri.DeviceId)) | ||
| return false; | ||
|
|
||
| string deviceId = pushUri.DeviceId.GetHashCode().ToString(); | ||
| var code = pushUri.PushLocation; | ||
|
|
||
| // We just store the full Device Id in the PushUri object, the hashed version is for Azure | ||
| //var existingPushUri = _pushUriService.GetPushUriByPlatformDeviceId((Platforms)pushUri.PlatformType, pushUri.DeviceId); | ||
| List<PushRegistrationDescription> usersDevices = null; | ||
| // 1) iOS -> APNS | ||
| if (pushUri.PlatformType == (int)Platforms.iOS) | ||
| return await _novuProvider.UpdateUserSubscriberApns(pushUri.UserId, code, pushUri.DeviceId); | ||
|
|
||
| try | ||
| { | ||
| usersDevices = await _notificationProvider.GetRegistrationsByUserId(pushUri.UserId); | ||
|
|
||
| if (usersDevices == null || !usersDevices.Any(x => x.Tags.Contains(deviceId))) | ||
| await _notificationProvider.RegisterPush(pushUri); | ||
| } | ||
| catch (TimeoutException) | ||
| { } | ||
| catch (TaskCanceledException) | ||
| { } | ||
| // 2) Android -> FCM | ||
| if (pushUri.PlatformType == (int)Platforms.Android) | ||
| return await _novuProvider.UpdateUserSubscriberFcm(pushUri.UserId, code, pushUri.DeviceId); | ||
|
|
||
| //if (existingPushUri == null) | ||
| // pushUri = _pushUriService.SavePushUri(pushUri); | ||
|
|
||
| //if (usersDevices == null || !usersDevices.Any(x => x.Tags.Contains(deviceId))) | ||
| // await _notificationProvider.RegisterPush(pushUri); | ||
|
|
||
| return true; | ||
| // 3) TODO: Web Push (other platforms) | ||
| return false; | ||
| } | ||
|
|
||
| public async Task<bool> UnRegister(PushUri pushUri) | ||
|
|
@@ -72,29 +61,22 @@ public async Task<bool> UnRegister(PushUri pushUri) | |
|
|
||
| public async Task<bool> RegisterUnit(PushUri pushUri) | ||
| { | ||
| //string deviceId = pushUri.DeviceId; | ||
| List<PushRegistrationDescription> usersDevices = null; | ||
|
|
||
| //try | ||
| //{ | ||
| // usersDevices = await _unitNotificationProvider.GetRegistrationsByUUID(pushUri.PushLocation); | ||
| //} | ||
| //catch (TimeoutException) | ||
| //{ } | ||
| if (pushUri == null || !pushUri.UnitId.HasValue || string.IsNullOrWhiteSpace(pushUri.PushLocation)) | ||
| return false; | ||
|
|
||
| if (pushUri.UnitId.HasValue && !string.IsNullOrWhiteSpace(pushUri.PushLocation)) | ||
| await _novuProvider.UpdateUnitSubscriberFcm(pushUri.UnitId.Value, pushUri.PushLocation, pushUri.DeviceId); | ||
| var unitId = pushUri.UnitId.Value; | ||
| var code = pushUri.PushLocation; | ||
|
|
||
| // 1) iOS -> APNS | ||
| if (pushUri.PlatformType == (int)Platforms.iOS) | ||
| return await _novuProvider.UpdateUnitSubscriberApns(unitId, code, pushUri.DeviceId); | ||
|
|
||
| //if (usersDevices == null || !usersDevices.Any(x => x.Tags.Contains(string.Format("unitId:{0}", pushUri.UnitId.ToString())))) | ||
| // await _unitNotificationProvider.RegisterPush(pushUri); | ||
| //else | ||
| //{ | ||
| // await _unitNotificationProvider.UnRegisterPushByUUID(pushUri.PushLocation); | ||
| // await _unitNotificationProvider.RegisterPush(pushUri); | ||
| //} | ||
| // 2) Android -> FCM | ||
| if (pushUri.PlatformType == (int)Platforms.Android) | ||
| return await _novuProvider.UpdateUnitSubscriberFcm(unitId, code, pushUri.DeviceId); | ||
|
|
||
| return true; | ||
| // 3) TODO: Web Push (other platforms) | ||
| return false; | ||
| } | ||
|
|
||
| public async Task<bool> UnRegisterUnit(PushUri pushUri) | ||
|
|
@@ -118,7 +100,25 @@ public async Task<bool> PushMessage(StandardPushMessage message, string userId, | |
| profile = await _userProfileService.GetProfileByUserIdAsync(userId); | ||
|
|
||
| if (profile != null && profile.SendMessagePush) | ||
| await _notificationProvider.SendAllNotifications(message.Title, message.SubTitle, userId, string.Format("M{0}", message.MessageId), ((int)PushSoundTypes.Message).ToString(), true, 1, "#000000"); | ||
| { | ||
| try | ||
| { | ||
| await _notificationProvider.SendAllNotifications(message.Title, message.SubTitle, userId, string.Format("M{0}", message.MessageId), ((int)PushSoundTypes.Message).ToString(), true, 1, "#000000"); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Framework.Logging.LogException(ex); | ||
| } | ||
|
|
||
| try | ||
| { | ||
| await _novuProvider.SendUserMessage(message.Title, message.SubTitle, userId, message.DepartmentCode, string.Format("M{0}", message.MessageId), null); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Framework.Logging.LogException(ex); | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
@@ -132,8 +132,24 @@ public async Task<bool> PushNotification(StandardPushMessage message, string use | |
| profile = await _userProfileService.GetProfileByUserIdAsync(userId); | ||
|
|
||
| if (profile != null && profile.SendNotificationPush) | ||
| await _notificationProvider.SendAllNotifications(message.Title, message.SubTitle, userId, string.Format("N{0}", message.MessageId), ((int)PushSoundTypes.Notifiation).ToString(), true, 1, "#000000"); | ||
|
|
||
| { | ||
| try | ||
| { | ||
| await _notificationProvider.SendAllNotifications(message.Title, message.SubTitle, userId, string.Format("N{0}", message.MessageId), ((int)PushSoundTypes.Notifiation).ToString(), true, 1, "#000000"); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Framework.Logging.LogException(ex); | ||
| } | ||
| try | ||
| { | ||
| await _novuProvider.SendUserMessage(message.Title, message.SubTitle, userId, message.DepartmentCode, string.Format("N{0}", message.MessageId), null); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Framework.Logging.LogException(ex); | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -167,7 +183,26 @@ public async Task<bool> PushCall(StandardPushCall call, string userId, UserProfi | |
| color = priority.Color; | ||
|
|
||
| if (profile != null && profile.SendPush) | ||
| await _notificationProvider.SendAllNotifications(call.SubTitle, call.Title, userId, string.Format("C{0}", call.CallId), ConvertCallPriorityToSound((int)call.Priority, priority), true, call.ActiveCallCount, color); | ||
| { | ||
| // Legacy Push Notifications (Azure) | ||
| try | ||
| { | ||
| await _notificationProvider.SendAllNotifications(call.SubTitle, call.Title, userId, string.Format("C{0}", call.CallId), ConvertCallPriorityToSound((int)call.Priority, priority), true, call.ActiveCallCount, color); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Framework.Logging.LogException(ex); | ||
| } | ||
|
|
||
| try | ||
| { | ||
| await _novuProvider.SendUserDispatch(call.Title, call.SubTitle, userId, call.DepartmentCode, string.Format("C{0}", call.CallId), ConvertCallPriorityToSound((int)call.Priority, priority), true, call.ActiveCallCount, color); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify DepartmentCode is populated in StandardPushCall The code passes 🏁 Script executed: #!/bin/bash
# Check StandardPushCall definition and usage to verify DepartmentCode is always set
ast-grep --pattern 'class StandardPushCall {
$$$
public string DepartmentCode { $$$; set; }
$$$
}'
# Check where StandardPushCall is instantiated
rg -A 5 "new StandardPushCall"Length of output: 1586 StandardPushCall.DepartmentCode is never set In Please update each instantiation in // existing assignment
spc.DepartmentId = departmentId;
+ spc.DepartmentCode = departmentCode; // ensure DepartmentCode is populatedAffected locations (3 occurrences of
🤖 Prompt for AI Agents |
||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Framework.Logging.LogException(ex); | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
@@ -184,15 +219,6 @@ public async Task<bool> PushCallUnit(StandardPushCall call, int unitId, Departme | |
| if (priority != null) | ||
| color = priority.Color; | ||
|
|
||
| try | ||
| { | ||
| await _unitNotificationProvider.SendAllNotifications(call.SubTitle, call.Title, unitId, string.Format("C{0}", call.CallId), ConvertCallPriorityToSound((int)call.Priority, priority), true, call.ActiveCallCount, color); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Framework.Logging.LogException(ex); | ||
| } | ||
|
|
||
| try | ||
| { | ||
| await _novuProvider.SendUnitDispatch(call.Title, call.SubTitle, unitId, call.DepartmentCode, string.Format("C{0}", call.CallId), ConvertCallPriorityToSound((int)call.Priority, priority), true, call.ActiveCallCount, color); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking enum value changes will corrupt persisted platform mappings and conflict with hard-coded checks
Previous code (and likely persisted DB values) use 1=iPad, 2=iPhone, 3=Android, 4=Windows8. This change sets iOS=1, Android=2, Web=3, which:
Preserve legacy numeric values and introduce new names without reassigning existing numbers. Optionally re-add legacy members marked [Obsolete] for compatibility.
Apply this diff to restore stable values and keep compatibility:
If changing enum assignments is not feasible now, introduce centralized helpers to interpret legacy ints consistently and update UI/provider code to use them.
📝 Committable suggestion
🤖 Prompt for AI Agents