mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-03 17:36:59 +01:00
Removing obsolete NotificationDbSaver hosted service
This commit is contained in:
parent
b19298f633
commit
741b93dc04
4 changed files with 25 additions and 46 deletions
|
@ -201,7 +201,6 @@ namespace BTCPayServer.Hosting
|
||||||
|
|
||||||
services.AddSingleton<ChangellyClientProvider>();
|
services.AddSingleton<ChangellyClientProvider>();
|
||||||
|
|
||||||
services.AddSingleton<IHostedService, NotificationDbSaver>();
|
|
||||||
services.AddSingleton<NotificationManager>();
|
services.AddSingleton<NotificationManager>();
|
||||||
services.AddScoped<NotificationSender>();
|
services.AddScoped<NotificationSender>();
|
||||||
|
|
||||||
|
|
|
@ -2,48 +2,15 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BTCPayServer.Data;
|
using BTCPayServer.Data;
|
||||||
using BTCPayServer.Events;
|
|
||||||
using BTCPayServer.Models.NotificationViewModels;
|
using BTCPayServer.Models.NotificationViewModels;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
|
||||||
namespace BTCPayServer.HostedServices
|
namespace BTCPayServer.Services.Notifications
|
||||||
{
|
{
|
||||||
public class NotificationDbSaver : EventHostedServiceBase
|
|
||||||
{
|
|
||||||
private readonly ApplicationDbContextFactory _ContextFactory;
|
|
||||||
|
|
||||||
public NotificationDbSaver(ApplicationDbContextFactory contextFactory,
|
|
||||||
EventAggregator eventAggregator) : base(eventAggregator)
|
|
||||||
{
|
|
||||||
_ContextFactory = contextFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void SubscribeToEvents()
|
|
||||||
{
|
|
||||||
Subscribe<NotificationEvent>();
|
|
||||||
base.SubscribeToEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override async Task ProcessEvent(object evt, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var casted = (NotificationEvent)evt;
|
|
||||||
using (var db = _ContextFactory.CreateContext())
|
|
||||||
{
|
|
||||||
foreach (var uid in casted.ApplicationUserIds)
|
|
||||||
{
|
|
||||||
var data = casted.Notification.ToData(uid);
|
|
||||||
db.Notifications.Add(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
await db.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class NotificationManager
|
public class NotificationManager
|
||||||
{
|
{
|
||||||
private readonly ApplicationDbContextFactory _factory;
|
private readonly ApplicationDbContextFactory _factory;
|
|
@ -11,6 +11,7 @@ namespace BTCPayServer.Services.Notifications
|
||||||
{
|
{
|
||||||
private readonly UserManager<ApplicationUser> _userManager;
|
private readonly UserManager<ApplicationUser> _userManager;
|
||||||
private readonly EventAggregator _eventAggregator;
|
private readonly EventAggregator _eventAggregator;
|
||||||
|
private readonly ApplicationDbContextFactory _ContextFactory;
|
||||||
|
|
||||||
public NotificationSender(UserManager<ApplicationUser> userManager, EventAggregator eventAggregator)
|
public NotificationSender(UserManager<ApplicationUser> userManager, EventAggregator eventAggregator)
|
||||||
{
|
{
|
||||||
|
@ -22,16 +23,28 @@ namespace BTCPayServer.Services.Notifications
|
||||||
{
|
{
|
||||||
var admins = await _userManager.GetUsersInRoleAsync(Roles.ServerAdmin);
|
var admins = await _userManager.GetUsersInRoleAsync(Roles.ServerAdmin);
|
||||||
var adminUids = admins.Select(a => a.Id).ToArray();
|
var adminUids = admins.Select(a => a.Id).ToArray();
|
||||||
var evt = new NotificationEvent
|
|
||||||
|
var notif = new NewVersionNotification
|
||||||
|
{
|
||||||
|
Version = version
|
||||||
|
};
|
||||||
|
using (var db = _ContextFactory.CreateContext())
|
||||||
|
{
|
||||||
|
foreach (var uid in adminUids)
|
||||||
|
{
|
||||||
|
var data = notif.ToData(uid);
|
||||||
|
db.Notifications.Add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
// propagate notification
|
||||||
|
_eventAggregator.Publish(new NotificationEvent
|
||||||
{
|
{
|
||||||
ApplicationUserIds = adminUids,
|
ApplicationUserIds = adminUids,
|
||||||
Notification = new NewVersionNotification
|
Notification = notif
|
||||||
{
|
});
|
||||||
Version = version
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
_eventAggregator.Publish(evt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
@inject BTCPayServer.HostedServices.NotificationManager notificationManager
|
@inject BTCPayServer.Services.Notifications.NotificationManager notificationManager
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var notificationModel = notificationManager.GetSummaryNotifications(User);
|
var notificationModel = notificationManager.GetSummaryNotifications(User);
|
||||||
|
|
Loading…
Add table
Reference in a new issue