Add "Mark all as seen" button to notification dropdown (#2101)

This commit is contained in:
Umar Bolatov 2020-12-11 21:14:50 -08:00 committed by GitHub
parent 0d144d088e
commit b1e9c005b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View file

@ -2,6 +2,7 @@
@inject UserManager<ApplicationUser> UserManager
@inject CssThemeManager CssThemeManager
@using BTCPayServer.HostedServices
@using Microsoft.AspNetCore.Http.Extensions
@model BTCPayServer.Components.NotificationsDropdown.NotificationSummaryViewModel
@if (Model.UnseenCount > 0)
@ -24,6 +25,9 @@
</a>
}
<a class="dropdown-item text-secondary" asp-controller="Notifications" asp-action="Index">See All</a>
<form asp-controller="Notifications" asp-action="MarkAllAsSeen" asp-route-returnUrl="@Context.Request.GetDisplayUrl()" method="post">
<button class="dropdown-item text-secondary" type="submit"><i class="fa fa-eye"></i> Mark all as seen</button>
</form>
</div>
</li>
}

View file

@ -206,6 +206,17 @@ namespace BTCPayServer.Controllers
return RedirectToAction(nameof(Index));
}
[HttpPost]
public async Task<IActionResult> MarkAllAsSeen(string returnUrl)
{
if (!ValidUserClaim(out var userId))
{
return NotFound();
}
await _notificationManager.ToggleSeen(new NotificationsQuery() {Seen = false, UserId = userId}, true);
return Redirect(returnUrl);
}
private bool ValidUserClaim(out string userId)
{
userId = _userManager.GetUserId(User);

View file

@ -13,6 +13,10 @@ namespace BTCPayServer.Services.Notifications
public class UserNotificationsUpdatedEvent
{
public string UserId { get; set; }
public override string ToString()
{
return string.Empty;
}
}
public class NotificationSender
{