show full list of friends

pull/9850/head
Thibault Duplessis 2021-09-19 22:19:58 +02:00
parent e7fc377aad
commit 1333baf320
5 changed files with 54 additions and 88 deletions

View File

@ -117,8 +117,9 @@ final class Relation(
OptionFuResult(env.user.repo named username) { user =>
RelatedPager(api.followingPaginatorAdapter(user.id), page) flatMap { pag =>
negotiate(
html = api countFollowers user.id map { nbFollowers =>
Ok(html.relation.bits.following(user, pag, nbFollowers))
html = {
if (ctx is user) Ok(html.relation.bits.friends(user, pag)).fuccess
else ctx.me.fold(notFound)(me => Redirect(routes.Relation.following(me.username)).fuccess)
},
api = _ => Ok(jsonRelatedPaginator(pag)).fuccess
)
@ -129,18 +130,15 @@ final class Relation(
def followers(username: String, page: Int) =
Open { implicit ctx =>
Reasonable(page, 20) {
OptionFuResult(env.user.repo named username) { user =>
RelatedPager(api.followersPaginatorAdapter(user.id), page) flatMap { pag =>
negotiate(
html = api countFollowing user.id map { nbFollowing =>
Ok(html.relation.bits.followers(user, pag, nbFollowing))
},
api = _ => Ok(jsonRelatedPaginator(pag)).fuccess
)
negotiate(
html = notFound,
api = _ =>
Reasonable(page, 20) {
RelatedPager(api.followersPaginatorAdapter(UserModel normalize username), page) flatMap { pag =>
Ok(jsonRelatedPaginator(pag)).fuccess
}
}
}
}
)
}
def apiFollowing(name: String) = apiRelation(name, Direction.Following)

View File

@ -512,7 +512,7 @@ final class User(
}
}
.sequenceFu
} yield html.user.opponents(me, relateds)
} yield html.relation.bits.opponents(me, relateds)
}
def perfStat(username: String, perfKey: String) =

View File

@ -1,44 +1,23 @@
package views.html.relation
import controllers.routes
import play.api.mvc.Call
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.paginator.Paginator
import lila.game.FavoriteOpponents
import lila.relation.Related
import lila.user.User
import controllers.routes
object bits {
def followers(u: User, pag: Paginator[Related], nbFollowing: Int)(implicit ctx: Context) =
layout(s"${u.username}${trans.nbFollowers.pluralSameTxt(pag.nbResults)}")(
div(cls := "box__top")(
h1(userLink(u, withOnline = false)),
div(cls := "actions")(
trans.nbFollowers.pluralSame(pag.nbResults),
" ",
amp,
" ",
a(href := routes.Relation.following(u.username))(trans.nbFollowing.pluralSame(nbFollowing))
)
),
pagTable(pag, routes.Relation.followers(u.username))
)
def following(u: User, pag: Paginator[Related], nbFollowers: Int)(implicit ctx: Context) =
layout(s"${u.username}${trans.nbFollowing.pluralSameTxt(pag.nbResults)}")(
div(cls := "box__top")(
h1(userLink(u, withOnline = false)),
div(cls := "actions")(
trans.nbFollowing.pluralSame(pag.nbResults),
" ",
amp,
" ",
a(href := routes.Relation.followers(u.username))(trans.nbFollowers.pluralSame(nbFollowers))
)
def friends(u: User, pag: Paginator[Related])(implicit ctx: Context) =
layout(s"${u.username}${trans.friends.txt()}")(
h1(
a(href := routes.User.show(u.username), dataIcon := "", cls := "text"),
trans.friends()
),
pagTable(pag, routes.Relation.following(u.username))
)
@ -54,6 +33,38 @@ object bits {
pagTable(pag, routes.Relation.blocks())
)
def opponents(u: User, sugs: List[lila.relation.Related])(implicit ctx: Context) =
layout(s"${u.username}${trans.favoriteOpponents.txt()}")(
h1(
a(href := routes.User.show(u.username), dataIcon := "", cls := "text"),
trans.favoriteOpponents(),
" (",
trans.nbGames.pluralSame(FavoriteOpponents.gameLimit),
")"
),
table(cls := "slist")(
tbody(
if (sugs.nonEmpty) sugs.map { r =>
tr(
td(userLink(r.user)),
td(showBestPerf(r.user)),
td(
r.nbGames.filter(_ > 0).map { nbGames =>
a(href := s"${routes.User.games(u.username, "search")}?players.b=${r.user.username}")(
trans.nbGames.plural(nbGames, nbGames.localize)
)
}
),
td(
views.html.relation.actions(r.user.id, r.relation, followable = r.followable, blocked = false)
)
)
}
else tr(td(trans.none()))
)
)
)
def layout(title: String)(content: Modifier*)(implicit ctx: Context) =
views.html.base.layout(
title = title,
@ -71,7 +82,7 @@ object bits {
tr(cls := "paginated")(
td(userLink(r.user)),
td(showBestPerf(r.user)),
td(trans.nbGames.pluralSame(r.user.count.game)),
td(trans.nbGames.plural(r.user.count.game, r.user.count.game.localize)),
td(actions(r.user.id, relation = r.relation, followable = r.followable, blocked = false))
)
},

View File

@ -1,42 +0,0 @@
package views.html
package user
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.user.User
import lila.game.FavoriteOpponents
import controllers.routes
object opponents {
def apply(u: User, sugs: List[lila.relation.Related])(implicit ctx: Context) =
relation.bits.layout(s"${u.username}${trans.favoriteOpponents.txt()}")(
h1(
a(href := routes.User.show(u.username), dataIcon := "", cls := "text"),
trans.favoriteOpponents(),
" (",
trans.nbGames.pluralSame(FavoriteOpponents.gameLimit),
")"
),
table(cls := "slist")(
tbody(
if (sugs.nonEmpty) sugs.map { r =>
tr(
td(userLink(r.user)),
td(showBestPerf(r.user)),
td(
r.nbGames.filter(_ > 0).map { nbGames =>
a(href := s"${routes.User.games(u.username, "search")}?players.b=${r.user.username}")(
trans.nbGames.pluralSame(nbGames)
)
}
),
td(relation.actions(r.user.id, r.relation, followable = r.followable, blocked = false))
)
}
else tr(td(trans.none()))
)
)
)
}

View File

@ -48,9 +48,6 @@ object header {
),
div(cls := "user-show__social")(
div(cls := "number-menu")(
a(cls := "nm-item", href := routes.Relation.followers(u.username))(
splitNumber(trans.nbFollowers.pluralSame(info.nbFollowers))
),
u.noBot option a(
href := routes.UserTournament.path(u.username, "recent"),
cls := "nm-item tournament_stats",
@ -232,6 +229,8 @@ object header {
trans.profileCompletion(s"${profile.completionPercent}%")
),
br,
a(href := routes.Relation.following(u.username))(trans.friends()),
br,
a(href := routes.User.opponents)(trans.favoriteOpponents())
),
u.playTime.map { playTime =>