R8 the Mastodon API made real in decePub: featured tags, notify, languages, recommendations, notes, suggestions, the direct stream

A profile shows the hashtags an account features as chips opening their feed; under another account's header is what the
persona keeps of it for itself alone: for one it follows, a bell (follow with notify), the languages of its posts that
reach the home feed (follow with languages[]) and Recommend (endorsements, private here), and for any account a private
note saved on blur or with Save. Settings edits the persona's featured hashtags (added by name or from those used lately,
10 at most) and its reading preferences (/clientapi/avatar/private/preferences), which CascadingState keeps per persona
and the card applies to sensitive media and content warnings. A hashtag's tab features it on the profile. Explore has Who
to follow (/api/v2/suggestions, dismissed for good after asking); Administration has Staff picks. The Direct tab follows
the direct stream's conversation events; status notifications show the post. The follows CSV carries notify and languages.

Verified: Release build, 0 errors (the 3 warnings were there before). Not run against PrivaPub or in the pasture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WpVCoDeM1qUTRp4fXQdfof
This commit is contained in:
thepraandClaude Opus 5.5 committed 2026-10-18 08:58:30 +02:00
1 parent 566b0e33ea
commit d33697e3fc
28 files changed
+1784 -52

No files matched your search

+76 -6
View File
@@ -29,9 +29,11 @@ namespace decePubClient.Services
}
/// <summary>
/// Accounts as the current persona sees them: a profile, its relationship to the persona, its posts, following,
/// blocking and muting it, the persona's follow requests, followers and following, and search across the fediverse (a remote handle or URL is
/// resolved by PrivaPub, never by the browser). Lists come back empty and values null on failure; nothing throws.
/// Accounts as the current persona sees them: a profile, its relationship to the persona, its posts and the hashtags it
/// features, following, blocking and muting it, what the persona keeps of it for itself alone (being told of its posts,
/// the languages of them it reads, its recommendation, its private note), the persona's follow requests, followers and
/// following, and search across the fediverse (a remote handle or URL is resolved by PrivaPub, never by the browser).
/// Lists come back empty and values null on failure; nothing throws.
/// </summary>
public class AccountService(IHttpService httpService, ILoggingService logger, CoalescingStringLocalizer localizer)
{
@@ -93,16 +95,84 @@ namespace decePubClient.Services
}
/// <summary>Follows the account, its boosts shown in the home feed or not; Data is the new Relationship.</summary>
public async Task<WebResult> Follow(string accountId, bool showReblogs, CancellationToken cancellationToken = default)
public Task<WebResult> Follow(string accountId, bool showReblogs, CancellationToken cancellationToken = default) =>
FollowWith(accountId, [new("reblogs", Flag(showReblogs))], cancellationToken);
/// <summary>Follows the account with everything a follow carries: its boosts shown or not, the persona told of its new
/// posts or not, and the languages of them that reach the home feed (none, every language), as a Mastodon follows
/// export names them. Data is the new Relationship.</summary>
public Task<WebResult> Follow(string accountId, bool showReblogs, bool notify, IReadOnlyCollection<string> languages,
CancellationToken cancellationToken = default) =>
FollowWith(accountId, [new("reblogs", Flag(showReblogs)), new("notify", Flag(notify)), .. LanguageFields(languages)], cancellationToken);
/// <summary>Tells the persona of each new post of an account it follows (a `status` notification), or stops. The
/// follow's boosts stay as they are: a follow always sets them, so the caller gives the relationship's own. Data is the
/// new Relationship.</summary>
public Task<WebResult> SetNotify(string accountId, bool showReblogs, bool notify, CancellationToken cancellationToken = default) =>
FollowWith(accountId, [new("reblogs", Flag(showReblogs)), new("notify", Flag(notify))], cancellationToken);
/// <summary>Lets only the posts of an account the persona follows written in these languages reach its home feed
/// (a post whose language is unknown still does); none is every language. The follow's boosts stay as they are, as in
/// SetNotify. Data is the new Relationship.</summary>
public Task<WebResult> SetLanguages(string accountId, bool showReblogs, IReadOnlyCollection<string> languages, CancellationToken cancellationToken = default) =>
FollowWith(accountId, [new("reblogs", Flag(showReblogs)), .. LanguageFields(languages)], cancellationToken);
// an empty value says the list is given, and empty: PrivaPub keeps no language, every language
static IEnumerable<KeyValuePair<string, string>> LanguageFields(IReadOnlyCollection<string> languages) => languages.Count == 0
? [new("languages[]", string.Empty)]
: languages.Select(language => new KeyValuePair<string, string>("languages[]", language));
async Task<WebResult> FollowWith(string accountId, List<KeyValuePair<string, string>> fields, CancellationToken cancellationToken)
{
using var response = await httpService.Post(APIs.Mastodon.POST_M_AccountAction(accountId, "follow"),
new[] { new KeyValuePair<string, string>("reblogs", showReblogs ? "true" : "false") }, cancellationToken: cancellationToken);
using var response = await httpService.Post(APIs.Mastodon.POST_M_AccountAction(accountId, "follow"), fields, cancellationToken: cancellationToken);
if (!response.IsSuccessStatusCode)
return await response.Content.ReadWebResult(response.StatusCode, localizer, cancellationToken);
return new WebResult { Data = await response.MastodonReadFromJsonAsync<Relationship>(cancellationToken) };
}
static string Flag(bool value) => value ? "true" : "false";
/// <summary>Keeps an account the persona follows in its recommendations (Mastodon's endorsements), or takes it out. They
/// are the persona's alone: PrivaPub lists them to nobody else and never federates them; it refuses (422) an account the
/// persona doesn't follow. Data is the new Relationship.</summary>
public async Task<WebResult> Endorse(string accountId, bool endorse, CancellationToken cancellationToken = default)
{
using var response = await httpService.Post(APIs.Mastodon.POST_M_AccountAction(accountId, endorse ? "endorse" : "unendorse"),
cancellationToken: cancellationToken);
if (!response.IsSuccessStatusCode)
return await response.Content.ReadWebResult(response.StatusCode, localizer, cancellationToken);
return new WebResult { Data = await response.MastodonReadFromJsonAsync<Relationship>(cancellationToken) };
}
/// <summary>The persona's private note on an account: NoteLength characters at most (PrivaPub refuses more with a 422),
/// empty takes it away. Shown to the persona alone, never federated. Data is the new Relationship.</summary>
public async Task<WebResult> SetNote(string accountId, string comment, CancellationToken cancellationToken = default)
{
using var response = await httpService.Post(APIs.Mastodon.POST_M_AccountNote(accountId),
new[] { new KeyValuePair<string, string>("comment", comment?.Trim() ?? string.Empty) }, cancellationToken: cancellationToken);
if (!response.IsSuccessStatusCode)
return await response.Content.ReadWebResult(response.StatusCode, localizer, cancellationToken);
return new WebResult { Data = await response.MastodonReadFromJsonAsync<Relationship>(cancellationToken) };
}
/// <summary>The longest private note PrivaPub keeps (Mastodon's AccountNote limit).</summary>
public const int NoteLength = 2000;
/// <summary>The hashtags the account features on its profile: a persona's own, or what an account elsewhere's server
/// told of its own; none for a community.</summary>
public async Task<List<FeaturedTag>> FeaturedTags(string accountId, CancellationToken cancellationToken = default)
{
using var response = await httpService.Get(APIs.Mastodon.GET_M_AccountFeaturedTags(accountId), cancellationToken: cancellationToken);
if (response.IsSuccessStatusCode)
return await response.MastodonReadFromJsonAsync<List<FeaturedTag>>(cancellationToken) ?? [];
await LogFailure(response, nameof(FeaturedTags), cancellationToken);
return [];
}
/// <summary>Follows, unfollows, blocks, unblocks, mutes or unmutes; Data is the new Relationship.</summary>
public async Task<WebResult> Act(string accountId, AccountAction action, CancellationToken cancellationToken = default)
{