using System.Text.Json.Serialization;
namespace decePubClient.Models.Mastodon;
/// A persona's filter (Mastodon's v2 filters): words and posts it would rather not see in some contexts, to be
/// warned about, hidden or blurred. Statuses carry the filters they match (Status.Filtered); the client applies the
/// context and the action.
public class Filter
{
public string Id { get; set; }
public string Title { get; set; }
public List Context { get; set; } = [];
public DateTime? ExpiresAt { get; set; }
public FilterAction FilterAction { get; set; } = FilterAction.Warn;
public List Keywords { get; set; } = [];
public List Statuses { get; set; } = [];
public bool IsActive => ExpiresAt is null || ExpiresAt > DateTime.UtcNow;
}
public class FilterKeyword
{
public string Id { get; set; }
public string Keyword { get; set; }
public bool WholeWord { get; set; }
}
public class FilterStatus
{
public string Id { get; set; }
public string StatusId { get; set; }
}
public class FilterResult
{
public Filter Filter { get; set; }
public List KeywordMatches { get; set; } = [];
public List StatusMatches { get; set; } = [];
}
/// Where a filter applies; a card is told which of these it is shown in.
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum FilterContext
{
[JsonStringEnumMemberName("home")] Home,
[JsonStringEnumMemberName("notifications")] Notifications,
[JsonStringEnumMemberName("public")] Public,
[JsonStringEnumMemberName("thread")] Thread,
[JsonStringEnumMemberName("account")] Account
}
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum FilterAction
{
/// The post is folded behind the filter's title.
[JsonStringEnumMemberName("warn")] Warn,
/// The post is not shown at all.
[JsonStringEnumMemberName("hide")] Hide,
/// The post's media are blurred, as sensitive media are.
[JsonStringEnumMemberName("blur")] Blur
}
/// What making or changing a filter sends; ExpiresIn 0 means never.
public class FilterForm
{
public string Title { get; set; }
public List Context { get; set; } = [];
public FilterAction FilterAction { get; set; } = FilterAction.Warn;
public int? ExpiresIn { get; set; }
public List KeywordsAttributes { get; set; } = [];
}
public class FilterKeywordForm
{
public string Id { get; set; }
public string Keyword { get; set; }
public bool WholeWord { get; set; }
[JsonPropertyName("_destroy")]
public bool? Destroy { get; set; }
}