mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Added rich notifications for mobile
This commit is contained in:
parent
505bd06035
commit
b7c0c07534
4 changed files with 34 additions and 19 deletions
|
@ -6,6 +6,6 @@ namespace Ombi.Api.Notifications
|
||||||
{
|
{
|
||||||
public interface IOneSignalApi
|
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 app_id { get; set; }
|
||||||
public string[] include_player_ids { 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 Contents contents { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Data
|
|
||||||
{
|
|
||||||
public string foo { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Contents
|
public class Contents
|
||||||
{
|
{
|
||||||
public string en { get; set; }
|
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 readonly IApplicationConfigRepository _appConfig;
|
||||||
private const string ApiUrl = "https://onesignal.com/api/v1/notifications";
|
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())
|
if (!playerIds.Any())
|
||||||
{
|
{
|
||||||
|
@ -39,6 +39,17 @@ namespace Ombi.Api.Notifications
|
||||||
include_player_ids = playerIds.ToArray()
|
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);
|
request.AddJsonBody(body);
|
||||||
|
|
||||||
var result = await _api.Request<OneSignalNotificationResponse>(request);
|
var result = await _api.Request<OneSignalNotificationResponse>(request);
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace Ombi.Notifications.Agents
|
||||||
|
|
||||||
// Get admin devices
|
// Get admin devices
|
||||||
var playerIds = await GetAdmins(NotificationType.NewRequest);
|
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)
|
protected override async Task NewIssue(NotificationOptions model, MobileNotificationSettings settings)
|
||||||
|
@ -75,7 +75,7 @@ namespace Ombi.Notifications.Agents
|
||||||
|
|
||||||
// Get admin devices
|
// Get admin devices
|
||||||
var playerIds = await GetAdmins(NotificationType.Issue);
|
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)
|
protected override async Task IssueComment(NotificationOptions model, MobileNotificationSettings settings)
|
||||||
|
@ -97,13 +97,13 @@ namespace Ombi.Notifications.Agents
|
||||||
{
|
{
|
||||||
// Send to user
|
// Send to user
|
||||||
var playerIds = GetUsers(model, NotificationType.IssueComment);
|
var playerIds = GetUsers(model, NotificationType.IssueComment);
|
||||||
await Send(playerIds, notification, settings);
|
await Send(playerIds, notification, settings, model);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Send to admin
|
// Send to admin
|
||||||
var playerIds = await GetAdmins(NotificationType.IssueComment);
|
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
|
// Send to user
|
||||||
var playerIds = GetUsers(model, NotificationType.IssueResolved);
|
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
|
// Get admin devices
|
||||||
var playerIds = await GetAdmins(NotificationType.Test);
|
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)
|
protected override async Task RequestDeclined(NotificationOptions model, MobileNotificationSettings settings)
|
||||||
|
@ -168,7 +168,7 @@ namespace Ombi.Notifications.Agents
|
||||||
// Send to user
|
// Send to user
|
||||||
var playerIds = GetUsers(model, NotificationType.RequestDeclined);
|
var playerIds = GetUsers(model, NotificationType.RequestDeclined);
|
||||||
await AddSubscribedUsers(playerIds);
|
await AddSubscribedUsers(playerIds);
|
||||||
await Send(playerIds, notification, settings);
|
await Send(playerIds, notification, settings, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task RequestApproved(NotificationOptions model, MobileNotificationSettings settings)
|
protected override async Task RequestApproved(NotificationOptions model, MobileNotificationSettings settings)
|
||||||
|
@ -188,7 +188,7 @@ namespace Ombi.Notifications.Agents
|
||||||
var playerIds = GetUsers(model, NotificationType.RequestApproved);
|
var playerIds = GetUsers(model, NotificationType.RequestApproved);
|
||||||
|
|
||||||
await AddSubscribedUsers(playerIds);
|
await AddSubscribedUsers(playerIds);
|
||||||
await Send(playerIds, notification, settings);
|
await Send(playerIds, notification, settings, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task AvailableRequest(NotificationOptions model, MobileNotificationSettings settings)
|
protected override async Task AvailableRequest(NotificationOptions model, MobileNotificationSettings settings)
|
||||||
|
@ -207,20 +207,20 @@ namespace Ombi.Notifications.Agents
|
||||||
var playerIds = GetUsers(model, NotificationType.RequestAvailable);
|
var playerIds = GetUsers(model, NotificationType.RequestAvailable);
|
||||||
|
|
||||||
await AddSubscribedUsers(playerIds);
|
await AddSubscribedUsers(playerIds);
|
||||||
await Send(playerIds, notification, settings);
|
await Send(playerIds, notification, settings, model);
|
||||||
}
|
}
|
||||||
protected override Task Send(NotificationMessage model, MobileNotificationSettings settings)
|
protected override Task Send(NotificationMessage model, MobileNotificationSettings settings)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
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())
|
if (playerIds == null || !playerIds.Any())
|
||||||
{
|
{
|
||||||
return;
|
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);
|
_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();
|
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)
|
private async Task<List<string>> GetAdmins(NotificationType type)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue