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:
1 parent
566b0e33ea
commit
d33697e3fc
28 files changed
+1784
-52
No files matched your search
@@ -18,9 +18,11 @@ namespace decePubClient.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What there is to find on PrivaPub: hashtags (their week, following them), what is trending there (hashtags, posts
|
||||
/// and links, from public posts it already holds) and the directory of accounts that let themselves be discovered.
|
||||
/// Lists come back empty and values null on failure; nothing throws.
|
||||
/// What there is to find on PrivaPub: hashtags (their week, following them, featuring them on the persona's profile),
|
||||
/// what is trending there (hashtags, posts and links, from public posts it already holds), the directory of accounts that
|
||||
/// let themselves be discovered, and who to follow (PrivaPub's suggestions: the staff's picks, past interactions, popular
|
||||
/// accounts here; never the persona itself nor a sibling persona of its login). Lists come back empty and values null on
|
||||
/// failure; nothing throws.
|
||||
/// </summary>
|
||||
public class DiscoveryService(IHttpService httpService, ILoggingService logger, CoalescingStringLocalizer localizer)
|
||||
{
|
||||
@@ -44,6 +46,77 @@ namespace decePubClient.Services
|
||||
return new WebResult { Data = await response.MastodonReadFromJsonAsync<Tag>(cancellationToken) };
|
||||
}
|
||||
|
||||
/// <summary>Features a hashtag on the persona's profile, or stops (Mastodon 4.4's tags/:name/feature); its followers are
|
||||
/// told, as featured tags are public. PrivaPub refuses (422) one past its limit. Data is the Tag, its Featuring set.</summary>
|
||||
public async Task<WebResult> FeatureTag(string name, bool feature, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var response = await httpService.Post(APIs.Mastodon.POST_M_TagAction(name, feature ? "feature" : "unfeature"), cancellationToken: cancellationToken);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadWebResult(response.StatusCode, localizer, cancellationToken);
|
||||
|
||||
return new WebResult { Data = await response.MastodonReadFromJsonAsync<Tag>(cancellationToken) };
|
||||
}
|
||||
|
||||
/// <summary>The hashtags the persona features on its profile, with how often it used them.</summary>
|
||||
public async Task<List<FeaturedTag>> FeaturedTags(CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var response = await httpService.Get(APIs.Mastodon.GET_FeaturedTags, cancellationToken: cancellationToken);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.MastodonReadFromJsonAsync<List<FeaturedTag>>(cancellationToken) ?? [];
|
||||
|
||||
await LogFailure(response, nameof(FeaturedTags), cancellationToken);
|
||||
return [];
|
||||
}
|
||||
|
||||
/// <summary>Features a hashtag by its name (a # before it is fine); one featured already is answered as it is. PrivaPub
|
||||
/// refuses (422) a name that is no hashtag and one past its limit. Data is the FeaturedTag.</summary>
|
||||
public async Task<WebResult> AddFeaturedTag(string name, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var response = await httpService.Post(APIs.Mastodon.POST_FeaturedTag,
|
||||
new[] { new KeyValuePair<string, string>("name", name?.Trim().TrimStart('#')) }, cancellationToken: cancellationToken);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadWebResult(response.StatusCode, localizer, cancellationToken);
|
||||
|
||||
return new WebResult { Data = await response.MastodonReadFromJsonAsync<FeaturedTag>(cancellationToken) };
|
||||
}
|
||||
|
||||
/// <summary>Stops featuring a hashtag, by the featured tag's id; its followers are told.</summary>
|
||||
public async Task<WebResult> RemoveFeaturedTag(string featuredTagId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var response = await httpService.Delete(APIs.Mastodon.DELETE_M_FeaturedTag(featuredTagId), cancellationToken: cancellationToken);
|
||||
return response.IsSuccessStatusCode ? new WebResult() : await response.Content.ReadWebResult(response.StatusCode, localizer, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>Hashtags the persona used lately and does not feature, the most used first.</summary>
|
||||
public async Task<List<Tag>> FeaturedTagSuggestions(CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var response = await httpService.Get(APIs.Mastodon.GET_FeaturedTagSuggestions, cancellationToken: cancellationToken);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.MastodonReadFromJsonAsync<List<Tag>>(cancellationToken) ?? [];
|
||||
|
||||
await LogFailure(response, nameof(FeaturedTagSuggestions), cancellationToken);
|
||||
return [];
|
||||
}
|
||||
|
||||
/// <summary>Accounts to follow, best first, each with why (/api/v2/suggestions).</summary>
|
||||
public async Task<List<Suggestion>> Suggestions(CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var response = await httpService.Get(APIs.Mastodon.GET_Suggestions, ["limit=40"], cancellationToken: cancellationToken);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.MastodonReadFromJsonAsync<List<Suggestion>>(cancellationToken) ?? [];
|
||||
|
||||
await LogFailure(response, nameof(Suggestions), cancellationToken);
|
||||
return [];
|
||||
}
|
||||
|
||||
/// <summary>Never suggests the account to this persona again; there is no undoing it, but the account can still be
|
||||
/// followed from its profile.</summary>
|
||||
public async Task<WebResult> DismissSuggestion(string accountId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var response = await httpService.Delete(APIs.Mastodon.DELETE_M_Suggestion(accountId), cancellationToken: cancellationToken);
|
||||
return response.IsSuccessStatusCode ? new WebResult() : await response.Content.ReadWebResult(response.StatusCode, localizer, cancellationToken);
|
||||
}
|
||||
|
||||
public Task<List<Tag>> FollowedTags(CancellationToken cancellationToken = default) =>
|
||||
List<Tag>(APIs.Mastodon.GET_FollowedTags, ["limit=200"], nameof(FollowedTags), cancellationToken);
|
||||
|
||||
|
||||
Reference in new issue
Block a user