show streamers with same channel

pull/8889/head
Thibault Duplessis 2021-01-07 16:37:07 +01:00
parent e51061553b
commit fdb5f25257
4 changed files with 49 additions and 8 deletions

View File

@ -67,17 +67,18 @@ final class Streamer(
}
}
private def modData(user: lila.user.User)(implicit ctx: Context) =
private def modData(streamer: StreamerModel)(implicit ctx: Context) =
isGranted(_.ModLog) ?? {
env.mod.logApi.userHistory(user.id) zip
env.user.noteApi.forMod(user.id) map some
env.mod.logApi.userHistory(streamer.userId) zip
env.user.noteApi.forMod(streamer.userId) zip
env.streamer.api.sameChannels(streamer) map some
}
def edit =
Auth { implicit ctx => _ =>
AsStreamer { s =>
env.streamer.liveStreamApi of s flatMap { sws =>
modData(s.user) map { forMod =>
modData(s.streamer) map { forMod =>
NoCache(Ok(html.streamer.edit(sws, StreamerForm userForm sws.streamer, forMod)))
}
}
@ -94,7 +95,7 @@ final class Streamer(
.bindFromRequest()
.fold(
error =>
modData(s.user) map { forMod =>
modData(s.streamer) map { forMod =>
BadRequest(html.streamer.edit(sws, error, forMod))
},
data =>

View File

@ -15,7 +15,7 @@ object edit extends Context.ToLang {
def apply(
s: lila.streamer.Streamer.WithUserAndStream,
form: Form[_],
modData: Option[(List[lila.mod.Modlog], List[lila.user.Note])]
modData: Option[((List[lila.mod.Modlog], List[lila.user.Note]), List[lila.streamer.Streamer])]
)(implicit ctx: Context) = {
views.html.base.layout(
@ -87,7 +87,7 @@ object edit extends Context.ToLang {
)
)
),
modData.map { case (log, notes) =>
modData.map { case ((log, notes), same) =>
div(cls := "mod_log status")(
strong(cls := "text", dataIcon := "!")(
"Moderation history",
@ -118,6 +118,26 @@ object edit extends Context.ToLang {
p(cls := "text")(richText(note.text))
)
}
),
br,
strong(cls := "text", dataIcon := "!")(
"Streamers with same Twitch or YouTube",
same.isEmpty option ": nothing to show."
),
same.nonEmpty option table(cls := "slist")(
same.map { s =>
tr(
td(userIdLink(s.userId.some)),
td(s.name),
td(s.twitch.map(t => a(href := s"https://twitch.tv/${t.userId}")(t.userId))),
td(
s.youTube.map(t =>
a(href := s"https://youtube.com/channel/${t.channelId}")(t.channelId)
)
),
td(momentFromNow(s.createdAt))
)
}
)
)
},

View File

@ -1,7 +1,7 @@
package lila.streamer
import org.joda.time.DateTime
import reactivemongo.api.ReadPreference
import scala.concurrent.duration._
import lila.db.dsl._
@ -155,6 +155,25 @@ final class StreamerApi(
)
}
def sameChannels(streamer: Streamer): Fu[List[Streamer]] =
coll
.find(
$doc(
"$or" -> List(
streamer.twitch.map(_.userId).map { t =>
$doc("twitch.userId" -> t)
},
streamer.youTube.map(_.channelId).map { t =>
$doc("youTube.channelId" -> t)
}
).flatten,
"_id" $ne streamer.userId
)
)
.sort($sort desc "createdAt")
.cursor[Streamer](readPreference = ReadPreference.secondaryPreferred)
.list(10)
private object cache {
private def selectListedApproved =

View File

@ -1,3 +1,4 @@
@import "../../../common/css/plugin";
@import "../../../common/css/form/form3";
@import "../../../common/css/component/slist";
@import "../streamer/form";