From 93036bae897ba88d6fff49a5aa7f7ae37b213f39 Mon Sep 17 00:00:00 2001
From: JoshiCodes <55353244+JoshiCodes@users.noreply.github.com>
Date: Fri, 13 Nov 2026 22:46:07 +0100
Subject: [PATCH] feat: add a wait before a notice can be accepted
---
.../NoticeRulesTests.cs | 12 +++++
.../NoticeServiceTests.cs | 20 ++++++++
.../Api/HeraldController.cs | 1 +
Jellyfin.Plugin.Herald/Api/PendingNotice.cs | 5 ++
.../Configuration/configPage.html | 14 ++++-
Jellyfin.Plugin.Herald/Notices/Notice.cs | 5 ++
Jellyfin.Plugin.Herald/Notices/NoticeDraft.cs | 5 ++
Jellyfin.Plugin.Herald/Notices/NoticeRules.cs | 10 ++++
.../Notices/NoticeService.cs | 1 +
.../Storage/HeraldDatabase.cs | 5 ++
.../Storage/SqliteNoticeStore.cs | 9 ++--
Jellyfin.Plugin.Herald/Web/client.js | 51 +++++++++++++++++--
12 files changed, 131 insertions(+), 7 deletions(-)
diff --git a/Jellyfin.Plugin.Herald.Tests/NoticeRulesTests.cs b/Jellyfin.Plugin.Herald.Tests/NoticeRulesTests.cs
index 65f9284..b1a63f9 100644
--- a/Jellyfin.Plugin.Herald.Tests/NoticeRulesTests.cs
+++ b/Jellyfin.Plugin.Herald.Tests/NoticeRulesTests.cs
@@ -143,6 +143,18 @@ public class NoticeRulesTests
Assert.NotNull(NoticeRules.ValidateDraft(new NoticeDraft { Title = title }));
}
+ [Theory]
+ [InlineData(-1, false)]
+ [InlineData(0, true)]
+ [InlineData(600, true)]
+ [InlineData(601, false)]
+ public void Draft_AcceptDelayHasToBeInRange(int seconds, bool valid)
+ {
+ var draft = new NoticeDraft { Title = "Hi", RequireAccept = true, AcceptDelaySeconds = seconds };
+
+ Assert.Equal(valid, NoticeRules.ValidateDraft(draft) is null);
+ }
+
[Fact]
public void Draft_SelectedUsersNeedAtLeastOneUser()
{
diff --git a/Jellyfin.Plugin.Herald.Tests/NoticeServiceTests.cs b/Jellyfin.Plugin.Herald.Tests/NoticeServiceTests.cs
index d40d3ca..92c7f40 100644
--- a/Jellyfin.Plugin.Herald.Tests/NoticeServiceTests.cs
+++ b/Jellyfin.Plugin.Herald.Tests/NoticeServiceTests.cs
@@ -30,6 +30,26 @@ public sealed class NoticeServiceTests : IDisposable
return notice;
}
+ [Fact]
+ public void AcceptDelay_IsStoredForMustAcceptNotices()
+ {
+ var created = Create("Terms", d =>
+ {
+ d.RequireAccept = true;
+ d.AcceptDelaySeconds = 15;
+ });
+
+ Assert.Equal(15, _service.Get(created.Id)!.AcceptDelaySeconds);
+ }
+
+ [Fact]
+ public void AcceptDelay_IsDroppedWithoutRequireAccept()
+ {
+ var created = Create("Info", d => d.AcceptDelaySeconds = 15);
+
+ Assert.Equal(0, _service.Get(created.Id)!.AcceptDelaySeconds);
+ }
+
[Fact]
public void Create_RoundTripsThroughTheDatabase()
{
diff --git a/Jellyfin.Plugin.Herald/Api/HeraldController.cs b/Jellyfin.Plugin.Herald/Api/HeraldController.cs
index 22c4784..25895e2 100644
--- a/Jellyfin.Plugin.Herald/Api/HeraldController.cs
+++ b/Jellyfin.Plugin.Herald/Api/HeraldController.cs
@@ -83,6 +83,7 @@ public class HeraldController : ControllerBase
Title = n.Title,
Body = n.Body,
RequireAccept = n.RequireAccept,
+ AcceptDelaySeconds = n.AcceptDelaySeconds,
Revision = n.Revision
}));
}
diff --git a/Jellyfin.Plugin.Herald/Api/PendingNotice.cs b/Jellyfin.Plugin.Herald/Api/PendingNotice.cs
index eb26fe5..6003464 100644
--- a/Jellyfin.Plugin.Herald/Api/PendingNotice.cs
+++ b/Jellyfin.Plugin.Herald/Api/PendingNotice.cs
@@ -27,6 +27,11 @@ public class PendingNotice
///
public bool RequireAccept { get; set; }
+ ///
+ /// Gets or sets the number of seconds the notice has to be on screen before it can be accepted.
+ ///
+ public int AcceptDelaySeconds { get; set; }
+
///
/// Gets or sets the revision to send back with the response.
///
diff --git a/Jellyfin.Plugin.Herald/Configuration/configPage.html b/Jellyfin.Plugin.Herald/Configuration/configPage.html
index fcea3cc..3da44fb 100644
--- a/Jellyfin.Plugin.Herald/Configuration/configPage.html
+++ b/Jellyfin.Plugin.Herald/Configuration/configPage.html
@@ -72,6 +72,11 @@
The notice can only be closed with an "Accept" button.
+