[backend/federation] Render Create in /notes/{id}/activity when not a renote

This commit is contained in:
Kopper 2024-11-06 15:46:30 +03:00 committed by Laura Hausmann
parent 3e8ba289c3
commit d22a21c7e7
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 13 additions and 12 deletions

View file

@ -52,27 +52,28 @@ public class ActivityPubController(
[HttpGet("/notes/{id}/activity")]
[AuthorizedFetch]
[OverrideResultType<ASAnnounce>]
[OverrideResultType<ASActivity>]
[ProducesResults(HttpStatusCode.OK)]
[ProducesErrors(HttpStatusCode.NotFound)]
public async Task<JObject> GetRenote(string id)
public async Task<JObject> GetNoteActivity(string id)
{
var actor = HttpContext.GetActor();
var note = await db.Notes
.IncludeCommonProperties()
.EnsureVisibleFor(actor)
.Where(p => p.Id == id && p.UserHost == null && p.IsPureRenote && p.Renote != null)
.Where(p => p.Id == id && p.UserHost == null)
.FirstOrDefaultAsync() ??
throw GracefulException.NotFound("Note not found");
return ActivityPub.ActivityRenderer
.RenderAnnounce(noteRenderer.RenderLite(note.Renote!),
note.GetPublicUri(config.Value),
userRenderer.RenderLite(note.User),
note.Visibility,
note.User.GetPublicUri(config.Value) + "/followers")
.Compact();
var noteActor = userRenderer.RenderLite(note.User);
ASActivity activity = note is { IsPureRenote: true, Renote: not null }
? ActivityPub.ActivityRenderer.RenderAnnounce(noteRenderer.RenderLite(note.Renote),
note.GetPublicUri(config.Value), noteActor, note.Visibility,
note.User.GetPublicUri(config.Value) + "/followers")
: ActivityPub.ActivityRenderer.RenderCreate(await noteRenderer.RenderAsync(note), noteActor);
return activity.Compact();
}
[HttpGet("/notes/{id}/replies")]

View file

@ -19,7 +19,7 @@ public class ActivityRenderer(
public static ASCreate RenderCreate(ASNote obj, ASObject actor) => new()
{
Id = $"{obj.Id}#Create",
Id = $"{obj.Id}/activity",
Actor = ASActor.FromObject(actor),
Object = obj,
To = obj.To,