[backend/federation] Expose replies collection
Exposes the replies collection for local notes, allowing remote instances to backfill replies when fetching our posts.
This commit is contained in:
parent
32c4eaf18a
commit
2523f8a4d1
3 changed files with 37 additions and 2 deletions
|
@ -74,6 +74,34 @@ public class ActivityPubController(
|
|||
.Compact();
|
||||
}
|
||||
|
||||
[HttpGet("/notes/{id}/replies")]
|
||||
[AuthorizedFetch]
|
||||
[OverrideResultType<ASOrderedCollection>]
|
||||
[ProducesResults(HttpStatusCode.OK)]
|
||||
[ProducesErrors(HttpStatusCode.NotFound)]
|
||||
public async Task<JObject> GetNoteReplies(string id)
|
||||
{
|
||||
var actor = HttpContext.GetActor();
|
||||
var note = await db.Notes
|
||||
.EnsureVisibleFor(actor)
|
||||
.FirstOrDefaultAsync(p => p.Id == id) ??
|
||||
throw GracefulException.NotFound("Note not found");
|
||||
|
||||
var replies = await db.Notes.Where(p => p.ReplyId == id)
|
||||
.OrderByDescending(p => p.Id)
|
||||
.ToListAsync();
|
||||
|
||||
var rendered = replies.Select(noteRenderer.RenderLite).ToList();
|
||||
var res = new ASOrderedCollection
|
||||
{
|
||||
Id = $"{note.GetPublicUri(config.Value)}/replies",
|
||||
TotalItems = (ulong)rendered.Count,
|
||||
Items = rendered.Cast<ASObject>().ToList()
|
||||
};
|
||||
|
||||
return res.Compact();
|
||||
}
|
||||
|
||||
[HttpGet("/users/{id}")]
|
||||
[AuthorizedFetch]
|
||||
[MediaTypeRouteFilter("application/activity+json", "application/ld+json")]
|
||||
|
|
|
@ -27,8 +27,9 @@ public class NoteRenderer(IOptions<Config.InstanceSection> config, MfmConverter
|
|||
if (note.IsPureRenote)
|
||||
throw GracefulException.BadRequest("Refusing to render pure renote as ASNote");
|
||||
|
||||
var id = note.GetPublicUri(config.Value);
|
||||
var userId = note.User.GetPublicUri(config.Value);
|
||||
var id = note.GetPublicUri(config.Value);
|
||||
var userId = note.User.GetPublicUri(config.Value);
|
||||
var replies = new ASOrderedCollection($"{id}/replies");
|
||||
var replyId = note.Reply != null
|
||||
? new ASObjectBase(note.Reply.Uri ?? note.Reply.GetPublicUri(config.Value))
|
||||
: null;
|
||||
|
@ -160,6 +161,7 @@ public class NoteRenderer(IOptions<Config.InstanceSection> config, MfmConverter
|
|||
UpdatedAt = note.UpdatedAt,
|
||||
Sensitive = sensitive,
|
||||
InReplyTo = replyId,
|
||||
Replies = replies,
|
||||
Cc = cc,
|
||||
To = to,
|
||||
Tags = tags,
|
||||
|
@ -190,6 +192,7 @@ public class NoteRenderer(IOptions<Config.InstanceSection> config, MfmConverter
|
|||
UpdatedAt = note.UpdatedAt,
|
||||
Sensitive = sensitive,
|
||||
InReplyTo = replyId,
|
||||
Replies = replies,
|
||||
Cc = cc,
|
||||
To = to,
|
||||
Tags = tags,
|
||||
|
|
|
@ -87,6 +87,10 @@ public class ASNote : ASObject
|
|||
[JC(typeof(ASAttachmentConverter))]
|
||||
public List<ASAttachment>? Attachments { get; set; }
|
||||
|
||||
[J($"{Constants.ActivityStreamsNs}#replies")]
|
||||
[JC(typeof(ASOrderedCollectionConverter))]
|
||||
public ASOrderedCollection? Replies { get; set; }
|
||||
|
||||
public Note.NoteVisibility GetVisibility(User actor)
|
||||
{
|
||||
if (actor.IsLocalUser) throw new Exception("Can't get recipients for local actor");
|
||||
|
|
Loading…
Add table
Reference in a new issue