<commit_before>package controllers

import play.api.mvc._
import views._

import lila.api.Context
import lila.app._
import lila.streamer.{ Streamer => StreamerModel, StreamerForm }

final class Streamer(
    env: Env,
    apiC: => Api
) extends LilaController(env) {

  private def api = env.streamer.api

  def index(page: Int) =
    Open { implicit ctx =>
      ctx.noKid ?? {
        pageHit
        val requests = getBool("requests") && isGranted(_.Streamers)
        for {
          liveStreams <- env.streamer.liveStreamApi.all
          live        <- api withUsers liveStreams
          pager       <- env.streamer.pager.notLive(page, liveStreams, requests)
        } yield Ok(html.streamer.index(live, pager, requests))
      }
    }

  def live =
    apiC.ApiRequest { _ =>
      env.user.lightUserApi asyncMany env.streamer.liveStreamApi.userIds.toList dmap (_.flatten) map {
        users =>
          apiC.toApiResult {
            users.map { u =>
              lila.common.LightUser.lightUserWrites.writes(u)
            }
          }<commit_msg>Mobile home page streamer api<commit_after>package controllers

import play.api.mvc._
import views._

import lila.api.Context
import play.api.libs.json._
import lila.app._
import lila.streamer.{ Streamer => StreamerModel, StreamerForm }

final class Streamer(
    env: Env,
    apiC: => Api
) extends LilaController(env) {

  private def api = env.streamer.api

  def index(page: Int) =
    Open { implicit ctx =>
      ctx.noKid ?? {
        pageHit
        val requests = getBool("requests") && isGranted(_.Streamers)
        for {
          liveStreams <- env.streamer.liveStreamApi.all
          live        <- api withUsers liveStreams
          pager       <- env.streamer.pager.notLive(page, liveStreams, requests)
        } yield Ok(html.streamer.index(live, pager, requests))
      }
    }

  def featured =
    Open { implicit ctx =>
      negotiate(
        html = notFound,
        api = _ =>
          ctx.noKid ?? {
            env.streamer.liveStreamApi.all
              .map { streams =>
                val max      = env.streamer.homepageMaxSetting.get()
                val featured = streams.homepage(max, ctx.req, ctx.me) withTitles env.user.lightUserApi
                Ok(
                  Json.toJson(
                    featured.live.streams.map(s =>
                      Json.obj(
                        "link"              -> routes.Streamer.redirect(s.streamer.id.value).absoluteURL(),
                        "usernameWithTitle" -> featured.titleName(s),
                        "status"            -> s.status
                      )
                    )
                  )
                )
              }
          }
      )
    }

  def live =
    apiC.ApiRequest { _ =>
      env.user.lightUserApi asyncMany env.streamer.liveStreamApi.userIds.toList dmap (_.flatten) map {
        users =>
          apiC.toApiResult {
            users.map { u =>
              lila.common.LightUser.lightUserWrites.writes(u)
            }
          }
{'fraction_non_alphanumeric': 0.10204081632653061, 'fraction_numerical': 0.0, 'mean_word_length': 1.6657894736842105, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 22, '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': '5692291', 'n_tokens_mistral': 917, 'n_tokens_neox': 887, 'n_words': 177}