From 4c0b3a9327a793c8e599c8c380d2504b72950eb6 Mon Sep 17 00:00:00 2001 From: uwaa Date: Mon, 6 Jan 2025 23:58:20 +0000 Subject: [PATCH] pleroma: add more endpoints --- Pleroma/Models/ModerationLogEntry.cs | 31 ++++++++++++++++++++++++++++ Pleroma/Models/Page.cs | 2 +- Pleroma/Pleroma.cs | 28 +++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 Pleroma/Models/ModerationLogEntry.cs diff --git a/Pleroma/Models/ModerationLogEntry.cs b/Pleroma/Models/ModerationLogEntry.cs new file mode 100644 index 0000000..4607f13 --- /dev/null +++ b/Pleroma/Models/ModerationLogEntry.cs @@ -0,0 +1,31 @@ +using System.Text.Json.Nodes; + +namespace Uwaa.Pleroma; + +public class ModerationLog +{ + [JsonPropertyName("items")] + public ModerationLogEntry[] Items { get; set; } = null!; + + [JsonPropertyName("total")] + public int Total { get; set; } +} + +public class ModerationLogEntry +{ + [JsonPropertyName("data")] + public JsonObject Data { get; set; } = null!; + + [JsonPropertyName("id")] + public int ID { get; set; } + + [JsonPropertyName("message")] + public string Message { get; set; } = null!; + + [JsonPropertyName("time")] + public int Time { get; set; } + + public string Action => (string)Data["action"]!; + + public override string ToString() => Message; +} diff --git a/Pleroma/Models/Page.cs b/Pleroma/Models/Page.cs index 4d563e7..0ad86d8 100644 --- a/Pleroma/Models/Page.cs +++ b/Pleroma/Models/Page.cs @@ -9,7 +9,7 @@ public class Page public int PageSize { get; set; } } -public class UsersPage +public class UsersPage : Page { [JsonPropertyName("users")] public AccountInfo[] Users { get; set; } = null!; diff --git a/Pleroma/Pleroma.cs b/Pleroma/Pleroma.cs index e47a9a0..ebb597b 100644 --- a/Pleroma/Pleroma.cs +++ b/Pleroma/Pleroma.cs @@ -403,6 +403,26 @@ public class Pleroma }))!; } + /// + /// Feature one of your own public statuses at the top of your profile + /// + /// The status to pin. + /// The pinned status, if it exists. + public Task Pin(StatusID status) + { + return Retry(() => new HttpRequestMessage(HttpMethod.Post, $"/api/v1/statuses/{WebUtility.UrlEncode(status.ID)}/pin")); + } + + /// + /// Unfeature a status from the top of your profile + /// + /// The status to unpin. + /// The unpinned status, if it exists. + public Task Unpin(StatusID status) + { + return Retry(() => new HttpRequestMessage(HttpMethod.Post, $"/api/v1/statuses/{WebUtility.UrlEncode(status.ID)}/unpin")); + } + /// /// Reposts/boosts/shares a status. /// @@ -849,6 +869,14 @@ public class PleromaAdmin : Pleroma return req; })!; } + + public Task GetModerationLog(int page = 1) + { + return Retry(() => new HttpRequestMessage(HttpMethod.Get, $"/api/v1/pleroma/admin/moderation_log" + CreateQuery(addPair => + { + addPair("page", page.ToString()); + })))!; + } } [JsonConverter(typeof(EnumLowerCaseConverter))]