[backend/federation] Use separate renoteUri schema

This allows renoteUris to be fetchable at their canonical uri.
This commit is contained in:
Laura Hausmann 2024-04-24 04:05:40 +02:00
parent 385f5843f7
commit bd8d5b20f8
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 28 additions and 3 deletions

View file

@ -42,7 +42,32 @@ public class ActivityPubController(
.FirstOrDefaultAsync(p => p.Id == id && p.UserHost == null);
if (note == null) return NotFound();
var rendered = await noteRenderer.RenderAsync(note);
var compacted = LdHelpers.Compact(rendered);
var compacted = rendered.Compact();
return Ok(compacted);
}
[HttpGet("/notes/{id}/activity")]
[AuthorizedFetch]
[MediaTypeRouteFilter("application/activity+json", "application/ld+json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ASNote))]
[ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(ErrorResponse))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ErrorResponse))]
public async Task<IActionResult> GetRenote(string id)
{
var actor = HttpContext.GetActor();
var note = await db.Notes
.IncludeCommonProperties()
.EnsureVisibleFor(actor)
.FirstOrDefaultAsync(p => p.Id == id && p.UserHost == null);
if (note is not { IsPureRenote: true, Renote: not null }) return NotFound();
var rendered = ActivityPub.ActivityRenderer.RenderAnnounce(noteRenderer.RenderLite(note.Renote),
note.GetPublicUri(config.Value),
userRenderer.RenderLite(note.User),
note.Visibility,
note.User.GetPublicUri(config.Value) + "/followers");
var compacted = rendered.Compact();
return Ok(compacted);
}
@ -88,7 +113,7 @@ public class ActivityPubController(
Items = rendered.Cast<ASObject>().ToList()
};
var compacted = LdHelpers.Compact(res);
var compacted = res.Compact();
return Ok(compacted);
}

View file

@ -209,7 +209,7 @@ public class ActivityRenderer(
_ => []
};
return RenderAnnounce(note, actor, to, cc, renoteUri);
return RenderAnnounce(note, actor, to, cc, $"{renoteUri}/activity");
}
public ASNote RenderVote(PollVote vote, Poll poll, Note note) => new()