diff options
author | Lauris BH <lauris@nix.lv> | 2017-12-04 01:14:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-04 01:14:26 +0200 |
commit | 5dc37b187c8b839a15ff73758799f218ddeb3bc9 (patch) | |
tree | b63e5ca72c7b9e72c79408ace82dfcba992b5793 /models/issue.go | |
parent | e59adcde655aac0e8afd3249407c9a0a2b1b1d6b (diff) | |
download | gitea-5dc37b187c8b839a15ff73758799f218ddeb3bc9.tar.gz gitea-5dc37b187c8b839a15ff73758799f218ddeb3bc9.zip |
Add reactions to issues/PR and comments (#2856)
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/models/issue.go b/models/issue.go index 5f576be4a9..2119dcefd9 100644 --- a/models/issue.go +++ b/models/issue.go @@ -54,6 +54,7 @@ type Issue struct { Attachments []*Attachment `xorm:"-"` Comments []*Comment `xorm:"-"` + Reactions ReactionList `xorm:"-"` } // BeforeUpdate is invoked from XORM before updating this object. @@ -155,6 +156,37 @@ func (issue *Issue) loadComments(e Engine) (err error) { return err } +func (issue *Issue) loadReactions(e Engine) (err error) { + if issue.Reactions != nil { + return nil + } + reactions, err := findReactions(e, FindReactionsOptions{ + IssueID: issue.ID, + }) + if err != nil { + return err + } + // Load reaction user data + if _, err := ReactionList(reactions).LoadUsers(); err != nil { + return err + } + + // Cache comments to map + comments := make(map[int64]*Comment) + for _, comment := range issue.Comments { + comments[comment.ID] = comment + } + // Add reactions either to issue or comment + for _, react := range reactions { + if react.CommentID == 0 { + issue.Reactions = append(issue.Reactions, react) + } else if comment, ok := comments[react.CommentID]; ok { + comment.Reactions = append(comment.Reactions, react) + } + } + return nil +} + func (issue *Issue) loadAttributes(e Engine) (err error) { if err = issue.loadRepo(e); err != nil { return @@ -192,10 +224,10 @@ func (issue *Issue) loadAttributes(e Engine) (err error) { } if err = issue.loadComments(e); err != nil { - return + return err } - return nil + return issue.loadReactions(e) } // LoadAttributes loads the attribute of this issue. |