2020-08-12 16:02:13 +09:00
|
|
|
@inject LinkGenerator linkGenerator
|
2020-10-20 13:09:09 +02:00
|
|
|
@inject UserManager<ApplicationUser> UserManager
|
|
|
|
@inject CssThemeManager CssThemeManager
|
|
|
|
@using BTCPayServer.HostedServices
|
2021-03-19 12:05:46 +01:00
|
|
|
@using BTCPayServer.Views.Notifications
|
2020-12-11 21:14:50 -08:00
|
|
|
@using Microsoft.AspNetCore.Http.Extensions
|
2020-08-12 16:02:13 +09:00
|
|
|
@model BTCPayServer.Components.NotificationsDropdown.NotificationSummaryViewModel
|
2021-01-07 01:07:42 -08:00
|
|
|
@addTagHelper *, BundlerMinifier.TagHelpers
|
2020-06-24 10:23:16 +02:00
|
|
|
|
|
|
|
@if (Model.UnseenCount > 0)
|
|
|
|
{
|
|
|
|
<li class="nav-item dropdown" id="notifications-nav-item">
|
2021-03-19 12:05:46 +01:00
|
|
|
<a class="nav-link js-scroll-trigger @ViewData.IsActiveCategory(typeof(NotificationsNavPages))" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" id="Notifications">
|
2021-03-05 08:48:15 +01:00
|
|
|
<span class="d-lg-none d-sm-block">Notifications</span><i class="fa fa-bell d-lg-inline-block d-none"></i>
|
2020-06-24 10:23:16 +02:00
|
|
|
</a>
|
|
|
|
<span class="alerts-badge badge badge-pill badge-danger">@Model.UnseenCount</span>
|
2021-01-07 01:07:42 -08:00
|
|
|
<div class="dropdown-menu dropdown-menu-right text-center notification-dropdown" aria-labelledby="navbarDropdown">
|
|
|
|
<div class="d-flex align-items-center justify-content-between py-3 px-4 border-bottom border-light">
|
|
|
|
<h5 class="m-0">Notifications</h5>
|
|
|
|
<form asp-controller="Notifications" asp-action="MarkAllAsSeen" asp-route-returnUrl="@Context.Request.GetCurrentPathWithQueryString()" method="post">
|
2021-04-07 19:37:35 -07:00
|
|
|
<button class="btn btn-link p-0" type="submit">Mark all as seen</button>
|
2021-01-07 01:07:42 -08:00
|
|
|
</form>
|
|
|
|
</div>
|
2020-06-24 10:23:16 +02:00
|
|
|
@foreach (var notif in Model.Last5)
|
|
|
|
{
|
2021-01-07 01:07:42 -08:00
|
|
|
<a asp-action="NotificationPassThrough" asp-controller="Notifications" asp-route-id="@notif.Id" class="notification d-flex align-items-center dropdown-item border-bottom border-light py-3 px-4">
|
|
|
|
<div class="mr-3">
|
|
|
|
<vc:icon symbol="note" />
|
2020-06-24 10:23:16 +02:00
|
|
|
</div>
|
2021-01-07 01:07:42 -08:00
|
|
|
|
|
|
|
<div class="notification-item__content">
|
2021-04-07 19:37:35 -07:00
|
|
|
<div class="text-left text-wrap">
|
2021-01-07 01:07:42 -08:00
|
|
|
@notif.Body
|
|
|
|
</div>
|
|
|
|
<div class="text-left d-flex">
|
|
|
|
<small class="text-muted" data-timeago-unixms="@notif.Created.ToUnixTimeMilliseconds()">@notif.Created.ToTimeAgo()</small>
|
|
|
|
</div>
|
2020-06-24 10:23:16 +02:00
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
}
|
2021-01-07 01:07:42 -08:00
|
|
|
<div class="p-3">
|
2021-04-07 19:37:35 -07:00
|
|
|
<a asp-controller="Notifications" asp-action="Index">View all</a>
|
2021-01-07 01:07:42 -08:00
|
|
|
</div>
|
2020-06-24 10:23:16 +02:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<li class="nav-item" id="notifications-nav-item">
|
2021-03-19 12:05:46 +01:00
|
|
|
<a asp-controller="Notifications" asp-action="Index" title="Notifications" class="nav-link js-scroll-trigger @ViewData.IsActiveCategory(typeof(NotificationsNavPages))" id="Notifications">
|
2021-03-05 08:48:15 +01:00
|
|
|
<span class="d-lg-none d-sm-block">Notifications</span><i class="fa fa-bell d-lg-inline-block d-none"></i>
|
2020-06-24 10:23:16 +02:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
}
|
2020-10-20 13:09:09 +02:00
|
|
|
@{
|
|
|
|
var disabled = CssThemeManager.Policies.DisableInstantNotifications;
|
|
|
|
if (!disabled)
|
|
|
|
{
|
|
|
|
var user = await UserManager.GetUserAsync(User);
|
2021-04-20 07:06:32 +02:00
|
|
|
disabled = user?.DisabledNotifications == "all";
|
2020-10-20 13:09:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
@if (!disabled)
|
|
|
|
{
|
2020-08-12 16:02:13 +09:00
|
|
|
|
2020-10-20 13:09:09 +02:00
|
|
|
<script type="text/javascript">
|
2020-08-12 16:02:13 +09:00
|
|
|
|
2020-10-20 13:09:09 +02:00
|
|
|
var supportsWebSockets = 'WebSocket' in window && window.WebSocket.CLOSING === 2;
|
2020-08-12 16:02:13 +09:00
|
|
|
|
2020-10-20 13:09:09 +02:00
|
|
|
if (supportsWebSockets) {
|
2020-08-12 16:02:13 +09:00
|
|
|
|
2020-10-20 13:09:09 +02:00
|
|
|
var loc = window.location, ws_uri;
|
|
|
|
if (loc.protocol === "https:") {
|
|
|
|
ws_uri = "wss:";
|
|
|
|
} else {
|
|
|
|
ws_uri = "ws:";
|
|
|
|
}
|
|
|
|
ws_uri += "//" + loc.host;
|
|
|
|
ws_uri += "@linkGenerator.GetPathByAction("SubscribeUpdates", "Notifications")";
|
|
|
|
var newDataEndpoint = "@linkGenerator.GetPathByAction("GetNotificationDropdownUI", "Notifications")";
|
|
|
|
|
|
|
|
try {
|
|
|
|
socket = new WebSocket(ws_uri);
|
|
|
|
socket.onmessage = function (e) {
|
|
|
|
$.get(newDataEndpoint, function(data){
|
|
|
|
$("#notifications-nav-item").replaceWith($(data));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
socket.onerror = function (e) {
|
|
|
|
console.error("Error while connecting to websocket for notifications (callback)", e);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.error("Error while connecting to websocket for notifications", e);
|
|
|
|
}
|
2020-08-12 16:02:13 +09:00
|
|
|
}
|
2020-10-20 13:09:09 +02:00
|
|
|
</script>
|
2020-08-12 16:02:13 +09:00
|
|
|
}
|