mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-11 16:05:49 +01:00
51 lines
1.8 KiB
Scala
51 lines
1.8 KiB
Scala
package view
|
|
|
|
import service.RequestCache
|
|
import twirl.api.Html
|
|
import util.StringUtil
|
|
|
|
trait AvatarImageProvider { self: RequestCache =>
|
|
|
|
/**
|
|
* Returns <img> which displays the avatar icon.
|
|
* Looks up Gravatar if avatar icon has not been configured in user settings.
|
|
*/
|
|
protected def getAvatarImageHtml(userName: String, size: Int,
|
|
mailAddress: String = "", tooltip: Boolean = false)(implicit context: app.Context): Html = {
|
|
|
|
val src = if(mailAddress.isEmpty){
|
|
// by user name
|
|
getAccountByUserName(userName).map { account =>
|
|
if(account.image.isEmpty && context.settings.gravatar){
|
|
s"""https://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress.toLowerCase)}?s=${size}&d=retro&r=g"""
|
|
} else {
|
|
s"""${context.path}/${account.userName}/_avatar"""
|
|
}
|
|
} getOrElse {
|
|
s"""${context.path}/_unknown/_avatar"""
|
|
}
|
|
} else {
|
|
// by mail address
|
|
getAccountByMailAddress(mailAddress).map { account =>
|
|
if(account.image.isEmpty && context.settings.gravatar){
|
|
s"""https://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress.toLowerCase)}?s=${size}&d=retro&r=g"""
|
|
} else {
|
|
s"""${context.path}/${account.userName}/_avatar"""
|
|
}
|
|
} getOrElse {
|
|
if(context.settings.gravatar){
|
|
s"""https://www.gravatar.com/avatar/${StringUtil.md5(mailAddress.toLowerCase)}?s=${size}&d=retro&r=g"""
|
|
} else {
|
|
s"""${context.path}/_unknown/_avatar"""
|
|
}
|
|
}
|
|
}
|
|
|
|
if(tooltip){
|
|
Html(s"""<img src="${src}" class="avatar" style="width: ${size}px; height: ${size}px;" data-toggle="tooltip" title="${userName}"/>""")
|
|
} else {
|
|
Html(s"""<img src="${src}" class="avatar" style="width: ${size}px; height: ${size}px;" />""")
|
|
}
|
|
}
|
|
|
|
} |