2026-10-04 11:03:14 +02:00
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
|
|
|
|
|
using decePubClient.Models.Types;
|
|
|
|
|
using decePubClient.Resources;
|
|
|
|
|
|
|
|
|
|
namespace decePubClient.Models;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A new post or reply. It goes through the Mastodon API (plain text, a content warning, a visibility and media) unless
|
|
|
|
|
/// it is located (text only, kept within RangeKm of where it was written, never federated) or meant for a group; those
|
|
|
|
|
/// go through /clientapi/post/insert.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ComposeForm
|
|
|
|
|
{
|
|
|
|
|
public const int MaxContentLength = 5_000;
|
|
|
|
|
|
|
|
|
|
/// <summary>The status a reply answers.</summary>
|
|
|
|
|
public string InReplyToId { get; set; }
|
|
|
|
|
/// <summary>The community or circle the post is for.</summary>
|
|
|
|
|
public string GroupId { get; set; }
|
|
|
|
|
|
|
|
|
|
[Required(ErrorMessageResourceName = ValidationNames.Required, ErrorMessageResourceType = typeof(ErrorMessages))]
|
|
|
|
|
public MessageType MessageType { get; set; } = MessageType.Public;
|
|
|
|
|
public bool HasContentWarning { get; set; }
|
|
|
|
|
[StringLength(500, ErrorMessageResourceName = ValidationNames.MaxLength, ErrorMessageResourceType = typeof(ErrorMessages))]
|
|
|
|
|
public string SpoilerText { get; set; }
|
|
|
|
|
[StringLength(MaxContentLength, ErrorMessageResourceName = ValidationNames.MaxLength, ErrorMessageResourceType = typeof(ErrorMessages))]
|
|
|
|
|
public string Content { get; set; }
|
|
|
|
|
public List<UploadMedia> Media { get; set; } = [];
|
|
|
|
|
|
|
|
|
|
/// <summary>A located post: shown only to readers within RangeKm of Latitude/Longitude.</summary>
|
|
|
|
|
public bool IsLocated { get; set; }
|
|
|
|
|
[Range(1, 50)]
|
|
|
|
|
public double RangeKm { get; set; } = 5;
|
|
|
|
|
public double? Latitude { get; set; }
|
|
|
|
|
public double? Longitude { get; set; }
|
|
|
|
|
|
2026-10-05 04:42:42 +02:00
|
|
|
/// <summary>A poll instead of media: two to four choices, open ExpiresIn seconds, one choice or several.</summary>
|
|
|
|
|
public bool HasPoll { get; set; }
|
|
|
|
|
public List<string> PollOptions { get; set; } = ["", ""];
|
|
|
|
|
public int PollExpiresIn { get; set; } = 86400;
|
|
|
|
|
public bool PollMultiple { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>The post this one quotes.</summary>
|
|
|
|
|
public string QuotedStatusId { get; set; }
|
|
|
|
|
|
2026-10-05 03:53:51 +02:00
|
|
|
/// <summary>Whether the post waits for ScheduledAt (a datetime-local value, the reader's own time) instead of going now.</summary>
|
|
|
|
|
public bool IsScheduled { get; set; }
|
|
|
|
|
public string ScheduledAt { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>When the post is to be published, in UTC, or null when it goes now or ScheduledAt is not a time.</summary>
|
|
|
|
|
public DateTime? ScheduledAtUtc => IsScheduled && DateTime.TryParse(ScheduledAt, System.Globalization.CultureInfo.InvariantCulture,
|
|
|
|
|
System.Globalization.DateTimeStyles.AssumeLocal, out var local) ? local.ToUniversalTime() : null;
|
|
|
|
|
|
2026-10-04 11:03:14 +02:00
|
|
|
[JsonIgnore, Bindable(false)]
|
|
|
|
|
public MediaType MediaType { get; set; } = MediaType.Images;
|
|
|
|
|
[JsonIgnore, Bindable(false)]
|
|
|
|
|
public bool IsScopeOptionsOpen { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>The Mastodon visibility of MessageType.</summary>
|
|
|
|
|
public string Visibility => MessageType switch
|
|
|
|
|
{
|
|
|
|
|
MessageType.Direct => "direct",
|
|
|
|
|
MessageType.FollowersOnly => "private",
|
|
|
|
|
MessageType.Unlisted => "unlisted",
|
|
|
|
|
_ => "public"
|
|
|
|
|
};
|
|
|
|
|
}
|