Merge pull request #10026 from stseng110499/import-game-study-hide-ratings

Hide ratings if selected for studies imported from game
pull/10033/head
Thibault Duplessis 2021-10-25 17:39:44 +02:00 committed by GitHub
commit 02963e0d91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 14 deletions

View File

@ -46,7 +46,7 @@ final class RelayRound(
ctx.req,
Redirect(routes.RelayTour.redirectOrApiTour(tour.slug, tour.id.value))
) {
env.relay.api.create(setup, me, tour) map { round =>
env.relay.api.create(setup, me, tour, ctx.pref.showRatings) map { round =>
Redirect(routes.RelayRound.show(tour.slug, round.slug, round.id.value))
}
}
@ -67,7 +67,7 @@ final class RelayRound(
setup =>
rateLimitCreation(me, req, rateLimited) {
JsonOk {
env.relay.api.create(setup, me, tour) map { round =>
env.relay.api.create(setup, me, tour, withRatings = true) map { round =>
env.relay.jsonView.withUrl(round withTour tour)
}
}

View File

@ -291,7 +291,7 @@ final class Study(
private def createStudy(data: lila.study.StudyForm.importGame.Data, me: lila.user.User)(implicit
ctx: Context
) =
env.study.api.importGame(lila.study.StudyMaker.ImportGame(data), me) flatMap {
env.study.api.importGame(lila.study.StudyMaker.ImportGame(data), me, ctx.pref.showRatings) flatMap {
_.fold(notFound) { sc =>
Redirect(routes.Study.chapter(sc.study.id.value, sc.chapter.id.value)).fuccess
}

View File

@ -151,7 +151,7 @@ final class RelayApi(
def tourUpdate(tour: RelayTour, data: RelayTourForm.Data, user: User): Funit =
tourRepo.coll.update.one($id(tour.id), data.update(tour, user)).void
def create(data: RelayRoundForm.Data, user: User, tour: RelayTour): Fu[RelayRound] =
def create(data: RelayRoundForm.Data, user: User, tour: RelayTour, withRatings: Boolean): Fu[RelayRound] =
roundRepo.lastByTour(tour) flatMap {
_ ?? { last => studyRepo.byId(last.studyId) }
} flatMap { lastStudy =>
@ -174,6 +174,7 @@ final class RelayApi(
from = Study.From.Relay(none).some
),
user,
withRatings,
_.copy(members =
lastStudy.fold(StudyMembers.empty)(_.members) + StudyMember(
id = user.id,

View File

@ -119,9 +119,13 @@ final class StudyApi(
def members(id: Study.Id): Fu[Option[StudyMembers]] = studyRepo membersById id
def importGame(data: StudyMaker.ImportGame, user: User): Fu[Option[Study.WithChapter]] =
def importGame(
data: StudyMaker.ImportGame,
user: User,
withRatings: Boolean
): Fu[Option[Study.WithChapter]] =
(data.form.as match {
case StudyForm.importGame.AsNewStudy => create(data, user)
case StudyForm.importGame.AsNewStudy => create(data, user, withRatings)
case StudyForm.importGame.AsChapterOf(studyId) =>
byId(studyId) flatMap {
case Some(study) if study.canContribute(user.id) =>
@ -131,7 +135,7 @@ final class StudyApi(
sticky = study.settings.sticky
)(Who(user.id, Sri(""))) >> byIdWithLastChapter(studyId)
case _ => fuccess(none)
} orElse importGame(data.copy(form = data.form.copy(asStr = none)), user)
} orElse importGame(data.copy(form = data.form.copy(asStr = none)), user, withRatings)
}) addEffect {
_ ?? { sc =>
Bus.publish(actorApi.StartStudy(sc.study.id), "startStudy")
@ -141,9 +145,10 @@ final class StudyApi(
def create(
data: StudyMaker.ImportGame,
user: User,
withRatings: Boolean,
transform: Study => Study = identity
): Fu[Option[Study.WithChapter]] =
studyMaker(data, user) map { sc =>
studyMaker(data, user, withRatings) map { sc =>
sc.copy(study = transform(sc.study))
} flatMap { sc =>
studyRepo.insert(sc.study) >>

View File

@ -11,10 +11,11 @@ final private class StudyMaker(
pgnDump: lila.game.PgnDump
)(implicit ec: scala.concurrent.ExecutionContext) {
def apply(data: StudyMaker.ImportGame, user: User): Fu[Study.WithChapter] =
def apply(data: StudyMaker.ImportGame, user: User, withRatings: Boolean): Fu[Study.WithChapter] =
(data.form.gameId ?? gameRepo.gameWithInitialFen).flatMap {
case Some((game, initialFen)) => createFromPov(data, Pov(game, data.form.orientation), initialFen, user)
case None => createFromScratch(data, user)
case Some((game, initialFen)) =>
createFromPov(data, Pov(game, data.form.orientation), initialFen, user, withRatings)
case None => createFromScratch(data, user)
} map { sc =>
// apply specified From if any
sc.copy(study = sc.study.copy(from = data.from | sc.study.from))
@ -45,12 +46,13 @@ final private class StudyMaker(
data: StudyMaker.ImportGame,
pov: Pov,
initialFen: Option[FEN],
user: User
user: User,
withRatings: Boolean
): Fu[Study.WithChapter] = {
for {
root <- chapterMaker.game2root(pov.game, initialFen)
tags <- pgnDump.tags(pov.game, initialFen, none, withOpening = true, withRating = true)
name <- Namer.gameVsText(pov.game, withRatings = false)(lightUserApi.async) dmap Chapter.Name.apply
tags <- pgnDump.tags(pov.game, initialFen, none, withOpening = true, withRatings)
name <- Namer.gameVsText(pov.game, withRatings)(lightUserApi.async) dmap Chapter.Name.apply
study = Study.make(user, Study.From.Game(pov.gameId), data.id, Study.Name("Game study").some)
chapter = Chapter.make(
studyId = study.id,