From b1e9c005b7aa1fb57681b710801eb59bba305262 Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Fri, 11 Dec 2020 21:14:50 -0800 Subject: [PATCH] Add "Mark all as seen" button to notification dropdown (#2101) --- .../Components/NotificationsDropdown/Default.cshtml | 4 ++++ BTCPayServer/Controllers/NotificationsController.cs | 11 +++++++++++ .../Services/Notifications/NotificationSender.cs | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/BTCPayServer/Components/NotificationsDropdown/Default.cshtml b/BTCPayServer/Components/NotificationsDropdown/Default.cshtml index aa6f8f9b3..5b15fce75 100644 --- a/BTCPayServer/Components/NotificationsDropdown/Default.cshtml +++ b/BTCPayServer/Components/NotificationsDropdown/Default.cshtml @@ -2,6 +2,7 @@ @inject UserManager 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 @@ } See All +
+ +
} diff --git a/BTCPayServer/Controllers/NotificationsController.cs b/BTCPayServer/Controllers/NotificationsController.cs index f9fde9360..900446031 100644 --- a/BTCPayServer/Controllers/NotificationsController.cs +++ b/BTCPayServer/Controllers/NotificationsController.cs @@ -206,6 +206,17 @@ namespace BTCPayServer.Controllers return RedirectToAction(nameof(Index)); } + [HttpPost] + public async Task 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); diff --git a/BTCPayServer/Services/Notifications/NotificationSender.cs b/BTCPayServer/Services/Notifications/NotificationSender.cs index e6c7b9630..58e750c20 100644 --- a/BTCPayServer/Services/Notifications/NotificationSender.cs +++ b/BTCPayServer/Services/Notifications/NotificationSender.cs @@ -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 {