Fix action avatar loading (#13909)

Fixes #13883

Co-authored-by: 6543 <6543@obermui.de>
release/v1.15
silverwind 2020-12-09 06:11:15 +01:00 committed by GitHub
parent 10b9a6df0d
commit 97ab820acc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 9 deletions

View File

@ -77,7 +77,8 @@ func (a *Action) GetOpType() ActionType {
return a.OpType return a.OpType
} }
func (a *Action) loadActUser() { // LoadActUser loads a.ActUser
func (a *Action) LoadActUser() {
if a.ActUser != nil { if a.ActUser != nil {
return return
} }
@ -105,13 +106,13 @@ func (a *Action) loadRepo() {
// GetActFullName gets the action's user full name. // GetActFullName gets the action's user full name.
func (a *Action) GetActFullName() string { func (a *Action) GetActFullName() string {
a.loadActUser() a.LoadActUser()
return a.ActUser.FullName return a.ActUser.FullName
} }
// GetActUserName gets the action's user name. // GetActUserName gets the action's user name.
func (a *Action) GetActUserName() string { func (a *Action) GetActUserName() string {
a.loadActUser() a.LoadActUser()
return a.ActUser.Name return a.ActUser.Name
} }

View File

@ -338,11 +338,12 @@ func NewFuncMap() []template.FuncMap {
} }
return false return false
}, },
"svg": SVG, "svg": SVG,
"avatar": Avatar, "avatar": Avatar,
"avatarHTML": AvatarHTML, "avatarHTML": AvatarHTML,
"avatarByEmail": AvatarByEmail, "avatarByAction": AvatarByAction,
"repoAvatar": RepoAvatar, "avatarByEmail": AvatarByEmail,
"repoAvatar": RepoAvatar,
"SortArrow": func(normSort, revSort, urlSort string, isDefault bool) template.HTML { "SortArrow": func(normSort, revSort, urlSort string, isDefault bool) template.HTML {
// if needed // if needed
if len(normSort) == 0 || len(urlSort) == 0 { if len(normSort) == 0 || len(urlSort) == 0 {
@ -559,6 +560,12 @@ func Avatar(user *models.User, others ...interface{}) template.HTML {
return template.HTML("") return template.HTML("")
} }
// AvatarByAction renders user avatars from action. args: action, size (int), class (string)
func AvatarByAction(action *models.Action, others ...interface{}) template.HTML {
action.LoadActUser()
return Avatar(action.ActUser, others...)
}
// RepoAvatar renders repo avatars. args: repo, size(int), class (string) // RepoAvatar renders repo avatars. args: repo, size(int), class (string)
func RepoAvatar(repo *models.Repository, others ...interface{}) template.HTML { func RepoAvatar(repo *models.Repository, others ...interface{}) template.HTML {
size, class := parseOthers(models.DefaultAvatarPixelSize, "ui avatar image", others...) size, class := parseOthers(models.DefaultAvatarPixelSize, "ui avatar image", others...)

View File

@ -1,7 +1,7 @@
{{range .Feeds}} {{range .Feeds}}
<div class="news"> <div class="news">
<div class="ui left"> <div class="ui left">
{{avatar .ActUser}} {{avatarByAction .}}
</div> </div>
<div class="ui grid"> <div class="ui grid">
<div class="ui fourteen wide column"> <div class="ui fourteen wide column">