namespace Uwaa.Pleroma; public class Account : ASObject { [JsonPropertyName("bot")] public bool Bot { get; set; } [JsonPropertyName("display_name")] public string DisplayName { get; set; } = null!; [JsonPropertyName("fields")] public AccountField[] Fields { get; set; } = Array.Empty(); [JsonPropertyName("followers_count")] public uint Followers { get; set; } [JsonPropertyName("following_count")] public uint Following { get; set; } [JsonPropertyName("locked")] public bool Locked { get; set; } [JsonPropertyName("note")] public string Bio { get; set; } = null!; [JsonPropertyName("statuses_count")] public uint StatusesCount { get; set; } [JsonPropertyName("url")] public string URL { get; set; } = null!; [JsonPropertyName("username")] public string Username { get; set; } = null!; [JsonPropertyName("acct")] public string Webfinger { get; set; } = null!; public string? Instance { get { if (Webfinger == null) return null; int spl = Webfinger.IndexOf('@'); if (spl == -1) return null; return Webfinger[(spl + 1)..]; } } /// /// If true, the user opts-out of automated interactions. Bots must not follow these users, nor reply, favorite, boost, or store posts from these users. /// public bool NoBot => Bio != null && Bio.Contains("#nobot", StringComparison.OrdinalIgnoreCase); [JsonConstructor()] internal Account() { } public override string ToString() => $"@{Webfinger}"; } [JsonConverter(typeof(AccountIDConverter))] public readonly struct AccountID(string id) { public static implicit operator AccountID(string id) => new AccountID(id); public static implicit operator AccountID?(string? id) => id == null ? new AccountID?() : new AccountID(id); public static implicit operator AccountID(Account account) => new AccountID(account.ID); public static implicit operator AccountID?(Account? account) => account == null ? new AccountID?() : new AccountID(account.ID); public static implicit operator AccountID(Relationship relationship) => new AccountID(relationship.ID); public static implicit operator AccountID(AccountInfo userInfo) => new AccountID(userInfo.ID); public readonly string ID = id; public override string ToString() => ID; public static bool operator ==(AccountID left, AccountID right) => left.Equals(right); public static bool operator !=(AccountID left, AccountID right) => !(left == right); public override bool Equals(object? obj) => (obj is AccountID id && Equals(id)) || (obj is Account status && Equals(status)); public bool Equals(AccountID other) => ID == other.ID; public override int GetHashCode() => ID.GetHashCode(); } class AccountIDConverter : JsonConverter { public override bool CanConvert(Type type) => type.IsAssignableTo(typeof(AccountID)); public override AccountID Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { return new AccountID(reader.GetString() ?? throw new NullReferenceException("Expected a string, got null")); } public override void Write(Utf8JsonWriter writer, AccountID value, JsonSerializerOptions options) { writer.WriteStringValue(value.ID); } }