[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();
|
.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}")]
|
[HttpGet("/users/{id}")]
|
||||||
[AuthorizedFetch]
|
[AuthorizedFetch]
|
||||||
[MediaTypeRouteFilter("application/activity+json", "application/ld+json")]
|
[MediaTypeRouteFilter("application/activity+json", "application/ld+json")]
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class NoteRenderer(IOptions<Config.InstanceSection> config, MfmConverter
|
||||||
|
|
||||||
var id = note.GetPublicUri(config.Value);
|
var id = note.GetPublicUri(config.Value);
|
||||||
var userId = note.User.GetPublicUri(config.Value);
|
var userId = note.User.GetPublicUri(config.Value);
|
||||||
|
var replies = new ASOrderedCollection($"{id}/replies");
|
||||||
var replyId = note.Reply != null
|
var replyId = note.Reply != null
|
||||||
? new ASObjectBase(note.Reply.Uri ?? note.Reply.GetPublicUri(config.Value))
|
? new ASObjectBase(note.Reply.Uri ?? note.Reply.GetPublicUri(config.Value))
|
||||||
: null;
|
: null;
|
||||||
|
@ -160,6 +161,7 @@ public class NoteRenderer(IOptions<Config.InstanceSection> config, MfmConverter
|
||||||
UpdatedAt = note.UpdatedAt,
|
UpdatedAt = note.UpdatedAt,
|
||||||
Sensitive = sensitive,
|
Sensitive = sensitive,
|
||||||
InReplyTo = replyId,
|
InReplyTo = replyId,
|
||||||
|
Replies = replies,
|
||||||
Cc = cc,
|
Cc = cc,
|
||||||
To = to,
|
To = to,
|
||||||
Tags = tags,
|
Tags = tags,
|
||||||
|
@ -190,6 +192,7 @@ public class NoteRenderer(IOptions<Config.InstanceSection> config, MfmConverter
|
||||||
UpdatedAt = note.UpdatedAt,
|
UpdatedAt = note.UpdatedAt,
|
||||||
Sensitive = sensitive,
|
Sensitive = sensitive,
|
||||||
InReplyTo = replyId,
|
InReplyTo = replyId,
|
||||||
|
Replies = replies,
|
||||||
Cc = cc,
|
Cc = cc,
|
||||||
To = to,
|
To = to,
|
||||||
Tags = tags,
|
Tags = tags,
|
||||||
|
|
|
@ -87,6 +87,10 @@ public class ASNote : ASObject
|
||||||
[JC(typeof(ASAttachmentConverter))]
|
[JC(typeof(ASAttachmentConverter))]
|
||||||
public List<ASAttachment>? Attachments { get; set; }
|
public List<ASAttachment>? Attachments { get; set; }
|
||||||
|
|
||||||
|
[J($"{Constants.ActivityStreamsNs}#replies")]
|
||||||
|
[JC(typeof(ASOrderedCollectionConverter))]
|
||||||
|
public ASOrderedCollection? Replies { get; set; }
|
||||||
|
|
||||||
public Note.NoteVisibility GetVisibility(User actor)
|
public Note.NoteVisibility GetVisibility(User actor)
|
||||||
{
|
{
|
||||||
if (actor.IsLocalUser) throw new Exception("Can't get recipients for local actor");
|
if (actor.IsLocalUser) throw new Exception("Can't get recipients for local actor");
|
||||||
|
|
Loading…
Add table
Reference in a new issue