Skip to content

Commit

Permalink
Fix LoadPosters remove from conversation comment list
Browse files Browse the repository at this point in the history
  • Loading branch information
RedCocoon committed Nov 3, 2024
1 parent 2ba22a8 commit 56fca5e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions models/conversations/comment_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ import (
// CommentList defines a list of comments
type CommentList []*ConversationComment

// LoadPosters loads posters
func (comments CommentList) LoadPosters(ctx context.Context) error {
if len(comments) == 0 {
return nil
}

posterIDs := container.FilterSlice(comments, func(c *ConversationComment) (int64, bool) {
return c.PosterID, c.Poster == nil && c.PosterID > 0
})

posterMaps, err := getPostersByIDs(ctx, posterIDs)
if err != nil {
return err
}

for _, comment := range comments {
if comment.Poster == nil {
comment.Poster = getPoster(comment.PosterID, posterMaps)
}
}
return nil
}

// getConversationIDs returns all the conversation ids on this comment list which conversation hasn't been loaded
func (comments CommentList) getConversationIDs() []int64 {
return container.FilterSlice(comments, func(comment *ConversationComment) (int64, bool) {
Expand Down Expand Up @@ -158,6 +181,10 @@ func (comments CommentList) LoadAttachments(ctx context.Context) (err error) {
// LoadAttributes loads attributes of the comments, except for attachments and
// comments
func (comments CommentList) LoadAttributes(ctx context.Context) (err error) {
if err = comments.LoadPosters(ctx); err != nil {
return err
}

if err = comments.LoadAttachments(ctx); err != nil {
return err
}
Expand Down

0 comments on commit 56fca5e

Please sign in to comment.