aboutsummaryrefslogtreecommitdiffstats
path: root/modules/templates
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2021-10-06 07:25:46 +0800
committerGitHub <noreply@github.com>2021-10-06 01:25:46 +0200
commitf0ba87fda88c7bb601eee17f3e3a72bea8a71521 (patch)
treecb5caf3a22fceaec8d2d421bec0cb094ecdb9c53 /modules/templates
parent48c2578bd8ce4ddd90bf926bd40388f57c90fe14 (diff)
downloadgitea-f0ba87fda88c7bb601eee17f3e3a72bea8a71521.tar.gz
gitea-f0ba87fda88c7bb601eee17f3e3a72bea8a71521.zip
Avatar refactor, move avatar code from `models` to `models.avatars`, remove duplicated code (#17123)
Why this refactor The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first. And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear: * user.AvatarLink() * user.AvatarLinkWithSize(size) * avatars.GenerateEmailAvatarFastLink(email, size) * avatars.GenerateEmailAvatarFinalLink(email, size) And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
Diffstat (limited to 'modules/templates')
-rw-r--r--modules/templates/helper.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 27d81ec9d9..b935eb6cc0 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -23,6 +23,7 @@ import (
"unicode"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/avatars"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/emoji"
"code.gitea.io/gitea/modules/git"
@@ -550,16 +551,16 @@ func SVG(icon string, others ...interface{}) template.HTML {
// Avatar renders user avatars. args: user, size (int), class (string)
func Avatar(item interface{}, others ...interface{}) template.HTML {
- size, class := parseOthers(models.DefaultAvatarPixelSize, "ui avatar image", others...)
+ size, class := parseOthers(avatars.DefaultAvatarPixelSize, "ui avatar image", others...)
if user, ok := item.(*models.User); ok {
- src := user.RealSizedAvatarLink(size * models.AvatarRenderedSizeFactor)
+ src := user.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor)
if src != "" {
return AvatarHTML(src, size, class, user.DisplayName())
}
}
if user, ok := item.(*models.Collaborator); ok {
- src := user.RealSizedAvatarLink(size * models.AvatarRenderedSizeFactor)
+ src := user.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor)
if src != "" {
return AvatarHTML(src, size, class, user.DisplayName())
}
@@ -575,7 +576,7 @@ func AvatarByAction(action *models.Action, others ...interface{}) template.HTML
// 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...)
+ size, class := parseOthers(avatars.DefaultAvatarPixelSize, "ui avatar image", others...)
src := repo.RelAvatarLink()
if src != "" {
@@ -586,8 +587,8 @@ func RepoAvatar(repo *models.Repository, others ...interface{}) template.HTML {
// AvatarByEmail renders avatars by email address. args: email, name, size (int), class (string)
func AvatarByEmail(email string, name string, others ...interface{}) template.HTML {
- size, class := parseOthers(models.DefaultAvatarPixelSize, "ui avatar image", others...)
- src := models.SizedAvatarLink(email, size*models.AvatarRenderedSizeFactor)
+ size, class := parseOthers(avatars.DefaultAvatarPixelSize, "ui avatar image", others...)
+ src := avatars.GenerateEmailAvatarFastLink(email, size*avatars.AvatarRenderedSizeFactor)
if src != "" {
return AvatarHTML(src, size, class, name)