mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-19 05:33:31 +01:00
Displaying number of unread messages in _Layout.cshtml
This commit is contained in:
parent
3eb503b13b
commit
654bb0c8ca
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -53,4 +54,25 @@ namespace BTCPayServer.HostedServices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class NotificationManager
|
||||||
|
{
|
||||||
|
private readonly ApplicationDbContext _db;
|
||||||
|
|
||||||
|
public NotificationManager(ApplicationDbContext db)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetNotificationCount(ClaimsPrincipal user)
|
||||||
|
{
|
||||||
|
var claimWithId = user.Claims.SingleOrDefault(a => a.Type == ClaimTypes.NameIdentifier);
|
||||||
|
|
||||||
|
// TODO: Soft caching in order not to pound database too much
|
||||||
|
var count = _db.Notifications
|
||||||
|
.Where(a => a.ApplicationUserId == claimWithId.Value && !a.Seen)
|
||||||
|
.Count();
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,6 +201,7 @@ namespace BTCPayServer.Hosting
|
|||||||
services.AddSingleton<ChangellyClientProvider>();
|
services.AddSingleton<ChangellyClientProvider>();
|
||||||
|
|
||||||
services.AddSingleton<IHostedService, NotificationDbSaver>();
|
services.AddSingleton<IHostedService, NotificationDbSaver>();
|
||||||
|
services.AddScoped<NotificationManager>();
|
||||||
|
|
||||||
services.AddSingleton<IHostedService, NBXplorerWaiters>();
|
services.AddSingleton<IHostedService, NBXplorerWaiters>();
|
||||||
services.AddSingleton<IHostedService, InvoiceNotificationManager>();
|
services.AddSingleton<IHostedService, InvoiceNotificationManager>();
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
@inject BTCPayServer.Services.BTCPayServerEnvironment env
|
@inject BTCPayServer.Services.BTCPayServerEnvironment env
|
||||||
@inject BTCPayServer.HostedServices.NBXplorerDashboard dashboard
|
@inject BTCPayServer.HostedServices.NBXplorerDashboard dashboard
|
||||||
@inject BTCPayServer.HostedServices.CssThemeManager themeManager
|
@inject BTCPayServer.HostedServices.CssThemeManager themeManager
|
||||||
|
@inject BTCPayServer.HostedServices.NotificationManager notificationManager
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@ -80,7 +81,11 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a asp-area="" asp-controller="Notifications" asp-action="Index" title="Notifications" class="nav-link js-scroll-trigger" id="Notifications"><i class="fa fa-bell"></i></a>
|
<a asp-area="" asp-controller="Notifications" asp-action="Index" title="Notifications" class="nav-link js-scroll-trigger" id="Notifications"><i class="fa fa-bell"></i></a>
|
||||||
<span class="alerts-badge badge badge-pill badge-danger">6</span>
|
@{ var notifications = notificationManager.GetNotificationCount(User); }
|
||||||
|
@if (notifications > 0)
|
||||||
|
{
|
||||||
|
<span class="alerts-badge badge badge-pill badge-danger">@notifications</span>
|
||||||
|
}
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a asp-area="" asp-controller="Account" asp- asp-action="Logout" title="Logout" class="nav-link js-scroll-trigger" id="Logout"><i class="fa fa-sign-out"></i></a>
|
<a asp-area="" asp-controller="Account" asp- asp-action="Logout" title="Logout" class="nav-link js-scroll-trigger" id="Logout"><i class="fa fa-sign-out"></i></a>
|
||||||
|
Loading…
Reference in New Issue
Block a user