diff --git a/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs b/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs index 10000117..8a833468 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/StatusController.cs @@ -97,7 +97,10 @@ public class StatusController( .PrecomputeVisibilities(user) .RenderAllForMastodonAsync(noteRenderer, user, Filter.FilterContext.Threads); - var res = new StatusContext { Ancestors = ancestors, Descendants = descendants.OrderDescendants() }; + var res = new StatusContext + { + Ancestors = ancestors.OrderAncestors(), Descendants = descendants.OrderDescendants() + }; return Ok(res); } diff --git a/Iceshrimp.Backend/Controllers/NoteController.cs b/Iceshrimp.Backend/Controllers/NoteController.cs index 89b1df09..afb75ab5 100644 --- a/Iceshrimp.Backend/Controllers/NoteController.cs +++ b/Iceshrimp.Backend/Controllers/NoteController.cs @@ -68,9 +68,10 @@ public class NoteController( .FilterHidden(user, db) .PrecomputeNoteContextVisibilities(user) .ToListAsync(); + var res = await noteRenderer.RenderMany(notes.EnforceRenoteReplyVisibility(), user, + Filter.FilterContext.Threads); - return Ok(await noteRenderer.RenderMany(notes.EnforceRenoteReplyVisibility(), user, - Filter.FilterContext.Threads)); + return Ok(res.ToList().OrderAncestors()); } [HttpGet("{id}/descendants")] diff --git a/Iceshrimp.Backend/Core/Helpers/NoteThreadHelpers.cs b/Iceshrimp.Backend/Core/Helpers/NoteThreadHelpers.cs index 5d38ee8f..3c333984 100644 --- a/Iceshrimp.Backend/Core/Helpers/NoteThreadHelpers.cs +++ b/Iceshrimp.Backend/Core/Helpers/NoteThreadHelpers.cs @@ -13,6 +13,48 @@ public static class NoteThreadHelpers public TreeNode? Parent; } + public static List OrderAncestors(this List notes) + { + var final = new List(); + foreach (var note in notes) + { + if (note.ReplyId == null) + { + final.Insert(0, note); + continue; + } + + var parent = final.Find(p => p.Id == note.ReplyId); + if (parent != null) + final.Insert(final.IndexOf(parent) + 1, note); + else + final.Add(note); + } + + return final; + } + + public static List OrderAncestors(this List notes) + { + var final = new List(); + foreach (var note in notes) + { + if (note.ReplyId == null) + { + final.Insert(0, note); + continue; + } + + var parent = final.Find(p => p.Id == note.ReplyId); + if (parent != null) + final.Insert(final.IndexOf(parent) + 1, note); + else + final.Add(note); + } + + return final; + } + public static List OrderDescendants(this List notes) { foreach (var note in notes)