Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix action avatar loading #13909

Merged
merged 4 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func (a *Action) GetOpType() ActionType {
return a.OpType
}

func (a *Action) loadActUser() {
// LoadActUser loads a.ActUser
func (a *Action) LoadActUser() {
if a.ActUser != nil {
return
}
Expand Down Expand Up @@ -105,13 +106,13 @@ func (a *Action) loadRepo() {

// GetActFullName gets the action's user full name.
func (a *Action) GetActFullName() string {
a.loadActUser()
a.LoadActUser()
return a.ActUser.FullName
}

// GetActUserName gets the action's user name.
func (a *Action) GetActUserName() string {
a.loadActUser()
a.LoadActUser()
return a.ActUser.Name
}

Expand Down
17 changes: 12 additions & 5 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,12 @@ func NewFuncMap() []template.FuncMap {
}
return false
},
"svg": SVG,
"avatar": Avatar,
"avatarHTML": AvatarHTML,
"avatarByEmail": AvatarByEmail,
"repoAvatar": RepoAvatar,
"svg": SVG,
"avatar": Avatar,
"avatarHTML": AvatarHTML,
"avatarByAction": AvatarByAction,
"avatarByEmail": AvatarByEmail,
"repoAvatar": RepoAvatar,
"SortArrow": func(normSort, revSort, urlSort string, isDefault bool) template.HTML {
// if needed
if len(normSort) == 0 || len(urlSort) == 0 {
Expand Down Expand Up @@ -559,6 +560,12 @@ func Avatar(user *models.User, others ...interface{}) 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)
func RepoAvatar(repo *models.Repository, others ...interface{}) template.HTML {
size, class := parseOthers(models.DefaultAvatarPixelSize, "ui avatar image", others...)
Expand Down
2 changes: 1 addition & 1 deletion templates/user/dashboard/feeds.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{range .Feeds}}
<div class="news">
<div class="ui left">
{{avatar .ActUser}}
{{avatarByAction .}}
</div>
<div class="ui grid">
<div class="ui fourteen wide column">
Expand Down