92 lines
No EOL
2.6 KiB
C#
92 lines
No EOL
2.6 KiB
C#
namespace Uwaa.Pleroma;
|
|
|
|
public class Account
|
|
{
|
|
/// <summary>
|
|
/// Pleroma uses 128-bit ids as opposed to Mastodon's 64 bits. However just like Mastodon's ids they are lexically sortable strings
|
|
/// </summary>
|
|
[JsonPropertyName("id")]
|
|
public string ID { get; set; } = null!;
|
|
|
|
[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<AccountField>();
|
|
|
|
[JsonPropertyName("followers_count")]
|
|
public uint Followers { get; set; }
|
|
|
|
[JsonPropertyName("following_count")]
|
|
public uint Following { get; set; }
|
|
|
|
[JsonPropertyName("local")]
|
|
public bool Local { 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)..];
|
|
}
|
|
}
|
|
|
|
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(Account account) => new AccountID(account.ID);
|
|
|
|
public static implicit operator AccountID(Relationship relationship) => new AccountID(relationship.ID);
|
|
|
|
public readonly string ID = id;
|
|
|
|
public override string ToString() => ID;
|
|
}
|
|
|
|
class AccountIDConverter : JsonConverter<AccountID>
|
|
{
|
|
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);
|
|
}
|
|
} |