76 lines
No EOL
2.1 KiB
C#
76 lines
No EOL
2.1 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Uwaa.Pleroma.API;
|
|
|
|
[JsonConverter(typeof(PublishStatusConverter))]
|
|
public class PublishStatus
|
|
{
|
|
public string Content { get; set; }
|
|
|
|
public bool Sensitive { get; set; }
|
|
|
|
public int? ExpiresIn { get; set; } = null!;
|
|
|
|
public string? ReplyTo { get; set; }
|
|
|
|
public StatusVisibility Visibility { get; set; } = StatusVisibility.Public;
|
|
|
|
/// <summary>
|
|
/// Called after the status has been successfully published.
|
|
/// </summary>
|
|
[JsonIgnore]
|
|
public Action? OnPublish;
|
|
|
|
public PublishStatus(string content)
|
|
{
|
|
Content = content ?? throw new ArgumentNullException(nameof(content));
|
|
}
|
|
}
|
|
|
|
class PublishStatusConverter : JsonConverter<PublishStatus>
|
|
{
|
|
public sealed override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(PublishStatus);
|
|
|
|
public override PublishStatus Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, PublishStatus status, JsonSerializerOptions options)
|
|
{
|
|
writer.WriteStartObject();
|
|
|
|
writer.WritePropertyName("status");
|
|
writer.WriteStringValue(status.Content);
|
|
|
|
writer.WritePropertyName("content-type");
|
|
writer.WriteStringValue("text/plain");
|
|
|
|
if (status.Sensitive)
|
|
{
|
|
writer.WritePropertyName("sensitive");
|
|
writer.WriteBooleanValue(true);
|
|
}
|
|
|
|
if (status.ExpiresIn.HasValue)
|
|
{
|
|
writer.WritePropertyName("expires_in");
|
|
writer.WriteNumberValue(status.ExpiresIn.Value);
|
|
}
|
|
|
|
if (status.ReplyTo != null)
|
|
{
|
|
writer.WritePropertyName("in_reply_to_id");
|
|
writer.WriteStringValue(status.ReplyTo);
|
|
}
|
|
|
|
if (status.Visibility != StatusVisibility.Public)
|
|
{
|
|
writer.WritePropertyName("visibility");
|
|
writer.WriteStringValue(status.Visibility.ToString().ToLowerInvariant());
|
|
}
|
|
|
|
writer.WriteEndObject();
|
|
}
|
|
} |