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.
+
+ + +
The button stays locked and counts down while the notice is on screen. 0 means no wait.
+