default to dark theme
Only applies to anonymous players, and accounts created after this change.dark-default
parent
f6b1ec10a0
commit
cc0aa2f531
|
@ -9,20 +9,18 @@ final class Share(
|
|||
relationApi: lila.relation.RelationApi
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
def getPrefId(insighted: User) = prefApi.getPrefById(insighted.id) dmap (_.insightShare)
|
||||
def getPrefId(insighted: User) = prefApi.getPref(insighted.id, _.insightShare)
|
||||
|
||||
def grant(insighted: User, to: Option[User]): Fu[Boolean] =
|
||||
if (to ?? Granter(_.SeeInsight)) fuTrue
|
||||
else
|
||||
prefApi.getPrefById(insighted.id) flatMap { pref =>
|
||||
pref.insightShare match {
|
||||
case _ if to.contains(insighted) => fuTrue
|
||||
case Pref.InsightShare.EVERYBODY => fuTrue
|
||||
case Pref.InsightShare.FRIENDS =>
|
||||
to ?? { t =>
|
||||
relationApi.fetchAreFriends(insighted.id, t.id)
|
||||
}
|
||||
case Pref.InsightShare.NOBODY => fuFalse
|
||||
}
|
||||
getPrefId(insighted) flatMap {
|
||||
case _ if to.contains(insighted) => fuTrue
|
||||
case Pref.InsightShare.EVERYBODY => fuTrue
|
||||
case Pref.InsightShare.FRIENDS =>
|
||||
to ?? { t =>
|
||||
relationApi.fetchAreFriends(insighted.id, t.id)
|
||||
}
|
||||
case Pref.InsightShare.NOBODY => fuFalse
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package lila.pref
|
||||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
import lila.user.User
|
||||
|
||||
case class Pref(
|
||||
_id: String, // user id
|
||||
bg: Int,
|
||||
|
@ -413,11 +417,18 @@ object Pref {
|
|||
object Zen extends BooleanPref {}
|
||||
object Ratings extends BooleanPref {}
|
||||
|
||||
def create(id: String) = default.copy(_id = id)
|
||||
val darkByDefaultSince = new DateTime(2021, 11, 7, 8, 0)
|
||||
|
||||
def create(id: User.ID) = default.copy(_id = id)
|
||||
|
||||
def create(user: User) = default.copy(
|
||||
_id = user.id,
|
||||
bg = if (user.createdAt isAfter darkByDefaultSince) Bg.DARK else Bg.LIGHT
|
||||
)
|
||||
|
||||
lazy val default = Pref(
|
||||
_id = "",
|
||||
bg = Bg.LIGHT,
|
||||
bg = Bg.DARK,
|
||||
bgImg = none,
|
||||
is3d = false,
|
||||
theme = Theme.default.name,
|
||||
|
|
|
@ -37,13 +37,16 @@ final class PrefApi(
|
|||
.void >>- { cache invalidate user.id }
|
||||
} >>- { cache invalidate user.id }
|
||||
|
||||
def getPrefById(id: User.ID): Fu[Pref] = cache get id dmap (_ getOrElse Pref.create(id))
|
||||
val getPref = getPrefById _
|
||||
def getPref(user: User): Fu[Pref] = getPref(user.id)
|
||||
def getPref(user: Option[User]): Fu[Pref] = user.fold(fuccess(Pref.default))(getPref)
|
||||
def getPrefById(id: User.ID): Fu[Option[Pref]] = cache get id
|
||||
|
||||
def getPref[A](user: User, pref: Pref => A): Fu[A] = getPref(user) dmap pref
|
||||
def getPref[A](userId: User.ID, pref: Pref => A): Fu[A] = getPref(userId) dmap pref
|
||||
def getPref(user: User): Fu[Pref] = cache get user.id dmap {
|
||||
_ getOrElse Pref.create(user)
|
||||
}
|
||||
|
||||
def getPref[A](user: User, pref: Pref => A): Fu[A] = getPref(user) dmap pref
|
||||
|
||||
def getPref[A](userId: User.ID, pref: Pref => A): Fu[A] =
|
||||
getPrefById(userId).dmap(p => pref(p | Pref.default))
|
||||
|
||||
def getPref(user: User, req: RequestHeader): Fu[Pref] =
|
||||
getPref(user) dmap RequestPref.queryParamOverride(req)
|
||||
|
@ -81,9 +84,6 @@ final class PrefApi(
|
|||
def setPref(user: User, change: Pref => Pref): Funit =
|
||||
getPref(user) map change flatMap setPref
|
||||
|
||||
def setPref(userId: User.ID, change: Pref => Pref): Funit =
|
||||
getPref(userId) map change flatMap setPref
|
||||
|
||||
def setPrefString(user: User, name: String, value: String): Funit =
|
||||
getPref(user) map { _.set(name, value) } orFail
|
||||
s"Bad pref ${user.id} $name -> $value" flatMap setPref
|
||||
|
|
|
@ -22,9 +22,9 @@ final private[round] class Drawer(
|
|||
import Pref.PrefZero
|
||||
if (game.playerHasOfferedDrawRecently(pov.color)) fuccess(pov.some)
|
||||
else
|
||||
pov.player.userId ?? prefApi.getPref map { pref =>
|
||||
pref.autoThreefold == Pref.AutoThreefold.ALWAYS || {
|
||||
pref.autoThreefold == Pref.AutoThreefold.TIME &&
|
||||
pov.player.userId ?? { uid => prefApi.getPref(uid, _.autoThreefold) } map { autoThreefold =>
|
||||
autoThreefold == Pref.AutoThreefold.ALWAYS || {
|
||||
autoThreefold == Pref.AutoThreefold.TIME &&
|
||||
game.clock ?? { _.remainingTime(pov.color) < Centis.ofSeconds(30) }
|
||||
} || pov.player.userId.exists(isBotSync)
|
||||
} map (_ option pov)
|
||||
|
|
Loading…
Reference in New Issue