From c606e4ed02ac950419b0841545fb2228ce88e8f9 Mon Sep 17 00:00:00 2001 From: uwaa Date: Fri, 27 Dec 2024 17:46:14 +0000 Subject: [PATCH] pleroma stuff --- Pleroma.Test/Program.cs | 4 +-- Pleroma/Models/AccountField.cs | 2 +- Pleroma/Models/Attachment.cs | 10 -------- Pleroma/Models/Notification.cs | 2 +- Pleroma/Models/Status.cs | 2 +- Pleroma/Pleroma.cs | 45 +++++++++++++++++++++++++++++++--- 6 files changed, 46 insertions(+), 19 deletions(-) diff --git a/Pleroma.Test/Program.cs b/Pleroma.Test/Program.cs index bbc5162..6ef2a42 100644 --- a/Pleroma.Test/Program.cs +++ b/Pleroma.Test/Program.cs @@ -15,9 +15,7 @@ static class Program static void PrintStatus(Status status) { Console.Write('\t'); - Console.Write(status.CreatedAt.ToShortDateString()); - Console.Write(' '); - Console.Write(status.CreatedAt.ToLongTimeString()); + Console.Write(status.CreatedAt.ToString("dd/MM/yy HH:mm:ss")); Console.Write(' '); Console.WriteLine(status); } diff --git a/Pleroma/Models/AccountField.cs b/Pleroma/Models/AccountField.cs index 86c6f20..c3bedf2 100644 --- a/Pleroma/Models/AccountField.cs +++ b/Pleroma/Models/AccountField.cs @@ -8,7 +8,7 @@ public class AccountField [JsonPropertyName("value")] public string Value { get; set; } = null!; - public DateTime? VerifiedAt { get; set; } + public DateTimeOffset? VerifiedAt { get; set; } [JsonConstructor()] internal AccountField() diff --git a/Pleroma/Models/Attachment.cs b/Pleroma/Models/Attachment.cs index 3a4d20e..c939eac 100644 --- a/Pleroma/Models/Attachment.cs +++ b/Pleroma/Models/Attachment.cs @@ -54,16 +54,6 @@ public class Attachment internal Attachment() { } - - /// - /// Downloads the attachment. - /// - public async Task Download() - { - using HttpClient client = new HttpClient(); - HttpResponseMessage res = await client.GetAsync(URL); - return await res.Content.ReadAsByteArrayAsync(); - } } [JsonConverter(typeof(EnumLowerCaseConverter))] diff --git a/Pleroma/Models/Notification.cs b/Pleroma/Models/Notification.cs index 4f6b795..4c650be 100644 --- a/Pleroma/Models/Notification.cs +++ b/Pleroma/Models/Notification.cs @@ -9,7 +9,7 @@ public class Notification : ASObject public Account Account { get; set; } = null!; [JsonPropertyName("created_at")] - public DateTime CreatedAt { get; set; } + public DateTimeOffset CreatedAt { get; set; } /// /// Group key shared by similar notifications diff --git a/Pleroma/Models/Status.cs b/Pleroma/Models/Status.cs index a9990ec..06d5d57 100644 --- a/Pleroma/Models/Status.cs +++ b/Pleroma/Models/Status.cs @@ -18,7 +18,7 @@ public class Status : ASObject /// The date when this status was created /// [JsonPropertyName("created_at")] - public DateTime CreatedAt { get; set; } + public DateTimeOffset CreatedAt { get; set; } /// /// Have you favourited this status? diff --git a/Pleroma/Pleroma.cs b/Pleroma/Pleroma.cs index 5284846..2a0cc0f 100644 --- a/Pleroma/Pleroma.cs +++ b/Pleroma/Pleroma.cs @@ -237,7 +237,7 @@ public class Pleroma public Task PostStatus(string? content = null, bool sensitive = false, int? expiresIn = null, - string? replyTo = null, + StatusID? replyTo = null, string? quoting = null, string? language = null, MediaID[]? attachments = null, @@ -273,10 +273,10 @@ public class Pleroma writer.WriteNumberValue(expiresIn.Value); } - if (replyTo != null) + if (replyTo.HasValue) { writer.WritePropertyName("in_reply_to_id"); - writer.WriteStringValue(replyTo); + writer.WriteStringValue(replyTo.Value.ID); } if (quoting != null) @@ -615,6 +615,26 @@ public class Pleroma })))!; } + /// + /// Downloads an attachment. + /// + public async Task Download(Attachment attachment) + { + HttpResponseMessage res = await HttpClient.GetAsync(attachment.URL); + res.EnsureSuccessStatusCode(); + return await res.Content.ReadAsByteArrayAsync(); + } + + /// + /// Downloads an attachment as a . + /// + public async Task DownloadStream(Attachment attachment) + { + HttpResponseMessage res = await HttpClient.GetAsync(attachment.URL); + res.EnsureSuccessStatusCode(); + return await res.Content.ReadAsStreamAsync(); + } + /// /// Notifications concerning the user. This API returns Link headers containing links to the next/previous page. However, the links can also be constructed dynamically using query params and id values. /// @@ -683,6 +703,25 @@ public class Pleroma /// Array of notification IDs to dismiss public Task Dismiss(NotificationID[] notifications) { + if (notifications.Length == 0) + return Task.CompletedTask; + + return Retry(() => new HttpRequestMessage(HttpMethod.Delete, $"/api/v1/notifications/destroy_multiple" + CreateQuery(addPair => + { + foreach (NotificationID id in notifications) + addPair("ids[]", id.ID); + }))); + } + + /// + /// Clears multiple notifications from the server. + /// + /// Array of notifications to dismiss + public Task Dismiss(Notification[] notifications) + { + if (notifications.Length == 0) + return Task.CompletedTask; + return Retry(() => new HttpRequestMessage(HttpMethod.Delete, $"/api/v1/notifications/destroy_multiple" + CreateQuery(addPair => { foreach (NotificationID id in notifications)