Merge pull request #10151 from stseng110499/feature/import-existing-study-hide-ratings

Hide ratings when importing game to existing study if option selected
deepcrayonfish^2
Thibault Duplessis 2021-11-22 10:00:54 +01:00 committed by GitHub
commit 238cb7fd49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 13 deletions

View File

@ -328,7 +328,8 @@ final class Study(
env.study.api.importPgns(
StudyModel.Id(id),
data.toChapterDatas,
sticky = data.sticky
sticky = data.sticky,
ctx.pref.showRatings
)(Who(me.id, lila.socket.Socket.Sri(sri)))
)
}

View File

@ -19,14 +19,14 @@ final private class ChapterMaker(
import ChapterMaker._
def apply(study: Study, data: Data, order: Int, userId: User.ID): Fu[Chapter] =
def apply(study: Study, data: Data, order: Int, userId: User.ID, withRatings: Boolean): Fu[Chapter] =
data.game.??(parseGame) flatMap {
case None =>
data.game ?? pgnFetch.fromUrl flatMap {
case Some(pgn) => fromFenOrPgnOrBlank(study, data.copy(pgn = pgn.some), order, userId)
case _ => fromFenOrPgnOrBlank(study, data, order, userId)
}
case Some(game) => fromGame(study, game, data, order, userId)
case Some(game) => fromGame(study, game, data, order, userId, withRatings)
} map { (c: Chapter) =>
if (c.name.value.isEmpty) c.copy(name = Chapter defaultName order) else c
}
@ -125,14 +125,15 @@ final private class ChapterMaker(
data: Data,
order: Int,
userId: User.ID,
withRatings: Boolean,
initialFen: Option[FEN] = None
): Fu[Chapter] =
for {
root <- game2root(game, initialFen)
tags <- pgnDump.tags(game, initialFen, none, withOpening = true, withRating = true)
tags <- pgnDump.tags(game, initialFen, none, withOpening = true, withRatings)
name <- {
if (data.isDefaultName)
Namer.gameVsText(game, withRatings = false)(lightUser.async) dmap Chapter.Name.apply
Namer.gameVsText(game, withRatings)(lightUser.async) dmap Chapter.Name.apply
else fuccess(data.name)
}
_ = notifyChat(study, game, userId)

View File

@ -132,7 +132,8 @@ final class StudyApi(
addChapter(
studyId = study.id,
data = data.form.toChapterData,
sticky = study.settings.sticky
sticky = study.settings.sticky,
withRatings
)(Who(user.id, Sri(""))) >> byIdWithLastChapter(studyId)
case _ => fuccess(none)
} orElse importGame(data.copy(form = data.form.copy(asStr = none)), user, withRatings)
@ -587,11 +588,13 @@ final class StudyApi(
}
}
def addChapter(studyId: Study.Id, data: ChapterMaker.Data, sticky: Boolean)(who: Who): Funit =
def addChapter(studyId: Study.Id, data: ChapterMaker.Data, sticky: Boolean, withRatings: Boolean)(
who: Who
): Funit =
data.manyGames match {
case Some(datas) =>
lila.common.Future.applySequentially(datas) { data =>
addChapter(studyId, data, sticky)(who)
addChapter(studyId, data, sticky, withRatings)(who)
}
case _ =>
sequenceStudy(studyId) { study =>
@ -605,7 +608,7 @@ final class StudyApi(
}
} >>
chapterRepo.nextOrderByStudy(study.id) flatMap { order =>
chapterMaker(study, data, order, who.u) flatMap { chapter =>
chapterMaker(study, data, order, who.u, withRatings) flatMap { chapter =>
doAddChapter(study, chapter, sticky, who)
} addFailureEffect {
case ChapterMaker.ValidationException(error) =>
@ -624,9 +627,11 @@ final class StudyApi(
studyRepo.updateSomeFields(study) >>- indexStudy(study)
}
def importPgns(studyId: Study.Id, datas: List[ChapterMaker.Data], sticky: Boolean)(who: Who) =
def importPgns(studyId: Study.Id, datas: List[ChapterMaker.Data], sticky: Boolean, withRatings: Boolean)(
who: Who
) =
lila.common.Future.applySequentially(datas) { data =>
addChapter(studyId, data, sticky)(who)
addChapter(studyId, data, sticky, withRatings)(who)
}
def doAddChapter(study: Study, chapter: Chapter, sticky: Boolean, who: Who) =
@ -731,7 +736,13 @@ final class StudyApi(
chapterRepo.orderedMetadataByStudy(studyId).flatMap { chaps =>
// deleting the only chapter? Automatically create an empty one
if (chaps.sizeIs < 2) {
chapterMaker(study, ChapterMaker.Data(Chapter.Name("Chapter 1")), 1, who.u) flatMap { c =>
chapterMaker(
study,
ChapterMaker.Data(Chapter.Name("Chapter 1")),
1,
who.u,
withRatings = true
) flatMap { c =>
doAddChapter(study, c, sticky = true, who) >> doSetChapter(study, c.id, who)
}
} // deleting the current chapter? Automatically move to another one

View File

@ -124,7 +124,7 @@ final private class StudySocket(
case "addChapter" =>
reading[ChapterMaker.Data](o) { data =>
val sticky = o.obj("d").flatMap(_.boolean("sticky")) | true
who foreach api.addChapter(studyId, data, sticky = sticky)
who foreach api.addChapter(studyId, data, sticky = sticky, withRatings = true)
}
case "setChapter" =>
o.get[Chapter.Id]("d") foreach { chapterId =>