@@ -17,13 +17,15 @@ import (
17
17
18
18
// Reaction represents a reactions on issues and comments.
19
19
type 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"`
27
29
}
28
30
29
31
// FindReactionsOptions describes the conditions to Find reactions
@@ -49,7 +51,10 @@ func (opts *FindReactionsOptions) toConds() builder.Cond {
49
51
cond = cond .And (builder.Eq {"reaction.comment_id" : 0 })
50
52
}
51
53
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
+ })
53
58
}
54
59
if opts .Reaction != "" {
55
60
cond = cond .And (builder.Eq {"reaction.type" : opts .Reaction })
@@ -173,7 +178,7 @@ func deleteReaction(e *xorm.Session, opts *ReactionOptions) error {
173
178
if opts .Comment != nil {
174
179
reaction .CommentID = opts .Comment .ID
175
180
}
176
- _ , err := e .Delete (reaction )
181
+ _ , err := e .Where ( "original_author_id = 0" ). Delete (reaction )
177
182
return err
178
183
}
179
184
@@ -233,7 +238,7 @@ func (list ReactionList) HasUser(userID int64) bool {
233
238
return false
234
239
}
235
240
for _ , reaction := range list {
236
- if reaction .UserID == userID {
241
+ if reaction .OriginalAuthor == "" && reaction . UserID == userID {
237
242
return true
238
243
}
239
244
}
@@ -252,14 +257,17 @@ func (list ReactionList) GroupByType() map[string]ReactionList {
252
257
func (list ReactionList ) getUserIDs () []int64 {
253
258
userIDs := make (map [int64 ]struct {}, len (list ))
254
259
for _ , reaction := range list {
260
+ if reaction .OriginalAuthor != "" {
261
+ continue
262
+ }
255
263
if _ , ok := userIDs [reaction .UserID ]; ! ok {
256
264
userIDs [reaction .UserID ] = struct {}{}
257
265
}
258
266
}
259
267
return keysInt64 (userIDs )
260
268
}
261
269
262
- func (list ReactionList ) loadUsers (e Engine ) ([]* User , error ) {
270
+ func (list ReactionList ) loadUsers (e Engine , repo * Repository ) ([]* User , error ) {
263
271
if len (list ) == 0 {
264
272
return nil , nil
265
273
}
@@ -274,7 +282,9 @@ func (list ReactionList) loadUsers(e Engine) ([]*User, error) {
274
282
}
275
283
276
284
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 {
278
288
reaction .User = user
279
289
} else {
280
290
reaction .User = NewGhostUser ()
@@ -284,8 +294,8 @@ func (list ReactionList) loadUsers(e Engine) ([]*User, error) {
284
294
}
285
295
286
296
// 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 )
289
299
}
290
300
291
301
// GetFirstUsers returns first reacted user display names separated by comma
0 commit comments