<commit_before>package lila.api

import play.api.libs.json._

import lila.common.paginator.{ Paginator, PaginatorJson }
import lila.game.GameRepo
import lila.user.{ UserRepo, User }

private[api] final class UserApi(
    jsonView: lila.user.JsonView,
    relationApi: lila.relation.RelationApi,
    bookmarkApi: lila.bookmark.BookmarkApi,
    crosstableApi: lila.game.CrosstableApi,
    gameCache: lila.game.Cached,
    prefApi: lila.pref.PrefApi,
    makeUrl: String => String
) {

  def pager(pag: Paginator[User]): JsObject =
    Json.obj("paginator" -> PaginatorJson(pag.mapResults { u =>
      jsonView(u) ++ Json.obj("url" -> makeUrl(s"@/${u.username}"))
    }))

  def one(username: String)(implicit ctx: Context): Fu[Option[JsObject]] = UserRepo named username flatMap {
    case None => fuccess(none)
    case Some(u) => GameRepo mostUrgentGame u zip
      (ctx.me.filter(u!=) ?? { me => crosstableApi.nbGames(me.id, u.id) }) zip
      relationApi.countFollowing(u.id) zip
      relationApi.countFollowers(u.id) zip
      ctx.isAuth.?? { prefApi followable u.id } zip
      ctx.userId.?? { relationApi.fetchRelation(_, u.id) } zip
      ctx.userId.?? { relationApi.fetchFollows(u.id, _) } zip
      bookmarkApi.countByUser(u) zip
      gameCache.nbPlaying(u.id) zip
      gameCache.nbImportedBy(u.id) map {
        case gameOption ~ nbGamesWithMe ~ following ~ followers ~ followable ~ relation ~ isFollowed ~ nbBookmarks ~ nbPlaying ~ nbImported =>
          jsonView(u) ++ {
            Json.obj(
              "url" -> makeUrl(s"@/$username"),
              "playing" -> gameOption.map(g => makeUrl(s"${g.gameId}/${g.color.name}")),
              "nbFollowing" -> following,
              "nbFollowers" -> followers,
              "count" -> Json.obj(
                "all" -> u.count.game,
                "rated" -> u.count.rated,
                "ai" -> u.count.ai,
                "draw" -> u.count.draw,
                "drawH" -> u.count.drawH,
                "loss" -> u.count.loss,
                "lossH" -> u.count.lossH,
                "win" -> u.count.win,
                "winH" -> u.count.winH,
                "bookmark" -> nbBookmarks,
                "playing" -> nbPlaying,
                "import" -> nbImported,
                "me" -> nbGamesWithMe
              )
            ) ++ ctx.isAuth.??(Json.obj(
                "followable" -> followable,
                "following" -> relation.has(true),
                "blocking" -> relation.has(false),
                "followsYou" -> isFollowed
              ))
          }.noNull
      } map (_.some)
  }
}
<commit_msg>return less user info when account is disabled<commit_after>package lila.api

import play.api.libs.json._

import lila.common.paginator.{ Paginator, PaginatorJson }
import lila.game.GameRepo
import lila.user.{ UserRepo, User }

private[api] final class UserApi(
    jsonView: lila.user.JsonView,
    relationApi: lila.relation.RelationApi,
    bookmarkApi: lila.bookmark.BookmarkApi,
    crosstableApi: lila.game.CrosstableApi,
    gameCache: lila.game.Cached,
    prefApi: lila.pref.PrefApi,
    makeUrl: String => String
) {

  def pager(pag: Paginator[User]): JsObject =
    Json.obj("paginator" -> PaginatorJson(pag.mapResults { u =>
      jsonView(u) ++ Json.obj("url" -> makeUrl(s"@/${u.username}"))
    }))

  def one(username: String)(implicit ctx: Context): Fu[Option[JsObject]] = UserRepo named username flatMap {
    case None => fuccess(none)
    case Some(u) if u.disabled => fuccess {
      Json.obj(
        "id" -> u.id,
        "username" -> u.username,
        "closed" -> true
      ).some
    }
    case Some(u) => GameRepo mostUrgentGame u zip
      (ctx.me.filter(u!=) ?? { me => crosstableApi.nbGames(me.id, u.id) }) zip
      relationApi.countFollowing(u.id) zip
      relationApi.countFollowers(u.id) zip
      ctx.isAuth.?? { prefApi followable u.id } zip
      ctx.userId.?? { relationApi.fetchRelation(_, u.id) } zip
      ctx.userId.?? { relationApi.fetchFollows(u.id, _) } zip
      bookmarkApi.countByUser(u) zip
      gameCache.nbPlaying(u.id) zip
      gameCache.nbImportedBy(u.id) map {
        case gameOption ~ nbGamesWithMe ~ following ~ followers ~ followable ~ relation ~ isFollowed ~ nbBookmarks ~ nbPlaying ~ nbImported =>
          jsonView(u) ++ {
            Json.obj(
              "url" -> makeUrl(s"@/$username"),
              "playing" -> gameOption.map(g => makeUrl(s"${g.gameId}/${g.color.name}")),
              "nbFollowing" -> following,
              "nbFollowers" -> followers,
              "count" -> Json.obj(
                "all" -> u.count.game,
                "rated" -> u.count.rated,
                "ai" -> u.count.ai,
                "draw" -> u.count.draw,
                "drawH" -> u.count.drawH,
                "loss" -> u.count.loss,
                "lossH" -> u.count.lossH,
                "win" -> u.count.win,
                "winH" -> u.count.winH,
                "bookmark" -> nbBookmarks,
                "playing" -> nbPlaying,
                "import" -> nbImported,
                "me" -> nbGamesWithMe
              )
            ) ++ ctx.isAuth.??(Json.obj(
                "followable" -> followable,
                "following" -> relation.has(true),
                "blocking" -> relation.has(false),
                "followsYou" -> isFollowed
              ))
          }.noNull
      } map (_.some)
  }
}

{'fraction_non_alphanumeric': 0.1467703127891912, 'fraction_numerical': 0.0, 'mean_word_length': 1.9546200109349372, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5376326', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1756, 'n_words': 322}