Wire the client to PrivaPub: one sign-in, real feeds, a globe, nerd stats
One sign-in for both of PrivaPub's APIs: the root logs in on /clientapi, picks a persona, and each persona gets its own Mastodon token in exchange for the JWT (PersonaExchange). HttpService picks credentials and JSON by route (JWT and camelCase for /clientapi, the persona token and snake_case for /api, nothing for /oauth), retries a refused persona token once, and records every request for the nerd stats. The feed page is three columns: navigation with a persona switcher, the feed with a tab per kind (home, local, federated, nearby, communities and circles, direct, notifications, favourites, bookmarks, hashtags), and a 3D globe that looks at the spherical mean of the posts in view and draws a pulse and an arc to a hovered one. Posts sit at their own place, their event's venue, the reader (located posts) or their author's server as PrivaPub publishes it. Cards favourite, boost, bookmark, reply, mute, block and delete; the composer posts with a content warning, visibility, media and alt text, or as a located post. Older pages load as the end nears; newer ones are polled while visible. Nerd stats in tooltips: provenance, author and server, place, media, counts, paging, the globe's camera and frame rate. The mock (Faker, MessagesService, the Message models and store) and the OIDC template leftovers are gone. Strings in English and Italian. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
This commit is contained in:
1 parent
f41ebf2160
commit
827ecb770e
56 files changed
+5367
-832
No files matched your search
@@ -4,6 +4,7 @@ using collAnon.Client.Services;
|
||||
|
||||
using decePubClient.Helpers;
|
||||
using decePubClient.Models;
|
||||
using decePubClient.Models.Mastodon;
|
||||
using decePubClient.Services;
|
||||
|
||||
using Markdig;
|
||||
@@ -20,11 +21,12 @@ using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
|
||||
namespace decePubClient.Extensions
|
||||
{
|
||||
public static class ExtensionMethods
|
||||
public static partial class ExtensionMethods
|
||||
{
|
||||
#region Navigation Manager
|
||||
|
||||
@@ -134,6 +136,9 @@ namespace decePubClient.Extensions
|
||||
return result.Invalidate(localizer["The server reported an internal error (HTTP {0}).", (int)statusCode], (int)statusCode,
|
||||
FailureCodes.ServerError);
|
||||
|
||||
if (TryReadMastodonError(json) is { } mastodonError)
|
||||
return result.Invalidate(mastodonError, (int)statusCode);
|
||||
|
||||
if (json.Contains("\"title\""))
|
||||
{
|
||||
var validationErrors = JsonSerializer.Deserialize<ValidationErrors>(json, SUtility.DefaultSerializer);
|
||||
@@ -154,7 +159,70 @@ namespace decePubClient.Extensions
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Reads a successful response body; a cancelled read returns SUtility.CancellationDefault.</summary>
|
||||
/// <summary>The message of a Mastodon API or /oauth error ({"error": ..., "error_description": ...}), or null.</summary>
|
||||
static string TryReadMastodonError(string json)
|
||||
{
|
||||
if (!json.Contains("\"error\"") || json.Contains("\"errorMessage\""))
|
||||
return null;
|
||||
try
|
||||
{
|
||||
var error = JsonSerializer.Deserialize<MastodonError>(json, SUtility.MastodonSerializer);
|
||||
return error?.ErrorDescription ?? error?.Error;
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a successful Mastodon API body (snake_case); a cancelled read, or a body that does not fit T (written to the
|
||||
/// browser console), returns SUtility.CancellationDefault.
|
||||
/// </summary>
|
||||
public static async Task<T> MastodonReadFromJsonAsync<T>(this HttpResponseMessage response, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<T>(SUtility.MastodonSerializer, cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return SUtility.CancellationDefault<T>();
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
Console.Error.WriteLine($"{nameof(MastodonReadFromJsonAsync)}<{typeof(T).Name}> {response.RequestMessage?.RequestUri}: {ex.Message}");
|
||||
return SUtility.CancellationDefault<T>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The paging cursors of a Mastodon list: max_id from the Link header's next (older items), min_id from its prev
|
||||
/// (newer items). Either is null when the header does not name it.
|
||||
/// </summary>
|
||||
public static (string MaxId, string MinId) PageCursors(this HttpResponseMessage response)
|
||||
{
|
||||
if (!response.Headers.TryGetValues("Link", out var values))
|
||||
return (null, null);
|
||||
string maxId = null, minId = null;
|
||||
foreach (Match link in LinkHeader().Matches(string.Join(',', values)))
|
||||
{
|
||||
var query = HttpUtility.ParseQueryString(new Uri(link.Groups[1].Value, UriKind.Absolute).Query);
|
||||
if (link.Groups[2].Value == "next")
|
||||
maxId = query["max_id"];
|
||||
else if (link.Groups[2].Value == "prev")
|
||||
minId = query["min_id"] ?? query["since_id"];
|
||||
}
|
||||
return (maxId, minId);
|
||||
}
|
||||
|
||||
[GeneratedRegex("<([^>]+)>\\s*;\\s*rel=\"([a-z]+)\"")]
|
||||
private static partial Regex LinkHeader();
|
||||
|
||||
/// <summary>
|
||||
/// Reads a successful /clientapi body; a cancelled read, or a body that does not fit T (written to the browser
|
||||
/// console), returns SUtility.CancellationDefault.
|
||||
/// </summary>
|
||||
public static async Task<T> DefaultReadFromJsonAsync<T>(this HttpResponseMessage response, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
@@ -165,6 +233,11 @@ namespace decePubClient.Extensions
|
||||
{
|
||||
return SUtility.CancellationDefault<T>();
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
Console.Error.WriteLine($"{nameof(DefaultReadFromJsonAsync)}<{typeof(T).Name}> {response.RequestMessage?.RequestUri}: {ex.Message}");
|
||||
return SUtility.CancellationDefault<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public static string Timeframe(this DateTime creationDate, CoalescingStringLocalizer localizer)
|
||||
|
||||
Reference in new issue
Block a user