M6: provenance fixes, stored features, community edits that are real edits
- A fetched ObjectRecord no longer wears the signature, key, signed headers and @context of the activity that caused the fetch, and its ReceivedAt is the fetch's own time. Its activity fields now name the trigger. Provenance answers signature null and fetchedBy "instance-actor". Migration _008 clears the old fetched records. - ObjectRecords store their ObjectFeatures extensions and context namespaces (migration _009 fills older records in batches), so statistics can count them. Provenance reads the stored lists. - ForeignAvatar.Features records what an actor document uses (ActorFeatures): featured, shared inbox, FEP-521a, FEP-8b32, identity proofs, Misskey fields, indexable, undiscoverable, locked, key size, and more. - RemoteEdits.Apply and RemoteDeletes.Remove are shared by the Update, Delete and Announce handlers. A community-wrapped Update is now an edit only when newer, refreshes polls and media otherwise, revises the ObjectRecord and re-resolves quotes. A community-wrapped Delete now tombstones the object, removes its ObjectRecord, reblogs and timeline rows, and lowers the reply count. Any deleted quoting post lowers the quoted post's quote count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ELjqpznMFMNrJoJUj6K5p2
This commit is contained in:
1 parent
d37999970c
commit
90a7e38ce9
19 files changed
+505
-109
No files matched your search
@@ -37,6 +37,7 @@ namespace PrivaPub.Federation.Actors
|
||||
public List<CustomEmoji> Emojis { get; init; } = new();
|
||||
public Dictionary<string, string> Fields { get; init; } = new();
|
||||
public IReadOnlyList<ActorKey> Keys { get; init; } = Array.Empty<ActorKey>();
|
||||
public List<string> Features { get; init; } = new();
|
||||
|
||||
public ActorKey Key(string keyId) => Keys.FirstOrDefault(k => k.Id == keyId);
|
||||
|
||||
@@ -54,6 +55,7 @@ namespace PrivaPub.Federation.Actors
|
||||
{
|
||||
Id = id,
|
||||
Type = type,
|
||||
Features = ActorFeatures.Detect(root),
|
||||
PreferredUsername = RemoteActorService.Text(root, "preferredUsername"),
|
||||
Name = RemoteActorService.Text(root, "name"),
|
||||
Summary = RemoteActorService.Text(root, "summary"),
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace PrivaPub.Federation.Actors
|
||||
{
|
||||
public static class ActorFeatures
|
||||
{
|
||||
public static List<string> Detect(JsonElement root)
|
||||
{
|
||||
var found = new List<string>();
|
||||
if (root.ValueKind != JsonValueKind.Object)
|
||||
return found;
|
||||
void When(bool condition, string feature)
|
||||
{
|
||||
if (condition)
|
||||
found.Add(feature);
|
||||
}
|
||||
bool Has(string name) => root.TryGetProperty(name, out var value) && value.ValueKind is not (JsonValueKind.Null or JsonValueKind.Undefined);
|
||||
bool True(string name) => root.TryGetProperty(name, out var value) && value.ValueKind == JsonValueKind.True;
|
||||
IEnumerable<JsonElement> Items(string name) => !root.TryGetProperty(name, out var value)
|
||||
? Enumerable.Empty<JsonElement>()
|
||||
: value.ValueKind == JsonValueKind.Array ? value.EnumerateArray() : new[] { value };
|
||||
bool Typed(JsonElement item, string type) =>
|
||||
item.ValueKind == JsonValueKind.Object && item.TryGetProperty("type", out var t) && t.ValueKind == JsonValueKind.String && t.GetString() == type;
|
||||
|
||||
When(Has("featured"), "featured");
|
||||
When(Has("featuredTags"), "featured-tags");
|
||||
When(Items("alsoKnownAs").Any(), "also-known-as");
|
||||
When(Has("movedTo"), "moved-to");
|
||||
When(root.TryGetProperty("endpoints", out var endpoints) && endpoints.ValueKind == JsonValueKind.Object && endpoints.TryGetProperty("sharedInbox", out _), "shared-inbox");
|
||||
When(Has("assertionMethod"), "fep-521a-assertion-method");
|
||||
When(Has("proof"), "fep-8b32-proof");
|
||||
When(Items("attachment").Any(a => Typed(a, "PropertyValue")), "property-value");
|
||||
When(Items("attachment").Any(a => Typed(a, "VerifiableIdentityStatement") || Typed(a, "IdentityProof")), "fep-c390-identity-proof");
|
||||
When(Items("tag").Any(t => Typed(t, "Emoji")), "custom-emoji");
|
||||
When(root.EnumerateObject().Any(p => p.Name.StartsWith("_misskey", StringComparison.Ordinal)), "misskey");
|
||||
When(True("isCat"), "is-cat");
|
||||
When(Has("webfinger"), "fep-2c59-webfinger");
|
||||
When(Has("attributionDomains"), "attribution-domains");
|
||||
When(Has("searchableBy"), "fep-268d-searchable-by");
|
||||
When(True("indexable"), "indexable");
|
||||
When(root.TryGetProperty("discoverable", out var discoverable) && discoverable.ValueKind == JsonValueKind.False, "undiscoverable");
|
||||
When(True("manuallyApprovesFollowers"), "locked");
|
||||
When(True("memorial"), "memorial");
|
||||
When(Has("generator"), "generator");
|
||||
When(root.TryGetProperty("publicKey", out var keys) && keys.ValueKind == JsonValueKind.Array, "public-key-array");
|
||||
if (KeyBits(root) is { } bits)
|
||||
found.Add($"key:rsa-{bits}");
|
||||
return found;
|
||||
}
|
||||
|
||||
static int? KeyBits(JsonElement root)
|
||||
{
|
||||
if (!root.TryGetProperty("publicKey", out var key))
|
||||
return default;
|
||||
if (key.ValueKind == JsonValueKind.Array)
|
||||
key = key.EnumerateArray().FirstOrDefault(k => k.ValueKind == JsonValueKind.Object);
|
||||
if (key.ValueKind != JsonValueKind.Object || !key.TryGetProperty("publicKeyPem", out var pem) || pem.ValueKind != JsonValueKind.String)
|
||||
return default;
|
||||
try
|
||||
{
|
||||
using var rsa = RSA.Create();
|
||||
rsa.ImportFromPem(pem.GetString());
|
||||
return rsa.KeySize;
|
||||
}
|
||||
catch (Exception ex) when (ex is ArgumentException or CryptographicException)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,6 +192,7 @@ namespace PrivaPub.Federation.Actors
|
||||
.Modify(a => a.Published, actor.Published)
|
||||
.Modify(a => a.Emojis, actor.Emojis)
|
||||
.Modify(a => a.Fields, actor.Fields)
|
||||
.Modify(a => a.Features, actor.Features)
|
||||
.Modify(a => a.AvatarType, Enum.TryParse<AvatarType>(actor.Type, out var type) ? type : AvatarType.Person)
|
||||
.Modify(a => a.PublicKeyId, key?.Id)
|
||||
.Modify(a => a.PublicKey, key?.Pem)
|
||||
|
||||
Reference in new issue
Block a user