✨ Mark all notifications read
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
using DysonNetwork.Shared.Data;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Pusher.Notification;
|
||||
|
@@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NodaTime;
|
||||
using AccountService = DysonNetwork.Shared.Proto.AccountService;
|
||||
|
||||
namespace DysonNetwork.Pusher.Notification;
|
||||
|
||||
@@ -13,8 +12,8 @@ namespace DysonNetwork.Pusher.Notification;
|
||||
[Route("/api/notifications")]
|
||||
public class NotificationController(
|
||||
AppDatabase db,
|
||||
PushService nty,
|
||||
AccountService.AccountServiceClient accounts) : ControllerBase
|
||||
PushService nty
|
||||
) : ControllerBase
|
||||
{
|
||||
[HttpGet("count")]
|
||||
[Authorize]
|
||||
@@ -59,6 +58,18 @@ public class NotificationController(
|
||||
return Ok(notifications);
|
||||
}
|
||||
|
||||
[HttpPost("all/read")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult> MarkAllNotificationsViewed()
|
||||
{
|
||||
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||
if (currentUserValue is not Account currentUser) return Unauthorized();
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
|
||||
await nty.MarkAllNotificationsViewed(accountId);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
public class PushNotificationSubscribeRequest
|
||||
{
|
||||
[MaxLength(4096)] public string DeviceToken { get; set; } = null!;
|
||||
@@ -112,10 +123,10 @@ public class NotificationController(
|
||||
|
||||
public class NotificationRequest
|
||||
{
|
||||
[Required] [MaxLength(1024)] public string Topic { get; set; } = null!;
|
||||
[Required] [MaxLength(1024)] public string Title { get; set; } = null!;
|
||||
[Required][MaxLength(1024)] public string Topic { get; set; } = null!;
|
||||
[Required][MaxLength(1024)] public string Title { get; set; } = null!;
|
||||
[MaxLength(2048)] public string? Subtitle { get; set; }
|
||||
[Required] [MaxLength(4096)] public string Content { get; set; } = null!;
|
||||
[Required][MaxLength(4096)] public string Content { get; set; } = null!;
|
||||
public Dictionary<string, object>? Meta { get; set; }
|
||||
public int Priority { get; set; } = 10;
|
||||
}
|
||||
@@ -149,4 +160,4 @@ public class NotificationController(
|
||||
);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -173,6 +173,14 @@ public class PushService
|
||||
);
|
||||
}
|
||||
|
||||
public async Task MarkAllNotificationsViewed(Guid accountId)
|
||||
{
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
await _db.Notifications
|
||||
.Where(n => n.AccountId == accountId)
|
||||
.ExecuteUpdateAsync(s => s.SetProperty(n => n.ViewedAt, now));
|
||||
}
|
||||
|
||||
public async Task SendNotificationBatch(Notification notification, List<Guid> accounts, bool save = false)
|
||||
{
|
||||
if (save)
|
||||
|
Reference in New Issue
Block a user