[backend/masto-client] Fix renotes appearing more than once in note responses (ISH-261)

This commit is contained in:
Laura Hausmann 2024-04-16 02:05:11 +02:00
parent 12ba40d44b
commit a56d7f521c
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -281,26 +281,27 @@ public class NoteRenderer(
List<AccountEntity>? accounts = null
)
{
var noteList = notes.SelectMany<Note, Note?>(p => [p, p.Renote])
var noteList = notes.ToList();
if (noteList.Count == 0) return [];
var allNotes = noteList.SelectMany<Note, Note?>(p => [p, p.Renote])
.Where(p => p != null)
.Cast<Note>()
.DistinctBy(p => p.Id)
.ToList();
if (noteList.Count == 0) return [];
var data = new NoteRendererDto
{
Accounts = accounts ?? await GetAccounts(noteList.Select(p => p.User).ToList()),
Mentions = await GetMentions(noteList),
Attachments = await GetAttachments(noteList),
Polls = await GetPolls(noteList, user),
LikedNotes = await GetLikedNotes(noteList, user),
BookmarkedNotes = await GetBookmarkedNotes(noteList, user),
PinnedNotes = await GetPinnedNotes(noteList, user),
Renotes = await GetRenotes(noteList, user),
Emoji = await GetEmoji(noteList),
Reactions = await GetReactions(noteList, user),
Accounts = accounts ?? await GetAccounts(allNotes.Select(p => p.User).ToList()),
Mentions = await GetMentions(allNotes),
Attachments = await GetAttachments(allNotes),
Polls = await GetPolls(allNotes, user),
LikedNotes = await GetLikedNotes(allNotes, user),
BookmarkedNotes = await GetBookmarkedNotes(allNotes, user),
PinnedNotes = await GetPinnedNotes(allNotes, user),
Renotes = await GetRenotes(allNotes, user),
Emoji = await GetEmoji(allNotes),
Reactions = await GetReactions(allNotes, user),
Filters = await GetFilters(user, filterContext)
};