The Mastodon client API: accounts, statuses, timelines, notifications, search
With a token for a persona, a Mastodon client can now:
- accounts: verify/update credentials (display name, note, fields, locked,
bot, discoverable, indexable, hide collections, posting defaults; the
change federates as Update{Person}), get, lookup, statuses (paged, by
visibility to the viewer), relationships, search, follow and unfollow,
follow requests (authorize and reject answer remote followers with
Accept or Reject), remove from followers. Followers and following lists
are shown to their owner only.
- statuses: post (plain text, mentions, hashtags, replies, content
warnings, the four visibilities, Idempotency-Key), get, edit (PUT),
delete returning the source for redrafting, context, history, source,
favourite, reblog and their undos, favourited_by and reblogged_by.
- timelines: home, public (local or remote), tag; favourites;
conversations; markers.
- notifications: list with types and exclude_types, get, dismiss, clear,
unread count.
- /api/v2/search, resolving a handle or a URL to an account or a post.
Media, polls, pins, bookmarks, mutes, blocks, lists, filters, trends and
push answer empty lists or a 422 saying they are not supported yet, so
clients degrade instead of failing. Public reads work without a token.
Persona settings (locked, bot, indexable, discoverable) now also shape
the ActivityPub actor.
Fixed on the way: three conditional expressions whose `default` was the
value type's, so a missing limit became 1, a missing flag became false and
an attachment without dimensions became 0x0.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012CzABvBkbcFqoHdmi8b9WB
This commit is contained in:
1 parent
b54cdf78b2
commit
0028e96e76
17 files changed
+1290
-73
No files matched your search
@@ -59,10 +59,10 @@ namespace PrivaPub.Api.Mastodon.Infrastructure
|
||||
{
|
||||
"true" or "1" or "on" or "yes" => true,
|
||||
"false" or "0" or "off" or "no" or "" => false,
|
||||
_ => default
|
||||
_ => (bool?)null
|
||||
};
|
||||
|
||||
public int? Int(string name) => int.TryParse(Get(name), out var value) ? value : default;
|
||||
public int? Int(string name) => int.TryParse(Get(name), out var value) ? value : (int?)null;
|
||||
|
||||
static void Add(Dictionary<string, List<string>> values, string key, string value)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Entities;
|
||||
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace PrivaPub.Api.Mastodon.Infrastructure
|
||||
{
|
||||
public sealed record Page(string MaxId, string SinceId, string MinId, int Limit)
|
||||
{
|
||||
public static Page From(MastodonParams parameters, int limit) =>
|
||||
new(parameters.Get("max_id"), parameters.Get("since_id"), parameters.Get("min_id"), limit);
|
||||
|
||||
public async Task<List<T>> Fetch<T>(Find<T, T> query, Expression<Func<T, string>> id, CancellationToken token) where T : IEntity
|
||||
{
|
||||
var field = new ExpressionFieldDefinition<T, string>(id);
|
||||
if (!string.IsNullOrEmpty(MaxId))
|
||||
query.Match(Builders<T>.Filter.Lt(field, MaxId));
|
||||
if (!string.IsNullOrEmpty(SinceId))
|
||||
query.Match(Builders<T>.Filter.Gt(field, SinceId));
|
||||
if (!string.IsNullOrEmpty(MinId))
|
||||
query.Match(Builders<T>.Filter.Gt(field, MinId));
|
||||
var ascending = !string.IsNullOrEmpty(MinId);
|
||||
var sortField = new ExpressionFieldDefinition<T>(Expression.Lambda<Func<T, object>>(Expression.Convert(id.Body, typeof(object)), id.Parameters));
|
||||
var items = await query.Sort(s => ascending ? s.Ascending(sortField) : s.Descending(sortField)).Limit(Limit).ExecuteAsync(token);
|
||||
if (ascending)
|
||||
items.Reverse();
|
||||
return items;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user