Skip to content

Commit

Permalink
CU-868a1kgf7 update for android push
Browse files Browse the repository at this point in the history
  • Loading branch information
ucswift committed Oct 2, 2024
1 parent 87ce6c6 commit 6043bf3
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 41 deletions.
46 changes: 29 additions & 17 deletions Providers/Resgrid.Providers.Bus/NotificationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Newtonsoft.Json.Linq;
using Resgrid.Providers.Bus.Models;
using Newtonsoft.Json;
using static System.Runtime.InteropServices.JavaScript.JSType;
using String = System.String;

namespace Resgrid.Providers.Bus
{
Expand Down Expand Up @@ -99,7 +101,8 @@ public async Task RegisterPush(PushUri pushUri)
{
try
{
var result = await hubClient.CreateFcmNativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray());
//var result = await hubClient.CreateFcmNativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray());
var result = await hubClient.CreateFcmV1NativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray());
}
catch (Exception ex)
{
Expand Down Expand Up @@ -311,7 +314,8 @@ public async Task<NotificationOutcomeState> SendAndroidNotification(string title
channel = "chats";

androidNotification = CreateAndroidNotification(title, subTitle, eventCode, type, count, color, channel);
var androidOutcome = await hubClient.SendFcmNativeNotificationAsync(androidNotification, string.Format("userId:{0}", userId));
//var androidOutcome = await hubClient.SendFcmNativeNotificationAsync(androidNotification, string.Format("userId:{0}", userId));
var androidOutcome = await hubClient.SendFcmV1NativeNotificationAsync(androidNotification, string.Format("userId:{0}", userId));

return androidOutcome.State;
}
Expand Down Expand Up @@ -506,27 +510,35 @@ private string CreateAndroidNotification(string title, string subTitle, string e

dynamic pushNotification = new JObject();

pushNotification.notification = new JObject();
pushNotification.notification.title = title;
pushNotification.notification.body = subTitle;
pushNotification.notification.android_channel_id = type;
pushNotification.message = new JObject();
pushNotification.message.notification = new JObject();
pushNotification.message.notification.title = title;
pushNotification.message.notification.body = subTitle;
//pushNotification.notification.android_channel_id = type;

pushNotification.android = new JObject();
pushNotification.android.ttl = "86400";
pushNotification.android.notification = new JObject();
pushNotification.message.android = new JObject();

if (channel != null && channel == "calls")
pushNotification.message.android.priority = 1;

//pushNotification.message.android.ttl = "86400";
pushNotification.message.android.notification = new JObject();
//pushNotification.android.notification.color = color;
pushNotification.android.notification.channel_id = type;
pushNotification.message.android.notification.channel_id = type;
//pushNotification.android.notification.sound = soundFilename;
pushNotification.android.notification.defaultSound = true;
pushNotification.message.android.notification.default_sound = true;

if (channel != null && channel == "calls")
pushNotification.android.notification.priority = "high";
{
pushNotification.message.android.notification.sticky = true;
pushNotification.message.android.notification.notification_priority = 5;
}

pushNotification.data = new JObject();
pushNotification.data.title = title;
pushNotification.data.message = subTitle;
pushNotification.data.eventCode = eventCode;
pushNotification.data.type = type;
pushNotification.message.data = new JObject();
pushNotification.message.data.title = title;
pushNotification.message.data.message = subTitle;
pushNotification.message.data.eventCode = eventCode;
pushNotification.message.data.type = type;

//if (channel != null && channel == "calls")
// pushNotification.data.priority = "high";
Expand Down
49 changes: 30 additions & 19 deletions Providers/Resgrid.Providers.Bus/UnitNotificationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Newtonsoft.Json.Linq;
using Resgrid.Providers.Bus.Models;
using Newtonsoft.Json;
using static Resgrid.Framework.Testing.TestData;

namespace Resgrid.Providers.Bus
{
Expand Down Expand Up @@ -82,7 +83,8 @@ public async Task RegisterPush(PushUri pushUri)
{
try
{
var result = await hubClient.CreateFcmNativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray());
//var result = await hubClient.CreateFcmNativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray());
var result = await hubClient.CreateFcmV1NativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray());
}
catch (ArgumentException ex)
{
Expand Down Expand Up @@ -308,7 +310,8 @@ public async Task<NotificationOutcomeState> SendAndroidNotification(string title
var hubClient = NotificationHubClient.CreateClientFromConnectionString(Config.ServiceBusConfig.AzureUnitNotificationHub_FullConnectionString, Config.ServiceBusConfig.AzureUnitNotificationHub_PushUrl);
string androidNotification = CreateAndroidNotification(subTitle, title, eventCode, type, count, color, "calls");

var androidOutcome = await hubClient.SendFcmNativeNotificationAsync(androidNotification, string.Format("unitId:{0}", unitId));
//var androidOutcome = await hubClient.SendFcmNativeNotificationAsync(androidNotification, string.Format("unitId:{0}", unitId));
var androidOutcome = await hubClient.SendFcmV1NativeNotificationAsync(androidNotification, string.Format("unitId:{0}", unitId));

return androidOutcome.State;
}
Expand Down Expand Up @@ -480,28 +483,36 @@ private string CreateAndroidNotification(string title, string subTitle, string e

dynamic pushNotification = new JObject();

pushNotification.notification = new JObject();
pushNotification.notification.title = title;
pushNotification.notification.body = subTitle;
pushNotification.notification.android_channel_id = type;
pushNotification.message = new JObject();
pushNotification.message.notification = new JObject();
pushNotification.message.notification.title = title;
pushNotification.message.notification.body = subTitle;
//pushNotification.notification.android_channel_id = type;

pushNotification.android = new JObject();
pushNotification.android.ttl = "86400";
pushNotification.android.notification = new JObject();
pushNotification.message.android = new JObject();

if (channel != null && channel == "calls")
pushNotification.message.android.priority = 1;

//pushNotification.message.android.ttl = "86400";
pushNotification.message.android.notification = new JObject();
//pushNotification.android.notification.color = color;
pushNotification.android.notification.channel_id = type;
pushNotification.message.android.notification.channel_id = type;
//pushNotification.android.notification.sound = soundFilename;
pushNotification.android.notification.defaultSound = true;
pushNotification.message.android.notification.default_sound = true;

if (channel != null && channel == "calls")
pushNotification.android.notification.priority = "high";

pushNotification.data = new JObject();
pushNotification.data.title = title;
pushNotification.data.message = subTitle;
pushNotification.data.notId = eventCode;
pushNotification.data.eventCode = eventCode;
pushNotification.data.type = type;
{
pushNotification.message.android.notification.sticky = true;
pushNotification.message.android.notification.notification_priority = 5;
}

pushNotification.message.data = new JObject();
pushNotification.message.data.title = title;
pushNotification.message.data.message = subTitle;
pushNotification.message.data.notId = eventCode;
pushNotification.message.data.eventCode = eventCode;
pushNotification.message.data.type = type;

return pushNotification.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public async Task<ActionResult<PersonnelInfoResult>> GetPersonnelInfo(string use
if (department.DepartmentId != DepartmentId)
return Unauthorized();

if (!await _authorizationService.CanUserViewPersonViaMatrixAsync(user.UserId, UserId, DepartmentId))
{
ResponseHelper.PopulateV4ResponseNotFound(result);

return result;
}

var profile = await _userProfileService.GetProfileByUserIdAsync(user.UserId);
var group = await _departmentGroupsService.GetGroupForUserAsync(user.UserId, DepartmentId);
var roles = await _personnelRolesService.GetRolesForUserAsync(user.UserId, DepartmentId);
Expand Down
11 changes: 9 additions & 2 deletions Web/Resgrid.Web.ServicesCore/Controllers/v4/UnitsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections.Generic;
using System;
using System.Web;
using SharpKml.Dom;

namespace Resgrid.Web.Services.Controllers.v4
{
Expand Down Expand Up @@ -62,6 +63,9 @@ public async Task<ActionResult<UnitsResult>> GetAllUnits()

foreach (var unit in units)
{
if (!await _authorizationService.CanUserViewUnitViaMatrixAsync(unit.UnitId, UserId, DepartmentId))
continue;

UnitType type = null;

if (types != null && types.Any())
Expand Down Expand Up @@ -113,6 +117,9 @@ public async Task<ActionResult<UnitsInfoResult>> GetAllUnitsInfos(string activeF

foreach (var unit in units)
{
if (!await _authorizationService.CanUserViewUnitViaMatrixAsync(unit.UnitId, UserId, DepartmentId))
continue;

UnitType type = null;

if (types != null && types.Any())
Expand Down Expand Up @@ -203,7 +210,7 @@ public async Task<ActionResult<GetUnitsFilterOptionsResult>> GetUnitsFilterOptio
return Ok(result);
}

public static UnitResultData ConvertUnitsData(Unit unit, UnitState state, UnitType type, string timeZone)
public static UnitResultData ConvertUnitsData(Model.Unit unit, UnitState state, UnitType type, string timeZone)
{
var data = new UnitResultData();
data.UnitId = unit.UnitId.ToString();
Expand Down Expand Up @@ -250,7 +257,7 @@ public static UnitResultData ConvertUnitsData(Unit unit, UnitState state, UnitTy
return data;
}

public static UnitsInfoResultData ConvertUnitsInfoResultData(Unit unit, UnitState state, CustomStateDetail customState, UnitType type, string timeZone,
public static UnitsInfoResultData ConvertUnitsInfoResultData(Model.Unit unit, UnitState state, CustomStateDetail customState, UnitType type, string timeZone,
bool canViewLocation, List<UnitActiveRole> activeRoles, List<PersonName> names)
{
var data = new UnitsInfoResultData();
Expand Down
14 changes: 12 additions & 2 deletions Web/Resgrid.WebCore/Areas/User/Controllers/UnitsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Resgrid.WebCore.Areas.User.Models;
using Resgrid.WebCore.Areas.User.Models.Personnel;
using System.Web;
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;

namespace Resgrid.Web.Areas.User.Controllers
{
Expand Down Expand Up @@ -68,13 +69,17 @@ public async Task<IActionResult> Index()
model.Department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId);
model.CanUserAddUnit = await _limitsService.CanDepartmentAddNewUnit(DepartmentId);
model.Groups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);
model.Units = await _unitsService.GetUnitsForDepartmentUnlimitedAsync(DepartmentId);
model.Units = new List<Unit>();
var units = await _unitsService.GetUnitsForDepartmentUnlimitedAsync(DepartmentId);
model.States = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId);
model.UnitStatuses = await _customStateService.GetAllActiveUnitStatesForDepartmentAsync(DepartmentId);
model.UnitCustomStates = new Dictionary<int, CustomState>();

foreach (var unit in model.Units)
foreach (var unit in units)
{
if (!await _authorizationService.CanUserViewUnitViaMatrixAsync(unit.UnitId, UserId, DepartmentId))
continue;

var type = await _unitsService.GetUnitTypeByNameAsync(DepartmentId, unit.Type);
if (type != null && type.CustomStatesId.HasValue)
{
Expand All @@ -85,6 +90,8 @@ public async Task<IActionResult> Index()
model.UnitCustomStates.Add(unit.UnitId, customStates);
}
}

model.Units.Add(unit);
}

if (model.Department.IsUserAnAdmin(UserId))
Expand Down Expand Up @@ -1052,6 +1059,9 @@ public async Task<IActionResult> GetUnitsList()

foreach (var unit in units)
{
if (!await _authorizationService.CanUserViewUnitViaMatrixAsync(unit.UnitId, UserId, DepartmentId))
continue;

var unitJson = new UnitForListJson();
unitJson.Name = unit.Name;
unitJson.Type = unit.Type;
Expand Down
2 changes: 1 addition & 1 deletion Web/Resgrid.WebCore/Areas/User/Views/Security/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@

<tr>
<td>
Who can view groups and units
Who can view units
</td>
<td style="max-width: 350px">
By default all users can see all units in the system. This option allows you to limit who can units in the system.
Expand Down

0 comments on commit 6043bf3

Please sign in to comment.