mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-18 00:47:48 -04:00
refactor: getPoster
This commit is contained in:
parent
911aea15a6
commit
0887e98f2a
@ -35,16 +35,7 @@ func (comments CommentList) LoadPosters(ctx context.Context) error {
|
||||
}
|
||||
|
||||
for _, comment := range comments {
|
||||
if comment.PosterID == user_model.ActionsUserID {
|
||||
comment.Poster = user_model.NewActionsUser()
|
||||
} else if comment.PosterID <= 0 {
|
||||
continue
|
||||
} else {
|
||||
var ok bool
|
||||
if comment.Poster, ok = posterMaps[comment.PosterID]; !ok {
|
||||
comment.Poster = user_model.NewGhostUser()
|
||||
}
|
||||
}
|
||||
comment.Poster = getPoster(comment.PosterID, posterMaps)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -92,16 +92,7 @@ func (issues IssueList) loadPosters(ctx context.Context) error {
|
||||
}
|
||||
|
||||
for _, issue := range issues {
|
||||
if issue.PosterID == user_model.ActionsUserID {
|
||||
issue.Poster = user_model.NewActionsUser()
|
||||
} else if issue.PosterID <= 0 {
|
||||
continue
|
||||
} else {
|
||||
var ok bool
|
||||
if issue.Poster, ok = posterMaps[issue.PosterID]; !ok {
|
||||
issue.Poster = user_model.NewGhostUser()
|
||||
}
|
||||
}
|
||||
issue.Poster = getPoster(issue.PosterID, posterMaps)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -126,6 +117,20 @@ func getPosters(ctx context.Context, posterIDs []int64) (map[int64]*user_model.U
|
||||
return posterMaps, nil
|
||||
}
|
||||
|
||||
func getPoster(posterID int64, posterMaps map[int64]*user_model.User) *user_model.User {
|
||||
if posterID == user_model.ActionsUserID {
|
||||
return user_model.NewActionsUser()
|
||||
}
|
||||
if posterID <= 0 {
|
||||
return nil
|
||||
}
|
||||
poster, ok := posterMaps[posterID]
|
||||
if !ok {
|
||||
return user_model.NewGhostUser()
|
||||
}
|
||||
return poster
|
||||
}
|
||||
|
||||
func (issues IssueList) getIssueIDs() []int64 {
|
||||
ids := make([]int64, 0, len(issues))
|
||||
for _, issue := range issues {
|
||||
|
Loading…
x
Reference in New Issue
Block a user