feat: add a wait before a notice can be accepted

This commit is contained in:
2026-11-13 22:46:07 +01:00
parent 28b6244a17
commit 93036bae89
12 changed files with 131 additions and 7 deletions
+5
View File
@@ -27,6 +27,11 @@ public class Notice
/// </summary>
public bool RequireAccept { get; set; }
/// <summary>
/// Gets or sets the number of seconds the notice has to be on screen before it can be accepted.
/// </summary>
public int AcceptDelaySeconds { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the notice is shown at all.
/// </summary>
@@ -20,6 +20,11 @@ public class NoticeDraft
/// </summary>
public bool RequireAccept { get; set; }
/// <summary>
/// Gets or sets the number of seconds the notice has to be on screen before it can be accepted.
/// </summary>
public int AcceptDelaySeconds { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the notice is shown.
/// </summary>
@@ -19,6 +19,11 @@ public static class NoticeRules
/// </summary>
public const int MaxBodyLength = 20000;
/// <summary>
/// Longest wait before a notice can be accepted, in seconds.
/// </summary>
public const int MaxAcceptDelaySeconds = 600;
/// <summary>
/// Checks whether a notice is addressed to a user.
/// </summary>
@@ -124,6 +129,11 @@ public static class NoticeRules
return "Body is too long.";
}
if (draft.AcceptDelaySeconds < 0 || draft.AcceptDelaySeconds > MaxAcceptDelaySeconds)
{
return "The wait before accepting has to be between 0 and 600 seconds.";
}
if (draft.Target is { AllUsers: false } target && (target.UserIds is null || target.UserIds.Count == 0))
{
return "Select at least one user or address all users.";
@@ -210,6 +210,7 @@ public class NoticeService
notice.Title = (draft.Title ?? string.Empty).Trim();
notice.Body = (draft.Body ?? string.Empty).Replace("\r\n", "\n", StringComparison.Ordinal).Trim();
notice.RequireAccept = draft.RequireAccept;
notice.AcceptDelaySeconds = draft.RequireAccept ? draft.AcceptDelaySeconds : 0;
notice.Enabled = draft.Enabled;
var allUsers = draft.Target?.AllUsers ?? true;