[backend/api] Render note bookmarked
This commit is contained in:
parent
a6e967af11
commit
51b40ec029
2 changed files with 22 additions and 7 deletions
|
@ -76,6 +76,8 @@ public class NoteRenderer(
|
|||
var attachments =
|
||||
(data?.Attachments ?? await GetAttachmentsAsync([note])).Where(p => note.FileIds.Contains(p.Id));
|
||||
var reactions = (data?.Reactions ?? await GetReactionsAsync([note], user)).Where(p => p.NoteId == note.Id);
|
||||
var bookmarked = data?.BookmarkedNotes?.Contains(note.Id)
|
||||
?? await db.NoteBookmarks.AnyAsync(p => p.Note == note && p.User == user);
|
||||
var liked = data?.LikedNotes?.Contains(note.Id) ??
|
||||
await db.NoteLikes.AnyAsync(p => p.Note == note && p.User == user);
|
||||
var emoji = data?.Emoji?.Where(p => note.Emojis.Contains(p.Id)).ToList() ?? await GetEmojiAsync([note]);
|
||||
|
@ -96,6 +98,7 @@ public class NoteRenderer(
|
|||
Likes = note.LikeCount,
|
||||
Renotes = note.RenoteCount,
|
||||
Replies = note.RepliesCount,
|
||||
Bookmarked = bookmarked,
|
||||
Liked = liked,
|
||||
Emoji = emoji,
|
||||
Poll = poll
|
||||
|
@ -159,6 +162,15 @@ public class NoteRenderer(
|
|||
return res;
|
||||
}
|
||||
|
||||
private async Task<List<string>> GetBookmarkedNotesAsync(List<Note> notes, User? user)
|
||||
{
|
||||
if (user == null) return [];
|
||||
if (notes.Count == 0) return [];
|
||||
return await db.NoteBookmarks.Where(p => p.User == user && notes.Contains(p.Note))
|
||||
.Select(p => p.NoteId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
private async Task<List<string>> GetLikedNotesAsync(List<Note> notes, User? user)
|
||||
{
|
||||
if (user == null) return [];
|
||||
|
@ -244,13 +256,14 @@ public class NoteRenderer(
|
|||
var allNotes = GetAllNotes(notesList);
|
||||
var data = new NoteRendererDto
|
||||
{
|
||||
Users = await GetUsersAsync(allNotes),
|
||||
Attachments = await GetAttachmentsAsync(allNotes),
|
||||
Reactions = await GetReactionsAsync(allNotes, user),
|
||||
Filters = await GetFiltersAsync(user, filterContext),
|
||||
LikedNotes = await GetLikedNotesAsync(allNotes, user),
|
||||
Emoji = await GetEmojiAsync(allNotes),
|
||||
Polls = await GetPollsAsync(allNotes, user)
|
||||
Users = await GetUsersAsync(allNotes),
|
||||
Attachments = await GetAttachmentsAsync(allNotes),
|
||||
Reactions = await GetReactionsAsync(allNotes, user),
|
||||
Filters = await GetFiltersAsync(user, filterContext),
|
||||
BookmarkedNotes = await GetBookmarkedNotesAsync(allNotes, user),
|
||||
LikedNotes = await GetLikedNotesAsync(allNotes, user),
|
||||
Emoji = await GetEmojiAsync(allNotes),
|
||||
Polls = await GetPollsAsync(allNotes, user)
|
||||
};
|
||||
|
||||
return await notesList.Select(p => RenderOne(p, user, filterContext, data)).AwaitAllAsync();
|
||||
|
@ -261,6 +274,7 @@ public class NoteRenderer(
|
|||
public List<NoteAttachment>? Attachments;
|
||||
public List<EmojiResponse>? Emoji;
|
||||
public List<Filter>? Filters;
|
||||
public List<string>? BookmarkedNotes;
|
||||
public List<string>? LikedNotes;
|
||||
public List<NoteReactionSchema>? Reactions;
|
||||
public List<UserResponse>? Users;
|
||||
|
|
|
@ -38,6 +38,7 @@ public class NoteBase
|
|||
public required string? Cw { get; set; }
|
||||
public required List<EmojiResponse> Emoji { get; set; }
|
||||
public required NoteVisibility Visibility { get; set; }
|
||||
public required bool Bookmarked { get; set; }
|
||||
public required bool Liked { get; set; }
|
||||
public required int Likes { get; set; }
|
||||
public required int Renotes { get; set; }
|
||||
|
|
Loading…
Add table
Reference in a new issue