show last played game in idle user TV - resolves #150
This commit is contained in:
parent
89cb63807f
commit
744174fbfd
|
@ -23,7 +23,7 @@ object User extends LilaController {
|
||||||
|
|
||||||
def tv(username: String) = Open { implicit ctx =>
|
def tv(username: String) = Open { implicit ctx =>
|
||||||
OptionFuResult(UserRepo named username) { user =>
|
OptionFuResult(UserRepo named username) { user =>
|
||||||
(GameRepo lastPlayed user) orElse
|
(GameRepo lastPlayedPlaying user) orElse
|
||||||
(GameRepo lastPlayed user) flatMap {
|
(GameRepo lastPlayed user) flatMap {
|
||||||
_.fold(fuccess(Redirect(routes.User.show(username)))) { pov =>
|
_.fold(fuccess(Redirect(routes.User.show(username)))) { pov =>
|
||||||
Round.watch(pov, userTv = user.some)
|
Round.watch(pov, userTv = user.some)
|
||||||
|
@ -38,7 +38,7 @@ object User extends LilaController {
|
||||||
|
|
||||||
def showMini(username: String) = Open { implicit ctx =>
|
def showMini(username: String) = Open { implicit ctx =>
|
||||||
OptionFuResult(UserRepo named username) { user =>
|
OptionFuResult(UserRepo named username) { user =>
|
||||||
GameRepo lastPlayed user zip
|
GameRepo lastPlayedPlaying user zip
|
||||||
(ctx.userId ?? { relationApi.blocks(user.id, _) }) zip
|
(ctx.userId ?? { relationApi.blocks(user.id, _) }) zip
|
||||||
(ctx.isAuth ?? { Env.pref.api.followable(user.id) }) zip
|
(ctx.isAuth ?? { Env.pref.api.followable(user.id) }) zip
|
||||||
(ctx.userId ?? { relationApi.relation(_, user.id) }) map {
|
(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 {
|
def one(username: String, token: Option[String]): Fu[Option[JsObject]] = UserRepo named username flatMap {
|
||||||
case None => fuccess(none)
|
case None => fuccess(none)
|
||||||
case Some(u) => GameRepo lastPlayed u zip
|
case Some(u) => GameRepo lastPlayedPlaying u zip
|
||||||
makeUrl(R User username) zip
|
makeUrl(R User username) zip
|
||||||
(check(token) ?? (knownEnginesSharingIp(u.id) map (_.some))) flatMap {
|
(check(token) ?? (knownEnginesSharingIp(u.id) map (_.some))) flatMap {
|
||||||
case ((gameOption, userUrl), knownEngines) => gameOption ?? { g =>
|
case ((gameOption, userUrl), knownEngines) => gameOption ?? { g =>
|
||||||
|
|
|
@ -125,12 +125,17 @@ object GameRepo {
|
||||||
// gets most urgent game to play
|
// gets most urgent game to play
|
||||||
def onePlaying(user: User): Fu[Option[Pov]] = nowPlaying(user) map (_.headOption)
|
def onePlaying(user: User): Fu[Option[Pov]] = nowPlaying(user) map (_.headOption)
|
||||||
|
|
||||||
// gets last recently played move game
|
// gets last recently played move game in progress
|
||||||
def lastPlayed(user: User): Fu[Option[Pov]] =
|
def lastPlayedPlaying(user: User): Fu[Option[Pov]] =
|
||||||
$find.one($query(Query recentlyPlayingWithClock user.id) sort Query.sortUpdatedNoIndex) map {
|
$find.one($query(Query recentlyPlayingWithClock user.id) sort Query.sortUpdatedNoIndex) map {
|
||||||
_ flatMap { Pov(_, user) }
|
_ flatMap { Pov(_, user) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def lastPlayed(user: User): Fu[Option[Pov]] =
|
||||||
|
$find($query(Query user user.id) sort ($sort desc F.createdAt), 20) map {
|
||||||
|
_.sortBy(_.updatedAt).lastOption flatMap { Pov(_, user) }
|
||||||
|
}
|
||||||
|
|
||||||
def countPlayingRealTime(userId: String): Fu[Int] =
|
def countPlayingRealTime(userId: String): Fu[Int] =
|
||||||
$count(Query.nowPlaying(userId) ++ Query.clock(true))
|
$count(Query.nowPlaying(userId) ++ Query.clock(true))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue