@@ -17,13 +17,15 @@ import (
1717
1818// Reaction represents a reactions on issues and comments.
1919type Reaction struct {
20- ID int64 `xorm:"pk autoincr"`
21- Type string `xorm:"INDEX UNIQUE(s) NOT NULL"`
22- IssueID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"`
23- CommentID int64 `xorm:"INDEX UNIQUE(s)"`
24- UserID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"`
25- User * User `xorm:"-"`
26- CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
20+ ID int64 `xorm:"pk autoincr"`
21+ Type string `xorm:"INDEX UNIQUE(s) NOT NULL"`
22+ IssueID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"`
23+ CommentID int64 `xorm:"INDEX UNIQUE(s)"`
24+ UserID int64 `xorm:"INDEX UNIQUE(s) NOT NULL"`
25+ OriginalAuthorID int64 `xorm:"INDEX UNIQUE(s) NOT NULL DEFAULT(0)"`
26+ OriginalAuthor string
27+ User * User `xorm:"-"`
28+ CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
2729}
2830
2931// FindReactionsOptions describes the conditions to Find reactions
@@ -49,7 +51,10 @@ func (opts *FindReactionsOptions) toConds() builder.Cond {
4951 cond = cond .And (builder.Eq {"reaction.comment_id" : 0 })
5052 }
5153 if opts .UserID > 0 {
52- cond = cond .And (builder.Eq {"reaction.user_id" : opts .UserID })
54+ cond = cond .And (builder.Eq {
55+ "reaction.user_id" : opts .UserID ,
56+ "reaction.original_author_id" : 0 ,
57+ })
5358 }
5459 if opts .Reaction != "" {
5560 cond = cond .And (builder.Eq {"reaction.type" : opts .Reaction })
@@ -173,7 +178,7 @@ func deleteReaction(e *xorm.Session, opts *ReactionOptions) error {
173178 if opts .Comment != nil {
174179 reaction .CommentID = opts .Comment .ID
175180 }
176- _ , err := e .Delete (reaction )
181+ _ , err := e .Where ( "original_author_id = 0" ). Delete (reaction )
177182 return err
178183}
179184
@@ -233,7 +238,7 @@ func (list ReactionList) HasUser(userID int64) bool {
233238 return false
234239 }
235240 for _ , reaction := range list {
236- if reaction .UserID == userID {
241+ if reaction .OriginalAuthor == "" && reaction . UserID == userID {
237242 return true
238243 }
239244 }
@@ -252,14 +257,17 @@ func (list ReactionList) GroupByType() map[string]ReactionList {
252257func (list ReactionList ) getUserIDs () []int64 {
253258 userIDs := make (map [int64 ]struct {}, len (list ))
254259 for _ , reaction := range list {
260+ if reaction .OriginalAuthor != "" {
261+ continue
262+ }
255263 if _ , ok := userIDs [reaction .UserID ]; ! ok {
256264 userIDs [reaction .UserID ] = struct {}{}
257265 }
258266 }
259267 return keysInt64 (userIDs )
260268}
261269
262- func (list ReactionList ) loadUsers (e Engine ) ([]* User , error ) {
270+ func (list ReactionList ) loadUsers (e Engine , repo * Repository ) ([]* User , error ) {
263271 if len (list ) == 0 {
264272 return nil , nil
265273 }
@@ -274,7 +282,9 @@ func (list ReactionList) loadUsers(e Engine) ([]*User, error) {
274282 }
275283
276284 for _ , reaction := range list {
277- if user , ok := userMaps [reaction .UserID ]; ok {
285+ if reaction .OriginalAuthor != "" {
286+ reaction .User = NewReplaceUser (fmt .Sprintf ("%s(%s)" , reaction .OriginalAuthor , repo .OriginalServiceType .Name ()))
287+ } else if user , ok := userMaps [reaction .UserID ]; ok {
278288 reaction .User = user
279289 } else {
280290 reaction .User = NewGhostUser ()
@@ -284,8 +294,8 @@ func (list ReactionList) loadUsers(e Engine) ([]*User, error) {
284294}
285295
286296// LoadUsers loads reactions' all users
287- func (list ReactionList ) LoadUsers () ([]* User , error ) {
288- return list .loadUsers (x )
297+ func (list ReactionList ) LoadUsers (repo * Repository ) ([]* User , error ) {
298+ return list .loadUsers (x , repo )
289299}
290300
291301// GetFirstUsers returns first reacted user display names separated by comma
0 commit comments