namespace Uwaa.Pleroma;
public class Status : ASObject
{
///
/// HTML-encoded status content
///
[JsonPropertyName("content")]
public string HtmlContent { get; set; } = null!;
///
/// The account that authored this status
///
[JsonPropertyName("account")]
public Account Account { get; set; } = null!;
///
/// The date when this status was created
///
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; }
///
/// Have you favourited this status?
///
[JsonPropertyName("favourited")]
public bool Favourited { get; set; }
///
/// How many favourites this status has received
///
[JsonPropertyName("favourites_count")]
public int FavouriteCount { get; set; }
///
/// ID of the account being replied to
///
[JsonPropertyName("in_reply_to_account_id")]
public string? ReplyToAccount { get; set; } = null;
///
/// ID of the status being replied
///
[JsonPropertyName("in_reply_to_id")]
public string? ReplyTo { get; set; } = null;
///
/// Primary language of this status
///
[JsonPropertyName("language")]
public string? Language { get; set; }
///
/// Media that is attached to this status
///
[JsonPropertyName("media_attachments")]
public Attachment[] Attachments { get; set; } = Array.Empty();
///
/// Mentions of users within the status content
///
[JsonPropertyName("mentions")]
public Mention[] Mentions { get; set; } = Array.Empty();
///
/// Have you pinned this status? Only appears if the status is pinnable.
///
[JsonPropertyName("pinned")]
public bool Pinned { get; set; }
///
/// Additional pleroma-specific data.
///
[JsonPropertyName("pleroma")]
public PleromaStatusData Pleroma { get; set; } = null!;
///
/// The status being reblogged
///
[JsonPropertyName("reblog")]
public Status? Reblog { get; set; }
///
/// Have you boosted this status?
///
[JsonPropertyName("reblogged")]
public bool Reblogged { get; set; }
///
/// How many boosts this status has received
///
[JsonPropertyName("reblogs_count")]
public int ReblogCount { get; set; }
///
/// How many replies this status has received
///
[JsonPropertyName("replies_count")]
public int ReplyCount { get; set; }
///
/// Is this status marked as sensitive content?
///
[JsonPropertyName("sensitive")]
public bool Sensitive { get; set; }
///
/// Subject or summary line, below which status content is collapsed until expanded
///
[JsonPropertyName("spoiler_text")]
public string SpoilerText { get; set; } = null!;
///
/// Hashtags included in the status.
///
[JsonPropertyName("tags")]
public Hashtag[] Tags { get; set; } = Array.Empty();
///
/// URI of the status used for federation
///
[JsonPropertyName("uri")]
public string URI { get; set; } = null!;
///
/// A link to the status's HTML representation
///
[JsonPropertyName("url")]
public string? URL { get; set; }
///
/// Visibility of this status
///
[JsonPropertyName("visibility")]
public StatusVisibility Visibility { get; set; }
///
/// Plain text content of that status.
///
[JsonIgnore]
public string Content => Pleroma?.Content?.Plain ?? HtmlContent;
///
/// Returns true if a status mentions or replies to a user.
///
/// The ID of the user.
public bool IsInteracting(AccountID user)
{
return ReplyToAccount == user.ID || Mentions.Any(m => m.ID == user.ID);
}
public override string ToString() => $"{Account?.Username ?? "unknown"}: \"{Content}\"";
}
///
/// Additional pleroma-specific data for a .
///
public class PleromaStatusData
{
[JsonPropertyName("content")]
public PleromaStatusContent Content { get; set; } = null!;
[JsonPropertyName("local")]
public bool Local { get; set; }
[JsonPropertyName("quote_id")]
public string? QuoteID { get; set; }
}
public class PleromaStatusContent
{
[JsonPropertyName("text/plain")]
public string Plain { get; set; } = null!;
}
[JsonConverter(typeof(StatusIDConverter))]
public readonly struct StatusID(string id) : IEquatable
{
public static implicit operator StatusID(string id) => new StatusID(id);
public static implicit operator StatusID(Status status) => new StatusID(status.ID);
public readonly string ID = id;
public override string ToString() => ID;
public static bool operator ==(StatusID left, StatusID right) => left.Equals(right);
public static bool operator !=(StatusID left, StatusID right) => !(left == right);
public override bool Equals(object? obj) => (obj is StatusID id && Equals(id)) || (obj is Status status && Equals(status));
public bool Equals(StatusID other) => ID == other.ID;
public override int GetHashCode() => ID.GetHashCode();
}
class StatusIDConverter : JsonConverter
{
public override bool CanConvert(Type type) => type.IsAssignableTo(typeof(StatusID));
public override StatusID Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return new StatusID(reader.GetString() ?? throw new NullReferenceException("Expected a string, got null"));
}
public override void Write(Utf8JsonWriter writer, StatusID value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ID);
}
}