| | | 1 | | using System.Globalization; |
| | | 2 | | using System.Text; |
| | | 3 | | |
| | | 4 | | namespace ArturRios.Heimdall.Command.Services; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// The exact wording of the scope owner invitation notices (UC-21, UC-60, UC-61), kept beside the port so |
| | | 8 | | /// the logging and Mailgun senders cannot drift from the sentence the specification fixes. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// The names come from records administrators control — a Scope Admin can rename themselves — and reach |
| | | 12 | | /// another person's mailbox, so each is folded onto one line (<see cref="OneLine" />). Nothing a caller |
| | | 13 | | /// controls is put in a subject. |
| | | 14 | | /// </remarks> |
| | | 15 | | public static class ScopeInvitationNoticeText |
| | | 16 | | { |
| | | 17 | | public const string InvitationSubject = "You were invited to co-own a scope"; |
| | | 18 | | |
| | | 19 | | public const string AnswerSubject = "Your scope invitation was answered"; |
| | | 20 | | |
| | | 21 | | /// <summary>The invitee's notice. No token and no link (TH-41).</summary> |
| | | 22 | | public static string Invitation(string inviterName, string scopeName, DateTime expiresAt) => |
| | 7 | 23 | | $"{OneLine(inviterName)} invited you to co-own the scope {OneLine(scopeName)}. " + |
| | 7 | 24 | | $"Sign in to Heimdall to accept or decline. The invitation expires on {Format(expiresAt)}."; |
| | | 25 | | |
| | | 26 | | /// <summary>The inviter's notice once the invitee answered.</summary> |
| | | 27 | | public static string Answer(string inviteeName, string scopeName, bool accepted) => |
| | 5 | 28 | | $"{OneLine(inviteeName)} {(accepted ? "accepted" : "declined")} your invitation to co-own the scope " + |
| | 5 | 29 | | $"{OneLine(scopeName)}."; |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// <paramref name="value" /> with every control character and every run of whitespace, line breaks and |
| | | 33 | | /// Unicode line separators included, turned into one space, and none at either end. |
| | | 34 | | /// </summary> |
| | | 35 | | public static string OneLine(string value) |
| | | 36 | | { |
| | 31 | 37 | | var builder = new StringBuilder(value.Length); |
| | 31 | 38 | | var pendingSpace = false; |
| | | 39 | | |
| | 664 | 40 | | foreach (var character in value) |
| | | 41 | | { |
| | 301 | 42 | | if (char.IsControl(character) || char.IsWhiteSpace(character)) |
| | | 43 | | { |
| | 36 | 44 | | pendingSpace = builder.Length > 0; |
| | | 45 | | |
| | 36 | 46 | | continue; |
| | | 47 | | } |
| | | 48 | | |
| | 265 | 49 | | if (pendingSpace) |
| | | 50 | | { |
| | 21 | 51 | | builder.Append(' '); |
| | 21 | 52 | | pendingSpace = false; |
| | | 53 | | } |
| | | 54 | | |
| | 265 | 55 | | builder.Append(character); |
| | | 56 | | } |
| | | 57 | | |
| | 31 | 58 | | return builder.ToString(); |
| | | 59 | | } |
| | | 60 | | |
| | 7 | 61 | | private static string Format(DateTime at) => at.ToString("yyyy-MM-dd HH:mm 'UTC'", CultureInfo.InvariantCulture); |
| | | 62 | | } |