Added rich notifications for mobile

pull/2452/head
Jamie 6 years ago
parent 505bd06035
commit b7c0c07534

@ -6,6 +6,6 @@ namespace Ombi.Api.Notifications
{
public interface IOneSignalApi
{
Task<OneSignalNotificationResponse> PushNotification(List<string> playerIds, string message);
Task<OneSignalNotificationResponse> PushNotification(List<string> playerIds, string message, bool isAdminNotification, int requestId, int requestType);
}
}

@ -4,18 +4,22 @@
{
public string app_id { get; set; }
public string[] include_player_ids { get; set; }
public Data data { get; set; }
public object data { get; set; }
public Button[] buttons { get; set; }
public Contents contents { get; set; }
}
public class Data
{
public string foo { get; set; }
}
public class Contents
{
public string en { get; set; }
}
public class Button
{
public string id { get; set; }
public string text { get; set; }
//public string icon { get; set; }
}
}

@ -20,7 +20,7 @@ namespace Ombi.Api.Notifications
private readonly IApplicationConfigRepository _appConfig;
private const string ApiUrl = "https://onesignal.com/api/v1/notifications";
public async Task<OneSignalNotificationResponse> PushNotification(List<string> playerIds, string message)
public async Task<OneSignalNotificationResponse> PushNotification(List<string> playerIds, string message, bool isAdminNotification, int requestId, int requestType)
{
if (!playerIds.Any())
{
@ -39,6 +39,17 @@ namespace Ombi.Api.Notifications
include_player_ids = playerIds.ToArray()
};
if (isAdminNotification)
{
// Add the action buttons
body.data = new { requestid = requestId, requestType = requestType};
body.buttons = new[]
{
new Button {id = "approve", text = "Approve Request"},
new Button {id = "deny", text = "Deny Request"},
};
}
request.AddJsonBody(body);
var result = await _api.Request<OneSignalNotificationResponse>(request);

@ -57,7 +57,7 @@ namespace Ombi.Notifications.Agents
// Get admin devices
var playerIds = await GetAdmins(NotificationType.NewRequest);
await Send(playerIds, notification, settings);
await Send(playerIds, notification, settings, model, true);
}
protected override async Task NewIssue(NotificationOptions model, MobileNotificationSettings settings)
@ -75,7 +75,7 @@ namespace Ombi.Notifications.Agents
// Get admin devices
var playerIds = await GetAdmins(NotificationType.Issue);
await Send(playerIds, notification, settings);
await Send(playerIds, notification, settings, model);
}
protected override async Task IssueComment(NotificationOptions model, MobileNotificationSettings settings)
@ -97,13 +97,13 @@ namespace Ombi.Notifications.Agents
{
// Send to user
var playerIds = GetUsers(model, NotificationType.IssueComment);
await Send(playerIds, notification, settings);
await Send(playerIds, notification, settings, model);
}
else
{
// Send to admin
var playerIds = await GetAdmins(NotificationType.IssueComment);
await Send(playerIds, notification, settings);
await Send(playerIds, notification, settings, model);
}
}
}
@ -124,7 +124,7 @@ namespace Ombi.Notifications.Agents
// Send to user
var playerIds = GetUsers(model, NotificationType.IssueResolved);
await Send(playerIds, notification, settings);
await Send(playerIds, notification, settings, model);
}
@ -149,7 +149,7 @@ namespace Ombi.Notifications.Agents
};
// Get admin devices
var playerIds = await GetAdmins(NotificationType.Test);
await Send(playerIds, notification, settings);
await Send(playerIds, notification, settings, model);
}
protected override async Task RequestDeclined(NotificationOptions model, MobileNotificationSettings settings)
@ -168,7 +168,7 @@ namespace Ombi.Notifications.Agents
// Send to user
var playerIds = GetUsers(model, NotificationType.RequestDeclined);
await AddSubscribedUsers(playerIds);
await Send(playerIds, notification, settings);
await Send(playerIds, notification, settings, model);
}
protected override async Task RequestApproved(NotificationOptions model, MobileNotificationSettings settings)
@ -188,7 +188,7 @@ namespace Ombi.Notifications.Agents
var playerIds = GetUsers(model, NotificationType.RequestApproved);
await AddSubscribedUsers(playerIds);
await Send(playerIds, notification, settings);
await Send(playerIds, notification, settings, model);
}
protected override async Task AvailableRequest(NotificationOptions model, MobileNotificationSettings settings)
@ -207,20 +207,20 @@ namespace Ombi.Notifications.Agents
var playerIds = GetUsers(model, NotificationType.RequestAvailable);
await AddSubscribedUsers(playerIds);
await Send(playerIds, notification, settings);
await Send(playerIds, notification, settings, model);
}
protected override Task Send(NotificationMessage model, MobileNotificationSettings settings)
{
throw new NotImplementedException();
}
protected async Task Send(List<string> playerIds, NotificationMessage model, MobileNotificationSettings settings)
protected async Task Send(List<string> playerIds, NotificationMessage model, MobileNotificationSettings settings, NotificationOptions requestModel, bool isAdminNotification = false)
{
if (playerIds == null || !playerIds.Any())
{
return;
}
var response = await _api.PushNotification(playerIds, model.Message);
var response = await _api.PushNotification(playerIds, model.Message, isAdminNotification, requestModel.RequestId, (int)requestModel.RequestType);
_logger.LogDebug("Sent message to {0} recipients with message id {1}", response.recipients, response.id);
}
@ -239,7 +239,7 @@ namespace Ombi.Notifications.Agents
}
var playerIds = user.NotificationUserIds.Select(x => x.PlayerId).ToList();
await Send(playerIds, notification, settings);
await Send(playerIds, notification, settings, model);
}
private async Task<List<string>> GetAdmins(NotificationType type)

Loading…
Cancel
Save