Files
decePubClient/Models/Mastodon/Filter.cs
T

80 lines
2.6 KiB
C#
Raw Normal View History

using System.Text.Json.Serialization;
namespace decePubClient.Models.Mastodon;
/// <summary>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.</summary>
public class Filter
{
public string Id { get; set; }
public string Title { get; set; }
public List<FilterContext> Context { get; set; } = [];
public DateTime? ExpiresAt { get; set; }
public FilterAction FilterAction { get; set; } = FilterAction.Warn;
public List<FilterKeyword> Keywords { get; set; } = [];
public List<FilterStatus> 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<string> KeywordMatches { get; set; } = [];
public List<string> StatusMatches { get; set; } = [];
}
/// <summary>Where a filter applies; a card is told which of these it is shown in.</summary>
[JsonConverter(typeof(JsonStringEnumConverter<FilterContext>))]
public enum FilterContext
{
[JsonStringEnumMemberName("home")] Home,
[JsonStringEnumMemberName("notifications")] Notifications,
[JsonStringEnumMemberName("public")] Public,
[JsonStringEnumMemberName("thread")] Thread,
[JsonStringEnumMemberName("account")] Account
}
[JsonConverter(typeof(JsonStringEnumConverter<FilterAction>))]
public enum FilterAction
{
/// <summary>The post is folded behind the filter's title.</summary>
[JsonStringEnumMemberName("warn")] Warn,
/// <summary>The post is not shown at all.</summary>
[JsonStringEnumMemberName("hide")] Hide,
/// <summary>The post's media are blurred, as sensitive media are.</summary>
[JsonStringEnumMemberName("blur")] Blur
}
/// <summary>What making or changing a filter sends; ExpiresIn 0 means never.</summary>
public class FilterForm
{
public string Title { get; set; }
public List<FilterContext> Context { get; set; } = [];
public FilterAction FilterAction { get; set; } = FilterAction.Warn;
public int? ExpiresIn { get; set; }
public List<FilterKeywordForm> 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; }
}