display streamer titles on homepage

This commit is contained in:
Thibault Duplessis 2018-01-13 10:42:30 -05:00
parent 4d7b87d826
commit 255862813b
9 changed files with 32 additions and 12 deletions

View file

@ -23,7 +23,7 @@ private[app] final class Renderer extends Actor {
case lila.puzzle.RenderDaily(puzzle, fen, lastMove) =>
sender ! spaceless(V.puzzle.daily(puzzle, fen, lastMove))
case streams: lila.streamer.LiveStreams => sender ! V.streamer.liveStreams(streams)
case streams: lila.streamer.LiveStreams.WithTitles => sender ! V.streamer.liveStreams(streams)
}
private val spaceRegex = """\s{2,}""".r

View file

@ -28,7 +28,7 @@ final class Preload(
lightUserApi: LightUserApi
) {
private type Response = (JsObject, Vector[Entry], List[MiniForumPost], List[Tournament], List[Event], List[Simul], Option[Game], List[User.LightPerf], List[Winner], Option[lila.puzzle.DailyPuzzle], LiveStreams, List[lila.blog.MiniPost], Option[TempBan], Option[Preload.CurrentGame], Int)
private type Response = (JsObject, Vector[Entry], List[MiniForumPost], List[Tournament], List[Event], List[Simul], Option[Game], List[User.LightPerf], List[Winner], Option[lila.puzzle.DailyPuzzle], LiveStreams.WithTitles, List[lila.blog.MiniPost], Option[TempBan], Option[Preload.CurrentGame], Int)
def apply(
posts: Fu[List[MiniForumPost]],
@ -46,7 +46,7 @@ final class Preload(
leaderboard(()) zip
tourneyWinners zip
dailyPuzzle() zip
liveStreams().dmap(_.autoFeatured) zip
liveStreams().dmap(_.autoFeatured.withTitles(lightUserApi)) zip
(ctx.userId ?? getPlayban) flatMap {
case (data, povs) ~ posts ~ tours ~ events ~ simuls ~ feat ~ entries ~ lead ~ tWinners ~ puzzle ~ streams ~ playban =>
val currentGame = ctx.me ?? Preload.currentGame(povs, lightUserApi.sync) _

View file

@ -1,4 +1,4 @@
@(data: play.api.libs.json.JsObject, userTimeline: Vector[lila.timeline.Entry], forumRecent: List[lila.forum.MiniForumPost], tours: List[Tournament], events: List[lila.event.Event], simuls: List[lila.simul.Simul], featured: Option[Game], leaderboard: List[User.LightPerf], tournamentWinners: List[lila.tournament.Winner], puzzle: Option[lila.puzzle.DailyPuzzle], streams: lila.streamer.LiveStreams, lastPost: List[lila.blog.MiniPost], playban: Option[lila.playban.TempBan], currentGame: Option[lila.app.mashup.Preload.CurrentGame], nbRounds: Int)(implicit ctx: Context)
@(data: play.api.libs.json.JsObject, userTimeline: Vector[lila.timeline.Entry], forumRecent: List[lila.forum.MiniForumPost], tours: List[Tournament], events: List[lila.event.Event], simuls: List[lila.simul.Simul], featured: Option[Game], leaderboard: List[User.LightPerf], tournamentWinners: List[lila.tournament.Winner], puzzle: Option[lila.puzzle.DailyPuzzle], streams: lila.streamer.LiveStreams.WithTitles, lastPost: List[lila.blog.MiniPost], playban: Option[lila.playban.TempBan], currentGame: Option[lila.app.mashup.Preload.CurrentGame], nbRounds: Int)(implicit ctx: Context)
@import play.api.libs.json.Json

View file

@ -1,6 +1,6 @@
@(live: lila.streamer.LiveStreams)
@live.streams.map { s =>
@(l: lila.streamer.LiveStreams.WithTitles)
@l.live.streams.map { s =>
<a class="stream highlight" href="@routes.Streamer.show(s.streamer.id.value)" title="@s.status">
<span class="text" data-icon="">@s.streamer.name.value</span> @s.status
<span class="text" data-icon="">@l.titleName(s)</span> @s.status
</a>
}

View file

@ -50,7 +50,7 @@ method:'post'
}
}
@title = @{ s"${s.user.title.fold("")(_ + " ")}${s.streamer.name} streams chess" }
@title = @{ s"${s.titleName} streams chess" }
@base.layout(title = title,
side = side.some,

View file

@ -10,6 +10,7 @@ final class Env(
isOnline: lila.user.User.ID => Boolean,
asyncCache: lila.memo.AsyncCache.Builder,
notifyApi: lila.notify.NotifyApi,
lightUserApi: lila.user.LightUserApi,
hub: lila.hub.Env,
db: lila.db.Env
) {
@ -45,7 +46,8 @@ final class Env(
timeline = hub.actor.timeline,
keyword = Stream.Keyword(Keyword),
googleApiKey = GoogleApiKey,
twitchClientId = TwitchClientId
twitchClientId = TwitchClientId,
lightUserApi = lightUserApi
)))
lazy val liveStreamApi = new LiveStreamApi(asyncCache, streamingActor)
@ -68,6 +70,7 @@ object Env {
isOnline = lila.user.Env.current.isOnline,
asyncCache = lila.memo.Env.current.asyncCache,
notifyApi = lila.notify.Env.current.api,
lightUserApi = lila.user.Env.current.lightUserApi,
hub = lila.hub.Env.current,
db = lila.db.Env.current
)

View file

@ -16,6 +16,19 @@ case class LiveStreams(streams: List[Stream]) {
def autoFeatured = LiveStreams {
streams.filter(_.streamer.approval.autoFeatured)
}
def withTitles(lightUser: lila.user.LightUserApi) = LiveStreams.WithTitles(
this,
streams.map(_.streamer.userId).map { userId =>
userId -> lightUser.sync(userId).flatMap(_.title)
}.toMap
)
}
object LiveStreams {
case class WithTitles(live: LiveStreams, titles: Map[User.ID, Option[String]]) {
def titleName(s: Stream) = s"${titles.get(s.streamer.userId).fold("")(_ + " ")}${s.streamer.name}"
}
}
final class LiveStreamApi(

View file

@ -102,8 +102,11 @@ object Streamer {
}
}
case class WithUser(streamer: Streamer, user: User)
case class WithUser(streamer: Streamer, user: User) {
def titleName = s"${user.title.fold("")(_ + " ")}${streamer.name}"
}
case class WithUserAndStream(streamer: Streamer, user: User, stream: Option[Stream]) {
def withoutStream = WithUser(streamer, user)
def titleName = withoutStream.titleName
}
}

View file

@ -17,7 +17,8 @@ private final class Streaming(
timeline: ActorSelection,
keyword: Stream.Keyword,
googleApiKey: String,
twitchClientId: String
twitchClientId: String,
lightUserApi: lila.user.LightUserApi
) extends Actor {
import Stream._
@ -59,7 +60,7 @@ private final class Streaming(
import makeTimeout.short
import akka.pattern.ask
if (newStreams != liveStreams) {
renderer ? newStreams.autoFeatured foreach {
renderer ? newStreams.autoFeatured.withTitles(lightUserApi) foreach {
case html: play.twirl.api.Html =>
context.system.lilaBus.publish(lila.hub.actorApi.StreamsOnAir(html.body), 'streams)
}