mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-13 01:56:55 -07:00
Added the test button for mobile notifications
This commit is contained in:
parent
2b227e7201
commit
1935d70cf7
9 changed files with 74 additions and 5 deletions
|
@ -152,6 +152,7 @@ namespace Ombi.DependencyInjection
|
|||
services.AddTransient<IMattermostNotification, MattermostNotification>();
|
||||
services.AddTransient<IPushoverNotification, PushoverNotification>();
|
||||
services.AddTransient<ITelegramNotification, TelegramNotification>();
|
||||
services.AddTransient<IMobileNotification, MobileNotification>();
|
||||
services.AddTransient<IChangeLogProcessor, ChangeLogProcessor>();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
namespace Ombi.Notifications.Agents
|
||||
{
|
||||
public interface IMobileNotification : INotification
|
||||
{
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ using Ombi.Store.Repository.Requests;
|
|||
|
||||
namespace Ombi.Notifications.Agents
|
||||
{
|
||||
public class MobileNotification : BaseNotification<MobileNotificationSettings>
|
||||
public class MobileNotification : BaseNotification<MobileNotificationSettings>, IMobileNotification
|
||||
{
|
||||
public MobileNotification(IOneSignalApi api, ISettingsService<MobileNotificationSettings> sn, ILogger<MobileNotification> log, INotificationTemplatesRepository r,
|
||||
IMovieRequestRepository m, ITvRequestRepository t, ISettingsService<CustomizationSettings> s, IRepository<NotificationUserId> notification,
|
||||
|
@ -232,7 +232,13 @@ namespace Ombi.Notifications.Agents
|
|||
Message = message,
|
||||
};
|
||||
// Send to user
|
||||
var playerIds = await GetAdmins(NotificationType.RequestAvailable);
|
||||
var user = await _userManager.Users.Include(x => x.NotificationUserIds).FirstOrDefaultAsync(x => x.Id.Equals(model.UserId));
|
||||
if (user == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var playerIds = user.NotificationUserIds.Select(x => x.PlayerId).ToList();
|
||||
await Send(playerIds, notification, settings);
|
||||
}
|
||||
|
||||
|
|
|
@ -101,3 +101,8 @@ export interface IMattermostNotifcationSettings extends INotificationSettings {
|
|||
export interface IMobileNotifcationSettings extends INotificationSettings {
|
||||
notificationTemplates: INotificationTemplates[];
|
||||
}
|
||||
|
||||
export interface IMobileNotificationTestSettings {
|
||||
settings: IMobileNotifcationSettings;
|
||||
userId: string;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
IEmailNotificationSettings,
|
||||
IEmbyServer,
|
||||
IMattermostNotifcationSettings,
|
||||
IMobileNotificationTestSettings,
|
||||
INewsletterNotificationSettings,
|
||||
IPlexServer,
|
||||
IPushbulletNotificationSettings,
|
||||
|
@ -82,4 +83,7 @@ export class TesterService extends ServiceHelpers {
|
|||
public newsletterTest(settings: INewsletterNotificationSettings): Observable<boolean> {
|
||||
return this.http.post<boolean>(`${this.url}newsletter`, JSON.stringify(settings), {headers: this.headers});
|
||||
}
|
||||
public mobileNotificationTest(settings: IMobileNotificationTestSettings): Observable<boolean> {
|
||||
return this.http.post<boolean>(`${this.url}mobile`, JSON.stringify(settings), {headers: this.headers});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,21 @@
|
|||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<label for="select" class="control-label">User to send test notification to</label>
|
||||
<div>
|
||||
<select class="form-control form-control-custom" id="select" [(ngModel)]="testUserId" [ngModelOptions]="{standalone: true}">
|
||||
<option value="">Please select</option>
|
||||
<option *ngFor="let x of userList" [value]="x.id">{{x.username}}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div>
|
||||
<button [disabled]="form.invalid" type="button" (click)="test(form)" class="btn btn-danger-outline">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
|
|
|
@ -15,6 +15,7 @@ export class MobileComponent implements OnInit {
|
|||
public templates: INotificationTemplates[];
|
||||
public form: FormGroup;
|
||||
public userList: IMobileUsersViewModel[];
|
||||
public testUserId: string = "d164439a-6f23-43c6-bc12-6a8d3d89dbf5";
|
||||
|
||||
constructor(private settingsService: SettingsService,
|
||||
private notificationService: NotificationService,
|
||||
|
@ -64,8 +65,12 @@ export class MobileComponent implements OnInit {
|
|||
this.notificationService.error("Please check your entered values");
|
||||
return;
|
||||
}
|
||||
if(!this.testUserId) {
|
||||
this.notificationService.warning("Warning","Please select a user to send the test notification");
|
||||
return;
|
||||
}
|
||||
|
||||
this.testerService.discordTest(form.value).subscribe(x => {
|
||||
this.testerService.mobileNotificationTest({settings: form.value, userId: this.testUserId}).subscribe(x => {
|
||||
if (x) {
|
||||
this.notificationService.success("Successfully sent a Mobile message, please check the admin mobile device");
|
||||
} else {
|
||||
|
|
|
@ -14,6 +14,7 @@ using Ombi.Core.Models.UI;
|
|||
using Ombi.Core.Notifications;
|
||||
using Ombi.Core.Settings.Models.External;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Models;
|
||||
using Ombi.Notifications;
|
||||
using Ombi.Notifications.Agents;
|
||||
using Ombi.Notifications.Models;
|
||||
|
@ -37,7 +38,7 @@ namespace Ombi.Controllers.External
|
|||
public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN,
|
||||
IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm,
|
||||
IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger<TesterController> log, IEmailProvider provider,
|
||||
ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter)
|
||||
ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter, IMobileNotification mobileNotification)
|
||||
{
|
||||
Service = service;
|
||||
DiscordNotification = notification;
|
||||
|
@ -56,6 +57,7 @@ namespace Ombi.Controllers.External
|
|||
TelegramNotification = telegram;
|
||||
SickRageApi = srApi;
|
||||
Newsletter = newsletter;
|
||||
MobileNotification = mobileNotification;
|
||||
}
|
||||
|
||||
private INotificationService Service { get; }
|
||||
|
@ -75,6 +77,7 @@ namespace Ombi.Controllers.External
|
|||
private ITelegramNotification TelegramNotification { get; }
|
||||
private ISickRageApi SickRageApi { get; }
|
||||
private INewsletterJob Newsletter { get; }
|
||||
private IMobileNotification MobileNotification { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -388,5 +391,21 @@ namespace Ombi.Controllers.External
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("mobile")]
|
||||
public async Task<bool> MobileNotificationTest([FromBody] MobileNotificationTestViewModel settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
await MobileNotification.NotifyAsync(new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1, UserId = settings.UserId}, settings.Settings);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.LogError(LoggingEvents.Api, e, "Could not test Mobile Notifications");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
10
src/Ombi/Models/MobileNotificationTestViewModel.cs
Normal file
10
src/Ombi/Models/MobileNotificationTestViewModel.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using Ombi.Settings.Settings.Models.Notifications;
|
||||
|
||||
namespace Ombi.Models
|
||||
{
|
||||
public class MobileNotificationTestViewModel
|
||||
{
|
||||
public string UserId { get; set; }
|
||||
public MobileNotificationSettings Settings { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue