[backend/federation] Don't require ASNotes by the authenticated actor to be fetchable

This fixes e.g. renotes of follower-only posts
This commit is contained in:
Laura Hausmann 2024-05-02 20:55:26 +02:00
parent fee5296cd9
commit 75b2227524
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 19 additions and 7 deletions

View file

@ -21,7 +21,6 @@ public class ActivityHandlerService(
DatabaseContext db, DatabaseContext db,
IOptions<Config.InstanceSection> config, IOptions<Config.InstanceSection> config,
FederationControlService federationCtrl, FederationControlService federationCtrl,
ObjectResolver resolver,
NotificationService notificationSvc, NotificationService notificationSvc,
ObjectResolver objectResolver, ObjectResolver objectResolver,
FollowupTaskService followupTaskSvc, FollowupTaskService followupTaskSvc,
@ -56,7 +55,7 @@ public class ActivityHandlerService(
// Resolve object & children // Resolve object & children
if (activity.Object != null) if (activity.Object != null)
activity.Object = await resolver.ResolveObject(activity.Object) ?? activity.Object = await objectResolver.ResolveObject(activity.Object, resolvedActor.Uri) ??
throw GracefulException.UnprocessableEntity("Failed to resolve activity object"); throw GracefulException.UnprocessableEntity("Failed to resolve activity object");
//TODO: validate inboxUserId //TODO: validate inboxUserId
@ -203,7 +202,7 @@ public class ActivityHandlerService(
} }
case ASBite bite: case ASBite bite:
{ {
var target = await objectResolver.ResolveObject(bite.Target); var target = await objectResolver.ResolveObject(bite.Target, resolvedActor.Uri);
var dbBite = target switch var dbBite = target switch
{ {
ASActor targetActor => new Bite ASActor targetActor => new Bite

View file

@ -14,18 +14,31 @@ public class ObjectResolver(
IOptions<Config.InstanceSection> config IOptions<Config.InstanceSection> config
) )
{ {
public async Task<ASObject?> ResolveObject(ASObjectBase baseObj, int recurse = 5, bool force = false) public async Task<ASObject?> ResolveObject(
ASObjectBase baseObj, string? actorUri = null, int recurse = 5, bool force = false
)
{ {
logger.LogDebug("Resolving object: {id}", baseObj.Id ?? "<anonymous>"); logger.LogDebug("Resolving object: {id}", baseObj.Id ?? "<anonymous>");
if (baseObj is ASActivity { Object.IsUnresolved: true } activity && recurse > 0) if (baseObj is ASActivity { Object.IsUnresolved: true } activity && recurse > 0)
{ {
activity.Object = await ResolveObject(activity.Object, --recurse, force); activity.Object = await ResolveObject(activity.Object, actorUri, --recurse, force);
return await ResolveObject(activity, recurse); return await ResolveObject(activity, actorUri, recurse);
} }
if (baseObj is ASObject { IsUnresolved: false } obj && !force) if (baseObj is ASObject { IsUnresolved: false } obj && !force)
return obj; {
if (actorUri == null ||
baseObj is not ASNote { AttributedTo.Count: > 0 } note ||
note.AttributedTo.Any(p => p.Id != actorUri))
{
return obj;
}
note.VerifiedFetch = true;
return note;
}
if (baseObj.Id == null) if (baseObj.Id == null)
{ {
logger.LogDebug("Refusing to resolve object with null id property"); logger.LogDebug("Refusing to resolve object with null id property");