Skip to content

Commit 434d0b5

Browse files
PR lichess-org#4453: simple requested changes
1 parent 341dac3 commit 434d0b5

File tree

6 files changed

+24
-36
lines changed

6 files changed

+24
-36
lines changed

app/controllers/Tournament.scala

+16-25
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,24 @@ object Tournament extends LilaController {
8484
negotiate(
8585
html = repo byId id flatMap {
8686
_.fold(tournamentNotFound.fuccess) { tour =>
87-
teamIdsIBelongToO(ctx.me) flatMap { teams =>
88-
(for {
89-
verdicts <- env.api.verdicts(tour, ctx.me, teams)
90-
version <- env.version(tour.id)
91-
chat <- canHaveChat(tour) ?? Env.chat.api.userChat.cached.findMine(Chat.Id(tour.id), ctx.me).map(some)
92-
json <- env.jsonView(tour, page, ctx.me, teams, none, version.some, ctx.lang)
93-
_ <- chat ?? { c => Env.user.lightUserApi.preloadMany(c.chat.userIds) }
94-
streamers <- streamerCache get tour.id
95-
shieldOwner <- env.shieldApi currentOwner tour
96-
} yield Ok(html.tournament.show(tour, verdicts, json, chat, streamers, shieldOwner))).mon(_.http.response.tournament.show.website)
97-
}
87+
(for {
88+
teams <- ctx.me ?? { teamIdsIBelongTo(_).map(_.some) }
89+
verdicts <- env.api.verdicts(tour, ctx.me, teams)
90+
version <- env.version(tour.id)
91+
chat <- canHaveChat(tour) ?? Env.chat.api.userChat.cached.findMine(Chat.Id(tour.id), ctx.me).map(some)
92+
json <- env.jsonView(tour, page, ctx.me, teams, none, version.some, ctx.lang)
93+
_ <- chat ?? { c => Env.user.lightUserApi.preloadMany(c.chat.userIds) }
94+
streamers <- streamerCache get tour.id
95+
shieldOwner <- env.shieldApi currentOwner tour
96+
} yield Ok(html.tournament.show(tour, verdicts, json, chat, streamers, shieldOwner))).mon(_.http.response.tournament.show.website)
9897
}
9998
}, api = _ => repo byId id flatMap {
10099
case None => NotFound(jsonError("No such tournament")).fuccess
101100
case Some(tour) => {
102101
get("playerInfo").?? { env.api.playerInfo(tour.id, _) } zip
103102
getBool("socketVersion").??(env version tour.id map some) flatMap {
104103
case (playerInfoExt, socketVersion) =>
105-
teamIdsIBelongToO(ctx.me) flatMap { teams =>
104+
ctx.me ?? { teamIdsIBelongTo(_).map(_.some) } flatMap { teams =>
106105
env.jsonView(tour, page, ctx.me, teams, playerInfoExt, socketVersion, ctx.lang)
107106
}
108107
} map { Ok(_) }
@@ -241,10 +240,8 @@ object Tournament extends LilaController {
241240
isGranted(_.ManageTournament)) 1 else 4
242241
CreateLimitPerUser(me.id, cost = 1) {
243242
CreateLimitPerIP(HTTPRequest lastRemoteAddress ctx.req, cost = 1) {
244-
teamsIBelongTo(me) flatMap { teams =>
245-
env.api.createTournament(setup, me, teams) flatMap { tour =>
246-
fuccess(Redirect(routes.Tournament.show(tour.id)))
247-
}
243+
env.api.createTournament(setup, me, teams) flatMap { tour =>
244+
fuccess(Redirect(routes.Tournament.show(tour.id)))
248245
}
249246
}(rateLimited)
250247
}(rateLimited)
@@ -320,18 +317,12 @@ object Tournament extends LilaController {
320317
expireAfter = _.ExpireAfterWrite(15.seconds)
321318
)
322319

323-
private val teamApi = lila.app.Env.team.api
320+
private val teamApi = Env.team.api
321+
private val teamCached = Env.team.cached
324322
private def teamIdsIBelongTo(me: lila.user.User): Fu[List[String]] =
325-
teamApi.mine(me) map { teams =>
326-
teams.map(_.id)
327-
}
323+
teamCached.teamIdsList(me.id)
328324
private def teamsIBelongTo(me: lila.user.User): Fu[List[(String, String)]] =
329325
teamApi.mine(me) map { teams =>
330326
teams.map(t => t._id -> t.name)
331327
}
332-
private def teamIdsIBelongToO(me: Option[lila.user.User]): Fu[Option[List[String]]] =
333-
me match {
334-
case Some(user) => teamIdsIBelongTo(user) map { t => t.some }
335-
case None => fuccess(None)
336-
}
337328
}

app/views/tournament/crud/inForm.scala.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@
4646
@tournament.startingPosition(field)
4747
}
4848
<h2>Conditions of entry</h2>
49-
@tournament.conditionForm(form, auto = false, List())
49+
@tournament.conditionForm(form, auto = false, Nil)
5050
@base.form.submit()

modules/tournament/src/main/Condition.scala

+3-6
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,10 @@ object Condition {
255255
"teamId" -> optional(text)
256256
)(TeamMemberSetup.apply)(TeamMemberSetup.unapply)
257257
case class TeamMemberSetup(teamId: Option[String]) {
258-
def convert(teams: Map[String, String]): Option[TeamMember] = {
259-
val id = teamId getOrElse "";
260-
teams.get(id) match {
261-
case Some(teamName) => TeamMember(id, teamName).some
262-
case None => None
258+
def convert(teams: Map[String, String]): Option[TeamMember] =
259+
teamId flatMap { id =>
260+
teams.get(id) map { TeamMember(id, _) }
263261
}
264-
}
265262
}
266263
object TeamMemberSetup {
267264
val default = TeamMemberSetup(None)

modules/tournament/src/main/JsonView.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final class JsonView(
5656
verdicts <- me match {
5757
case None => fuccess(tour.conditions.accepted)
5858
case Some(user) if myInfo.isDefined => fuccess(tour.conditions.accepted)
59-
case Some(user) => verify(tour.conditions, user, myTeamIds.getOrElse(List()))
59+
case Some(user) => verify(tour.conditions, user, ~myTeamIds)
6060
}
6161
stats <- statsApi(tour)
6262
myGameId <- me.ifTrue(myInfo.isDefined) ?? { fetchCurrentGameId(tour, _) }

modules/tournament/src/main/TournamentApi.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ final class TournamentApi(
195195

196196
def verdicts(tour: Tournament, me: Option[User], myTeamIds: Option[List[String]]): Fu[Condition.All.WithVerdicts] = me match {
197197
case None => fuccess(tour.conditions.accepted)
198-
case Some(user) => verify(tour.conditions, user, myTeamIds.getOrElse(List()))
198+
case Some(user) => verify(tour.conditions, user, ~myTeamIds)
199199
}
200200

201201
def join(tourId: Tournament.ID, me: User, p: Option[String], myTeamIds: List[String]): Unit = {

translation/source/site.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@
303303
<string name="yourPerfRatingIsTooLow">Your %1$s rating (%2$s) is too low</string>
304304
<string name="ratedMoreThanInPerf">Rated ≥ %1$s in %2$s</string>
305305
<string name="ratedLessThanInPerf">Rated ≤ %1$s in %2$s</string>
306-
<string name="mustBeInTeam">Must be in team %s.</string>
307-
<string name="youAreNotInTeam">You are not in the team %s.</string>
306+
<string name="mustBeInTeam">Must be in team %s</string>
307+
<string name="youAreNotInTeam">You are not in the team %s</string>
308308
<string name="backToGame">Back to game</string>
309309
<string name="siteDescription">Free online Chess server. Play Chess now in a clean interface. No registration, no ads, no plugin required. Play Chess with the computer, friends or random opponents.</string>
310310
<string name="teams">Teams</string>

0 commit comments

Comments
 (0)