update relay clocks when changed upstream
parent
10f481fa90
commit
1a58e4c924
|
@ -26,8 +26,20 @@ private final class RelaySync(
|
|||
game.root.mainline.foldLeft(Path.root -> none[Node]) {
|
||||
case ((parentPath, None), gameNode) =>
|
||||
val path = parentPath + gameNode
|
||||
if (chapter.root.nodeAt(path).isDefined) path -> none
|
||||
else (parentPath -> gameNode.some)
|
||||
chapter.root.nodeAt(path) match {
|
||||
case None => parentPath -> gameNode.some
|
||||
case Some(existing) =>
|
||||
gameNode.clock.filter(c => !existing.clock.has(c)) ?? { c =>
|
||||
studyApi.doSetClock(
|
||||
userId = chapter.ownerId,
|
||||
study = study,
|
||||
position = Position(chapter, path),
|
||||
clock = c.some,
|
||||
uid = socketUid
|
||||
)
|
||||
}
|
||||
path -> none
|
||||
}
|
||||
case (found, _) => found
|
||||
} match {
|
||||
case (_, None) => funit
|
||||
|
|
|
@ -304,6 +304,17 @@ final class StudyApi(
|
|||
}
|
||||
}
|
||||
|
||||
def doSetClock(userId: User.ID, study: Study, position: Position, clock: Option[Centis], uid: Uid) =
|
||||
position.chapter.setClock(clock, position.path) match {
|
||||
case Some(newChapter) =>
|
||||
studyRepo.updateNow(study)
|
||||
chapterRepo.setClock(newChapter, position.path, clock) >>-
|
||||
sendTo(study, Socket.SetClock(position.ref, clock, uid))
|
||||
case None =>
|
||||
fufail(s"Invalid setClock $position $clock") >>-
|
||||
reloadUidBecauseOf(study, uid, position.chapter.id)
|
||||
}
|
||||
|
||||
def setTag(userId: User.ID, studyId: Study.Id, setTag: actorApi.SetTag, uid: Uid) = sequenceStudy(studyId) { study =>
|
||||
Contribute(userId, study) {
|
||||
chapterRepo.byIdAndStudy(setTag.chapterId, studyId) flatMap {
|
||||
|
|
Loading…
Reference in New Issue