Build / Build (push) Successful in 51s
Starts the completion program (SocialPub docs/ROADMAP.md, "Owner decisions on finishing everything", 2026-10-17). - The localizer's namespace is decePubClient.Services; collAnon is gone from the repo. - Dead code: PagesBase, VConstants, SettingsOptions, ViewLanguage, unused APIs routes, InstanceService.Self, RequestStats.LastOf/AverageMs, PostAnon/DeleteTotallyAnon, unused AppStatusService methods and their main.js helpers (the app badge stays for Web Push), ExtensionMethods/SUtility leftovers (Markdig and BlazorZXingJs packages go), unused PublicCacheData/PageSettings/AppConfiguration fields, commented-out code. - The client log in IndexedDB, which nothing ever read, goes with the whole IndexedDB layer (DnetIndexedDb, IStorage): logs go to the browser console; main.js deletes the old "data" database once. - The solution names the real ClientModels project. Unused vendor assets (fontawesome, solid, open-iconic, rxjs) go. - robots.txt disallows everything; manifest.json and index.html say decePub; the service worker's cache name follows each publish's assets version, so old caches are purged. - MessageType is Visibility (member names kept: they are resx keys); ExpandMessage.razor is Thread.razor (same route). - i18n: dead keys removed, Italian "camera" is "punto di vista", DInputBase/DCalendar validation messages come from ErrorMessages, DataTransfer's spinner has its label. - CLAUDE.md follows: client storage, JS interop, PWA, the D fields' messages. Verified: dotnet build decePubClient.csproj and decePubClient.sln -c Release (0 errors, no new warnings); a Pasture publish served by the pasture's decepub peer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WpVCoDeM1qUTRp4fXQdfof
126 lines
5.9 KiB
C#
126 lines
5.9 KiB
C#
using System.Net;
|
|
|
|
using decePubClient.Extensions;
|
|
using decePubClient.Models;
|
|
using decePubClient.Models.Mastodon;
|
|
|
|
using PrivaPub.ClientModels;
|
|
|
|
namespace decePubClient.Services
|
|
{
|
|
/// <summary>
|
|
/// The current persona's lists (Mastodon's /api/v1/lists): made, renamed and deleted, their members (only accounts the
|
|
/// persona follows; PrivaPub drops a member when the follow ends), and the lists an account is in. A list's posts are a
|
|
/// feed of their own (TimelineService, TimelineType.Lists). Lists come back empty on failure; nothing throws.
|
|
/// </summary>
|
|
public class ListService(IHttpService httpService, ILoggingService logger, CoalescingStringLocalizer localizer)
|
|
{
|
|
/// <summary>The most members PrivaPub keeps in one list, and so the most read back.</summary>
|
|
public const int MaxMembers = 500;
|
|
const int MembersPerPage = 80;
|
|
|
|
public async Task<List<MastodonList>> All(CancellationToken cancellationToken = default)
|
|
{
|
|
using var response = await httpService.Get(APIs.Mastodon.GET_Lists, cancellationToken: cancellationToken);
|
|
if (response.IsSuccessStatusCode)
|
|
return await response.MastodonReadFromJsonAsync<List<MastodonList>>(cancellationToken) ?? [];
|
|
|
|
await LogFailure(response, nameof(All), cancellationToken);
|
|
return [];
|
|
}
|
|
|
|
/// <summary>Makes the list when it has no id yet, or saves its title, replies policy and exclusivity; Data is the list.</summary>
|
|
public async Task<WebResult> Save(MastodonList list, CancellationToken cancellationToken = default)
|
|
{
|
|
var form = new MastodonList { Title = list.Title?.Trim(), RepliesPolicy = list.RepliesPolicy, Exclusive = list.Exclusive };
|
|
using var response = list.Id is null
|
|
? await httpService.Post(APIs.Mastodon.POST_List, form, cancellationToken: cancellationToken)
|
|
: await httpService.Put(APIs.Mastodon.PUT_M_List(list.Id), form, cancellationToken: cancellationToken);
|
|
if (!response.IsSuccessStatusCode)
|
|
return await response.Content.ReadWebResult(response.StatusCode, localizer, cancellationToken);
|
|
|
|
return new WebResult { Data = await response.MastodonReadFromJsonAsync<MastodonList>(cancellationToken) };
|
|
}
|
|
|
|
public async Task<WebResult> Delete(string listId, CancellationToken cancellationToken = default)
|
|
{
|
|
using var response = await httpService.Delete(APIs.Mastodon.DELETE_M_List(listId), cancellationToken: cancellationToken);
|
|
if (!response.IsSuccessStatusCode)
|
|
return await response.Content.ReadWebResult(response.StatusCode, localizer, cancellationToken);
|
|
|
|
return new WebResult();
|
|
}
|
|
|
|
/// <summary>Every member of the list, page by page, up to MaxMembers.</summary>
|
|
public async Task<List<Account>> Members(string listId, CancellationToken cancellationToken = default)
|
|
{
|
|
var members = new List<Account>();
|
|
var maxId = default(string);
|
|
while (members.Count < MaxMembers)
|
|
{
|
|
string[] parameters = maxId is null ? [$"limit={MembersPerPage}"] : [$"limit={MembersPerPage}", $"max_id={Uri.EscapeDataString(maxId)}"];
|
|
using var response = await httpService.Get(APIs.Mastodon.M_ListAccounts(listId), parameters, cancellationToken: cancellationToken);
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
await LogFailure(response, nameof(Members), cancellationToken);
|
|
return members;
|
|
}
|
|
|
|
var page = await response.MastodonReadFromJsonAsync<List<Account>>(cancellationToken) ?? [];
|
|
members.AddRange(page);
|
|
maxId = response.PageCursors().MaxId;
|
|
if (page.Count < MembersPerPage || maxId is null)
|
|
return members;
|
|
}
|
|
return members;
|
|
}
|
|
|
|
/// <summary>Adds (or removes) an account the persona follows to (from) the list.</summary>
|
|
public async Task<WebResult> SetMember(string listId, string accountId, bool member, CancellationToken cancellationToken = default)
|
|
{
|
|
using var response = member
|
|
? await httpService.Post(APIs.Mastodon.M_ListAccounts(listId), new ListAccountsForm { AccountIds = [accountId] },
|
|
cancellationToken: cancellationToken)
|
|
: await httpService.Delete(APIs.Mastodon.M_ListAccounts(listId), [$"account_ids[]={Uri.EscapeDataString(accountId)}"],
|
|
cancellationToken: cancellationToken);
|
|
if (!response.IsSuccessStatusCode)
|
|
return await response.Content.ReadWebResult(response.StatusCode, localizer, cancellationToken);
|
|
|
|
return new WebResult();
|
|
}
|
|
|
|
/// <summary>The persona's lists the account is in.</summary>
|
|
public async Task<List<MastodonList>> Of(string accountId, CancellationToken cancellationToken = default)
|
|
{
|
|
using var response = await httpService.Get(APIs.Mastodon.GET_M_AccountLists(accountId), cancellationToken: cancellationToken);
|
|
if (response.IsSuccessStatusCode)
|
|
return await response.MastodonReadFromJsonAsync<List<MastodonList>>(cancellationToken) ?? [];
|
|
|
|
await LogFailure(response, nameof(Of), cancellationToken);
|
|
return [];
|
|
}
|
|
|
|
/// <summary>Accounts the persona follows whose name, display name or server starts with the query (PrivaPub's
|
|
/// following=true; nothing is resolved).</summary>
|
|
public async Task<List<Account>> FindFollowed(string query, CancellationToken cancellationToken = default)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(query))
|
|
return [];
|
|
using var response = await httpService.Get(APIs.Mastodon.GET_AccountSearch,
|
|
[$"q={Uri.EscapeDataString(query.Trim())}", "following=true", "resolve=false", "limit=20"], cancellationToken: cancellationToken);
|
|
if (response.IsSuccessStatusCode)
|
|
return await response.MastodonReadFromJsonAsync<List<Account>>(cancellationToken) ?? [];
|
|
|
|
await LogFailure(response, nameof(FindFollowed), cancellationToken);
|
|
return [];
|
|
}
|
|
|
|
async Task LogFailure(HttpResponseMessage response, string caller, CancellationToken cancellationToken)
|
|
{
|
|
var result = await response.Content.ReadWebResult(response.StatusCode, localizer, cancellationToken);
|
|
if (result.StatusCode is not ((int)HttpStatusCode.Gone or (int)HttpStatusCode.NotFound))
|
|
await logger.ProcessWarning(result.ToString(localizer), $"{nameof(ListService)}.{caller}", cancellationToken);
|
|
}
|
|
}
|
|
}
|