Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc376755

Browse files
committed
CU-8687aj3gt Update User and Unit path to support Novu
1 parentde413fd commitc376755

File tree

12 files changed

+274
-176
lines changed

12 files changed

+274
-176
lines changed

‎Core/Resgrid.Config/ChatConfig.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ public static class ChatConfig
1111
publicstaticstringNovuSecretKey="";
1212

1313
publicstaticstringNovuUnitFcmProviderId="";
14-
publicstaticstringNovuUnitApsProviderId="";
14+
publicstaticstringNovuUnitApnsProviderId="";
1515
publicstaticstringNovuResponderFcmProviderId="";
1616
publicstaticstringNovuDispatchUnitWorkflowId="unit-dispatch";
17+
publicstaticstringNovuDispatchUserWorkflowId="user-dispatch";
18+
publicstaticstringNovuMessageUserWorkflowId="user-message";
19+
publicstaticstringNovuNotificationUserWorkflowId="user-notification";
1720
}
1821
}

‎Core/Resgrid.Model/Messages/StandardPushMessage.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ public class StandardPushMessage
66
publicstringTitle{get;set;}
77
publicstringSubTitle{get;set;}
88
publicstringId{get;set;}
9+
publicstringDepartmentCode{get;set;}
910
}
1011
}

‎Core/Resgrid.Model/Platforms.cs‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
{
33
publicenumPlatforms
44
{
5-
WindowsPhone7=0,
6-
iPhone=1,
7-
iPad=2,
8-
Android=3,
5+
None=0,
6+
iOS=1,
7+
Android=2,
8+
Web=3,
99
Windows8=4,
10-
WindowsPhone8=5,
11-
Blackberry=6,
12-
UnitIOS=7,
13-
UnitAndroid=8,
14-
UnitWin=9
10+
//Windows8 = 4,
11+
//WindowsPhone8= 5,
12+
//Blackberry= 6,
13+
//UnitIOS= 7,
14+
//UnitAndroid= 8,
15+
//UnitWin= 9
1516
}
16-
}
17+
}

‎Core/Resgrid.Model/Providers/Models/INovuProvider.cs‎

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,96 @@
22

33
namespaceResgrid.Model.Providers;
44

5+
/// <summary>
6+
/// Defines operations for managing Novu notification subscribers and sending notifications.
7+
/// </summary>
58
publicinterfaceINovuProvider
69
{
10+
/// <summary>
11+
/// Creates a Novu subscriber for a user.
12+
/// </summary>
13+
/// <param name="userId">The unique identifier of the user.</param>
14+
/// <param name="code">The Novu integration code or API key.</param>
15+
/// <param name="departmentId">The department the user belongs to.</param>
16+
/// <param name="email">The user's email address.</param>
17+
/// <param name="firstName">The user's first name.</param>
18+
/// <param name="lastName">The user's last name.</param>
19+
/// <returns>True if the subscriber was created successfully; otherwise, false.</returns>
720
Task<bool>CreateUserSubscriber(stringuserId,stringcode,intdepartmentId,stringemail,stringfirstName,stringlastName);
21+
22+
/// <summary>
23+
/// Creates a Novu subscriber for a unit (device or group).
24+
/// </summary>
25+
/// <param name="unitId">The unique identifier of the unit.</param>
26+
/// <param name="code">The Novu integration code or API key.</param>
27+
/// <param name="departmentId">The department the unit belongs to.</param>
28+
/// <param name="unitName">The name of the unit.</param>
29+
/// <param name="deviceId">The device identifier associated with the unit.</param>
30+
/// <returns>True if the subscriber was created successfully; otherwise, false.</returns>
831
Task<bool>CreateUnitSubscriber(intunitId,stringcode,intdepartmentId,stringunitName,stringdeviceId);
32+
33+
/// <summary>
34+
/// Updates the Firebase Cloud Messaging (FCM) token for a user subscriber.
35+
/// </summary>
36+
/// <param name="userId">The unique identifier of the user.</param>
37+
/// <param name="code">The Novu integration code or API key.</param>
38+
/// <param name="token">The FCM token to associate with the user.</param>
39+
/// <returns>True if the token was updated successfully; otherwise, false.</returns>
940
Task<bool>UpdateUserSubscriberFcm(stringuserId,stringcode,stringtoken);
41+
42+
/// <summary>
43+
/// Updates the Firebase Cloud Messaging (FCM) token for a unit subscriber.
44+
/// </summary>
45+
/// <param name="unitId">The unique identifier of the unit.</param>
46+
/// <param name="code">The Novu integration code or API key.</param>
47+
/// <param name="token">The FCM token to associate with the unit.</param>
48+
/// <returns>True if the token was updated successfully; otherwise, false.</returns>
1049
Task<bool>UpdateUnitSubscriberFcm(intunitId,stringcode,stringtoken);
11-
Task<bool>UpdateUnitSubscriberAps(intunitId,stringcode,stringtoken);
1250

51+
/// <summary>
52+
/// Updates the Apple Push Notification Service (APNS) token for a unit subscriber.
53+
/// </summary>
54+
/// <param name="unitId">The unique identifier of the unit.</param>
55+
/// <param name="code">The Novu integration code or API key.</param>
56+
/// <param name="token">The APNS token to associate with the unit.</param>
57+
/// <returns>True if the token was updated successfully; otherwise, false.</returns>
58+
Task<bool>UpdateUnitSubscriberApns(intunitId,stringcode,stringtoken);
59+
60+
/// <summary>
61+
/// Updates the Apple Push Notification Service (APNS) token for a user subscriber.
62+
/// </summary>
63+
/// <param name="userId">The unique identifier of the user.</param>
64+
/// <param name="code">The Novu integration code or API key.</param>
65+
/// <param name="token">The APNS token to associate with the user.</param>
66+
/// <returns>True if the token was updated successfully; otherwise, false.</returns>
67+
Task<bool>UpdateUserSubscriberApns(stringuserId,stringcode,stringtoken);
68+
69+
/// <summary>
70+
/// Sends a dispatch notification to a unit.
71+
/// </summary>
72+
/// <param name="title">The notification title.</param>
73+
/// <param name="body">The notification body content.</param>
74+
/// <param name="unitId">The unique identifier of the unit to notify.</param>
75+
/// <param name="depCode">The department code.</param>
76+
/// <param name="eventCode">The event code associated with the dispatch.</param>
77+
/// <param name="type">The type of notification.</param>
78+
/// <param name="enableCustomSounds">Whether to enable custom notification sounds.</param>
79+
/// <param name="count">The badge or notification count.</param>
80+
/// <param name="color">The color code for the notification.</param>
81+
/// <returns>True if the notification was sent successfully; otherwise, false.</returns>
1382
Task<bool>SendUnitDispatch(stringtitle,stringbody,intunitId,stringdepCode,stringeventCode,stringtype,
1483
boolenableCustomSounds,intcount,stringcolor);
1584

85+
/// <summary>
86+
/// Deletes a notification message by its identifier.
87+
/// </summary>
88+
/// <param name="messageId">The unique identifier of the message to delete.</param>
89+
/// <returns>True if the message was deleted successfully; otherwise, false.</returns>
1690
Task<bool>DeleteMessage(stringmessageId);
91+
92+
Task<bool>SendUserDispatch(stringtitle,stringbody,stringuserId,stringdepCode,stringeventCode,stringtype,boolenableCustomSounds,intcount,stringcolor);
93+
94+
Task<bool>SendUserMessage(stringtitle,stringbody,stringuserId,stringdepCode,stringeventCode,stringtype);
95+
96+
Task<bool>SendUserNotification(stringtitle,stringbody,stringuserId,stringdepCode,stringeventCode,stringtype);
1797
}

‎Core/Resgrid.Model/PushUri.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public string PushLocation
4545
{
4646
_pushLocation=value;
4747

48-
if(((Platforms)PlatformType)==Platforms.Windows8||((Platforms)PlatformType)==Platforms.WindowsPhone7||((Platforms)PlatformType)==Platforms.WindowsPhone8||((Platforms)PlatformType)==Platforms.UnitWin)
49-
ChannelUri=newUri(_pushLocation,UriKind.Absolute);
48+
//if (((Platforms)PlatformType) == Platforms.Windows8 || ((Platforms)PlatformType) == Platforms.WindowsPhone7 || ((Platforms)PlatformType) == Platforms.WindowsPhone8 || ((Platforms)PlatformType) == Platforms.UnitWin)
49+
//ChannelUri = new Uri(_pushLocation, UriKind.Absolute);
5050
}
5151
}
5252
}

‎Core/Resgrid.Services/PushService.cs‎

Lines changed: 90 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
usingSystem;
2-
usingSystem.IO;
3-
usingSystem.Linq;
4-
usingSystem.Reflection;
5-
usingSystem.Collections.Generic;
6-
usingSystem.Threading.Tasks;
1+
usingDnsClient;
2+
usingFirebaseAdmin.Messaging;
73
usingResgrid.Model;
84
usingResgrid.Model.Messages;
95
usingResgrid.Model.Providers;
106
usingResgrid.Model.Services;
11-
usingDnsClient;
7+
usingSystem;
8+
usingSystem.Collections.Generic;
9+
usingSystem.Drawing;
10+
usingSystem.IO;
11+
usingSystem.Linq;
12+
usingSystem.Reflection;
13+
usingSystem.Threading.Tasks;
1214

1315
namespaceResgrid.Services
1416
{
@@ -36,31 +38,18 @@ public async Task<bool> Register(PushUri pushUri)
3638
if(pushUri==null||String.IsNullOrWhiteSpace(pushUri.DeviceId))
3739
returnfalse;
3840

39-
stringdeviceId=pushUri.DeviceId.GetHashCode().ToString();
41+
varcode=pushUri.PushLocation;
4042

41-
//We just store the full Device Id in the PushUri object, the hashed version is for Azure
42-
//var existingPushUri = _pushUriService.GetPushUriByPlatformDeviceId((Platforms)pushUri.PlatformType, pushUri.DeviceId);
43-
List<PushRegistrationDescription>usersDevices=null;
43+
//1) iOS -> APNS
44+
if(pushUri.PlatformType==(int)Platforms.iOS)
45+
returnawait_novuProvider.UpdateUserSubscriberApns(pushUri.UserId,code,pushUri.DeviceId);
4446

45-
try
46-
{
47-
usersDevices=await_notificationProvider.GetRegistrationsByUserId(pushUri.UserId);
48-
49-
if(usersDevices==null||!usersDevices.Any(x=>x.Tags.Contains(deviceId)))
50-
await_notificationProvider.RegisterPush(pushUri);
51-
}
52-
catch(TimeoutException)
53-
{}
54-
catch(TaskCanceledException)
55-
{}
56-
57-
//if (existingPushUri == null)
58-
//pushUri = _pushUriService.SavePushUri(pushUri);
47+
// 2) Android -> FCM
48+
if(pushUri.PlatformType==(int)Platforms.Android)
49+
returnawait_novuProvider.UpdateUserSubscriberFcm(pushUri.UserId,code,pushUri.DeviceId);
5950

60-
//if (usersDevices == null || !usersDevices.Any(x => x.Tags.Contains(deviceId)))
61-
//await _notificationProvider.RegisterPush(pushUri);
62-
63-
returntrue;
51+
// 3) TODO: Web Push (other platforms)
52+
returnfalse;
6453
}
6554

6655
publicasyncTask<bool>UnRegister(PushUripushUri)
@@ -72,13 +61,22 @@ public async Task<bool> UnRegister(PushUri pushUri)
7261

7362
publicasyncTask<bool>RegisterUnit(PushUripushUri)
7463
{
75-
if(pushUri.UnitId.HasValue&&!string.IsNullOrWhiteSpace(pushUri.PushLocation)&&pushUri.PlatformType==(int)Platforms.iPhone)// 1
76-
await_novuProvider.UpdateUnitSubscriberAps(pushUri.UnitId.Value,pushUri.PushLocation,pushUri.DeviceId);
77-
else// 2 (Android)
78-
await_novuProvider.UpdateUnitSubscriberFcm(pushUri.UnitId.Value,pushUri.PushLocation,pushUri.DeviceId);
79-
// Eventually 3 for Web Push
64+
if(pushUri==null||!pushUri.UnitId.HasValue||string.IsNullOrWhiteSpace(pushUri.PushLocation))
65+
returnfalse;
8066

81-
returntrue;
67+
varunitId=pushUri.UnitId.Value;
68+
varcode=pushUri.PushLocation;
69+
70+
// 1) iOS -> APNS
71+
if(pushUri.PlatformType==(int)Platforms.iOS)
72+
returnawait_novuProvider.UpdateUnitSubscriberApns(unitId,code,pushUri.DeviceId);
73+
74+
// 2) Android -> FCM
75+
if(pushUri.PlatformType==(int)Platforms.Android)
76+
returnawait_novuProvider.UpdateUnitSubscriberFcm(unitId,code,pushUri.DeviceId);
77+
78+
// 3) TODO: Web Push (other platforms)
79+
returnfalse;
8280
}
8381

8482
publicasyncTask<bool>UnRegisterUnit(PushUripushUri)
@@ -102,7 +100,25 @@ public async Task<bool> PushMessage(StandardPushMessage message, string userId,
102100
profile=await_userProfileService.GetProfileByUserIdAsync(userId);
103101

104102
if(profile!=null&&profile.SendMessagePush)
105-
await_notificationProvider.SendAllNotifications(message.Title,message.SubTitle,userId,string.Format("M{0}",message.MessageId),((int)PushSoundTypes.Message).ToString(),true,1,"#000000");
103+
{
104+
try
105+
{
106+
await_notificationProvider.SendAllNotifications(message.Title,message.SubTitle,userId,string.Format("M{0}",message.MessageId),((int)PushSoundTypes.Message).ToString(),true,1,"#000000");
107+
}
108+
catch(Exceptionex)
109+
{
110+
Framework.Logging.LogException(ex);
111+
}
112+
113+
try
114+
{
115+
await_novuProvider.SendUserMessage(message.Title,message.SubTitle,userId,message.DepartmentCode,string.Format("M{0}",message.MessageId),null);
116+
}
117+
catch(Exceptionex)
118+
{
119+
Framework.Logging.LogException(ex);
120+
}
121+
}
106122

107123
returntrue;
108124
}
@@ -116,8 +132,24 @@ public async Task<bool> PushNotification(StandardPushMessage message, string use
116132
profile=await_userProfileService.GetProfileByUserIdAsync(userId);
117133

118134
if(profile!=null&&profile.SendNotificationPush)
119-
await_notificationProvider.SendAllNotifications(message.Title,message.SubTitle,userId,string.Format("N{0}",message.MessageId),((int)PushSoundTypes.Notifiation).ToString(),true,1,"#000000");
120-
135+
{
136+
try
137+
{
138+
await_notificationProvider.SendAllNotifications(message.Title,message.SubTitle,userId,string.Format("N{0}",message.MessageId),((int)PushSoundTypes.Notifiation).ToString(),true,1,"#000000");
139+
}
140+
catch(Exceptionex)
141+
{
142+
Framework.Logging.LogException(ex);
143+
}
144+
try
145+
{
146+
await_novuProvider.SendUserMessage(message.Title,message.SubTitle,userId,message.DepartmentCode,string.Format("N{0}",message.MessageId),null);
147+
}
148+
catch(Exceptionex)
149+
{
150+
Framework.Logging.LogException(ex);
151+
}
152+
}
121153
returntrue;
122154
}
123155

@@ -151,7 +183,26 @@ public async Task<bool> PushCall(StandardPushCall call, string userId, UserProfi
151183
color=priority.Color;
152184

153185
if(profile!=null&&profile.SendPush)
154-
await_notificationProvider.SendAllNotifications(call.SubTitle,call.Title,userId,string.Format("C{0}",call.CallId),ConvertCallPriorityToSound((int)call.Priority,priority),true,call.ActiveCallCount,color);
186+
{
187+
// Legacy Push Notifications (Azure)
188+
try
189+
{
190+
await_notificationProvider.SendAllNotifications(call.SubTitle,call.Title,userId,string.Format("C{0}",call.CallId),ConvertCallPriorityToSound((int)call.Priority,priority),true,call.ActiveCallCount,color);
191+
}
192+
catch(Exceptionex)
193+
{
194+
Framework.Logging.LogException(ex);
195+
}
196+
197+
try
198+
{
199+
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);
200+
}
201+
catch(Exceptionex)
202+
{
203+
Framework.Logging.LogException(ex);
204+
}
205+
}
155206

156207
returntrue;
157208
}
@@ -168,15 +219,6 @@ public async Task<bool> PushCallUnit(StandardPushCall call, int unitId, Departme
168219
if(priority!=null)
169220
color=priority.Color;
170221

171-
try
172-
{
173-
await_unitNotificationProvider.SendAllNotifications(call.SubTitle,call.Title,unitId,string.Format("C{0}",call.CallId),ConvertCallPriorityToSound((int)call.Priority,priority),true,call.ActiveCallCount,color);
174-
}
175-
catch(Exceptionex)
176-
{
177-
Framework.Logging.LogException(ex);
178-
}
179-
180222
try
181223
{
182224
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);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp