diff options
Diffstat (limited to 'models/issue_reaction.go')
-rw-r--r-- | models/issue_reaction.go | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/models/issue_reaction.go b/models/issue_reaction.go index d421ab44e9..5c3bf9d06e 100644 --- a/models/issue_reaction.go +++ b/models/issue_reaction.go @@ -17,13 +17,15 @@ import ( // Reaction represents a reactions on issues and comments. type Reaction struct { - ID int64 `xorm:"pk autoincr"` - Type string `xorm:"INDEX UNIQUE(s) NOT NULL"` - IssueID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"` - CommentID int64 `xorm:"INDEX UNIQUE(s)"` - UserID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"` - User *User `xorm:"-"` - CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` + ID int64 `xorm:"pk autoincr"` + Type string `xorm:"INDEX UNIQUE(s) NOT NULL"` + IssueID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"` + CommentID int64 `xorm:"INDEX UNIQUE(s)"` + UserID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"` + OriginalAuthorID int64 `xorm:"INDEX UNIQUE(s) NOT NULL DEFAULT(0)"` + OriginalAuthor string + User *User `xorm:"-"` + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` } // FindReactionsOptions describes the conditions to Find reactions @@ -49,7 +51,10 @@ func (opts *FindReactionsOptions) toConds() builder.Cond { cond = cond.And(builder.Eq{"reaction.comment_id": 0}) } if opts.UserID > 0 { - cond = cond.And(builder.Eq{"reaction.user_id": opts.UserID}) + cond = cond.And(builder.Eq{ + "reaction.user_id": opts.UserID, + "reaction.original_author_id": 0, + }) } if opts.Reaction != "" { cond = cond.And(builder.Eq{"reaction.type": opts.Reaction}) @@ -173,7 +178,7 @@ func deleteReaction(e *xorm.Session, opts *ReactionOptions) error { if opts.Comment != nil { reaction.CommentID = opts.Comment.ID } - _, err := e.Delete(reaction) + _, err := e.Where("original_author_id = 0").Delete(reaction) return err } @@ -233,7 +238,7 @@ func (list ReactionList) HasUser(userID int64) bool { return false } for _, reaction := range list { - if reaction.UserID == userID { + if reaction.OriginalAuthor == "" && reaction.UserID == userID { return true } } @@ -252,6 +257,9 @@ func (list ReactionList) GroupByType() map[string]ReactionList { func (list ReactionList) getUserIDs() []int64 { userIDs := make(map[int64]struct{}, len(list)) for _, reaction := range list { + if reaction.OriginalAuthor != "" { + continue + } if _, ok := userIDs[reaction.UserID]; !ok { userIDs[reaction.UserID] = struct{}{} } @@ -259,7 +267,7 @@ func (list ReactionList) getUserIDs() []int64 { return keysInt64(userIDs) } -func (list ReactionList) loadUsers(e Engine) ([]*User, error) { +func (list ReactionList) loadUsers(e Engine, repo *Repository) ([]*User, error) { if len(list) == 0 { return nil, nil } @@ -274,7 +282,9 @@ func (list ReactionList) loadUsers(e Engine) ([]*User, error) { } for _, reaction := range list { - if user, ok := userMaps[reaction.UserID]; ok { + if reaction.OriginalAuthor != "" { + reaction.User = NewReplaceUser(fmt.Sprintf("%s(%s)", reaction.OriginalAuthor, repo.OriginalServiceType.Name())) + } else if user, ok := userMaps[reaction.UserID]; ok { reaction.User = user } else { reaction.User = NewGhostUser() @@ -284,8 +294,8 @@ func (list ReactionList) loadUsers(e Engine) ([]*User, error) { } // LoadUsers loads reactions' all users -func (list ReactionList) LoadUsers() ([]*User, error) { - return list.loadUsers(x) +func (list ReactionList) LoadUsers(repo *Repository) ([]*User, error) { + return list.loadUsers(x, repo) } // GetFirstUsers returns first reacted user display names separated by comma |