Skip to content

Commit 56fca5e

Browse files
committed
Fix LoadPosters remove from conversation comment list
1 parent 2ba22a8 commit 56fca5e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

models/conversations/comment_list.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@ import (
1414
// CommentList defines a list of comments
1515
type CommentList []*ConversationComment
1616

17+
// LoadPosters loads posters
18+
func (comments CommentList) LoadPosters(ctx context.Context) error {
19+
if len(comments) == 0 {
20+
return nil
21+
}
22+
23+
posterIDs := container.FilterSlice(comments, func(c *ConversationComment) (int64, bool) {
24+
return c.PosterID, c.Poster == nil && c.PosterID > 0
25+
})
26+
27+
posterMaps, err := getPostersByIDs(ctx, posterIDs)
28+
if err != nil {
29+
return err
30+
}
31+
32+
for _, comment := range comments {
33+
if comment.Poster == nil {
34+
comment.Poster = getPoster(comment.PosterID, posterMaps)
35+
}
36+
}
37+
return nil
38+
}
39+
1740
// getConversationIDs returns all the conversation ids on this comment list which conversation hasn't been loaded
1841
func (comments CommentList) getConversationIDs() []int64 {
1942
return container.FilterSlice(comments, func(comment *ConversationComment) (int64, bool) {
@@ -158,6 +181,10 @@ func (comments CommentList) LoadAttachments(ctx context.Context) (err error) {
158181
// LoadAttributes loads attributes of the comments, except for attachments and
159182
// comments
160183
func (comments CommentList) LoadAttributes(ctx context.Context) (err error) {
184+
if err = comments.LoadPosters(ctx); err != nil {
185+
return err
186+
}
187+
161188
if err = comments.LoadAttachments(ctx); err != nil {
162189
return err
163190
}

0 commit comments

Comments
 (0)