Skip to content

Commit

Permalink
fix setting broadcast round as unfinished manually
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Nov 17, 2024
1 parent 3c981d1 commit 94c9608
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 6 additions & 0 deletions modules/db/src/main/dsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ trait dsl:
"$unset" -> fields.nonEmpty.so($doc(fields.map(k => (k, BSONString("")))))
def $unset(field: String, fields: String*): Bdoc = $doc:
"$unset" -> $doc((Seq(field) ++ fields).map(k => (k, BSONString(""))))

def $unsetCompute[A](prev: A, next: A, fields: (String, A => Option[?])*): Bdoc =
$unset:
fields.flatMap: (key, accessor) =>
(accessor(prev).isDefined && accessor(next).isEmpty).option(key)

def $setBoolOrUnset(field: String, value: Boolean): Bdoc =
if value then $set(field -> true) else $unset(field)
def $setsAndUnsets(items: (String, Option[BSONValue])*): Bdoc =
Expand Down
4 changes: 2 additions & 2 deletions modules/relay/src/main/RelayApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ final class RelayApi(
round <- copyRoundSourceSettings(updated)
_ <- (from.name != round.name).so(studyApi.rename(round.studyId, round.name.into(StudyName)))
setters <- tryBdoc(round).toEither.toFuture
unsetters = (from.caption.isDefined && updated.caption.isEmpty).option("caption").toList
_ <- roundRepo.coll.update.one($id(round.id), $set(setters) ++ $unset(unsetters)).void
unsets = $unsetCompute(from, updated, ("caption", _.caption), ("finishedAt", _.finishedAt))
_ <- roundRepo.coll.update.one($id(round.id), $set(setters) ++ unsets).void
_ <- (round.sync.playing != from.sync.playing)
.so(sendToContributors(round.id, "relaySync", jsonView.sync(round)))
_ <- denormalizeTour(round.tourId)
Expand Down
4 changes: 1 addition & 3 deletions modules/relay/src/main/RelayRoundForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ object RelayRoundForm:
caption = if Granter(_.StudyAdmin) then caption else relay.caption,
sync = if relay.sync.playing then sync.play(official) else sync,
startsAt = relayStartsAt,
finishedAt = finished.fold(relay.finishedAt):
if _ then relay.finishedAt.orElse(nowInstant.some)
else none
finishedAt = finished.orZero.option(relay.finishedAt.|(nowInstant))
)

private def makeSync(prev: Option[RelayRound.Sync])(using Me): Sync =
Expand Down

0 comments on commit 94c9608

Please sign in to comment.