@@ -14,6 +14,29 @@ import (
1414// CommentList defines a list of comments
1515type 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
1841func (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
160183func (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