improve current game detection
parent
01d16f6dfb
commit
5162d27e56
|
@ -23,8 +23,8 @@ object User extends LilaController {
|
|||
|
||||
def tv(username: String) = Open { implicit ctx =>
|
||||
OptionFuResult(UserRepo named username) { user =>
|
||||
(GameRepo onePlaying user) orElse
|
||||
(GameRepo lastPlayed user.id) flatMap {
|
||||
(GameRepo lastPlayed user) orElse
|
||||
(GameRepo lastPlayed user) flatMap {
|
||||
_.fold(fuccess(Redirect(routes.User.show(username)))) { pov =>
|
||||
Round.watch(pov, userTv = user.some)
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ object User extends LilaController {
|
|||
|
||||
def showMini(username: String) = Open { implicit ctx =>
|
||||
OptionFuResult(UserRepo named username) { user =>
|
||||
GameRepo onePlaying user zip
|
||||
GameRepo lastPlayed user zip
|
||||
(ctx.userId ?? { relationApi.blocks(user.id, _) }) zip
|
||||
(ctx.isAuth ?? { Env.pref.api.followable(user.id) }) zip
|
||||
(ctx.userId ?? { relationApi.relation(_, user.id) }) map {
|
||||
|
|
|
@ -41,7 +41,7 @@ private[api] final class UserApi(
|
|||
|
||||
def one(username: String, token: Option[String]): Fu[Option[JsObject]] = UserRepo named username flatMap {
|
||||
case None => fuccess(none)
|
||||
case Some(u) => GameRepo onePlaying u zip
|
||||
case Some(u) => GameRepo lastPlayed u zip
|
||||
makeUrl(R User username) zip
|
||||
(check(token) ?? (knownEnginesSharingIp(u.id) map (_.some))) flatMap {
|
||||
case ((gameOption, userUrl), knownEngines) => gameOption ?? { g =>
|
||||
|
|
|
@ -15,7 +15,7 @@ import lila.db.api._
|
|||
import lila.db.BSON.BSONJodaDateTimeHandler
|
||||
import lila.db.ByteArray
|
||||
import lila.db.Implicits._
|
||||
import lila.user.{User,UidNb}
|
||||
import lila.user.{ User, UidNb }
|
||||
|
||||
object GameRepo {
|
||||
|
||||
|
@ -122,8 +122,15 @@ object GameRepo {
|
|||
_ flatMap { Pov(_, user) } sortBy Pov.priority
|
||||
}
|
||||
|
||||
// gets most urgent game to play
|
||||
def onePlaying(user: User): Fu[Option[Pov]] = nowPlaying(user) map (_.headOption)
|
||||
|
||||
// gets last recently played move game
|
||||
def lastPlayed(user: User): Fu[Option[Pov]] =
|
||||
$find.one($query(Query nowPlayingWithClock user.id) sort Query.sortUpdatedNoIndex) map {
|
||||
_ flatMap { Pov(_, user) }
|
||||
}
|
||||
|
||||
def countPlayingRealTime(userId: String): Fu[Int] =
|
||||
$count(Query.nowPlaying(userId) ++ Query.clock(true))
|
||||
|
||||
|
@ -244,11 +251,6 @@ object GameRepo {
|
|||
$count(Json.obj(F.createdAt -> ($gte($date(from)) ++ $lt($date(to)))))
|
||||
}).sequenceFu
|
||||
|
||||
def lastPlayed(userId: String): Fu[Option[Pov]] =
|
||||
$find($query(Query user userId) sort ($sort desc F.createdAt), 1) map {
|
||||
_.headOption flatMap { Pov(_, userId) }
|
||||
}
|
||||
|
||||
def bestOpponents(userId: String, limit: Int): Fu[List[(String, Int)]] = {
|
||||
import reactivemongo.bson._
|
||||
import reactivemongo.core.commands._
|
||||
|
|
|
@ -49,6 +49,7 @@ object Query {
|
|||
def users(u: Seq[String]) = Json.obj(F.playerUids -> $in(u))
|
||||
|
||||
def nowPlaying(u: String) = Json.obj(F.playingUids -> u)
|
||||
def nowPlayingWithClock(u: String) = nowPlaying(u) ++ clock(true)
|
||||
|
||||
// use the us index
|
||||
def win(u: String) = user(u) ++ Json.obj(F.winnerId -> u)
|
||||
|
@ -65,4 +66,5 @@ object Query {
|
|||
def checkable = Json.obj(F.checkAt -> $lt($date(DateTime.now)))
|
||||
|
||||
val sortCreated = $sort desc F.createdAt
|
||||
val sortUpdatedNoIndex = $sort desc F.updatedAt
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue