private tournaments conceal their chats to anon and logged in watchers

This commit is contained in:
Thibault Duplessis 2019-05-03 09:23:56 +07:00
parent 4efe4c19af
commit 78c35a596f
3 changed files with 8 additions and 6 deletions

View file

@ -222,7 +222,7 @@ object Round extends LilaController with TheftPrevention {
private[controllers] def getPlayerChat(game: GameModel, tour: Option[Tour])(implicit ctx: Context): Fu[Option[Chat.GameOrEvent]] = ctx.noKid ?? {
(game.tournamentId, game.simulId) match {
case (Some(tid), _) => {
ctx.isAuth && tour.fold(true)(Tournament.canHaveChat)
ctx.isAuth && tour.fold(true)(Tournament.canHaveChat(_, none))
} ??
Env.chat.api.userChat.cached.findMine(Chat.Id(tid), ctx.me).map { chat =>
Chat.GameOrEvent(Right(chat truncate 50)).some

View file

@ -74,13 +74,15 @@ object Tournament extends LilaController {
} yield Ok(html.tournament.leaderboard(winners))
}
private[controllers] def canHaveChat(tour: Tour)(implicit ctx: Context): Boolean =
private[controllers] def canHaveChat(tour: Tour, json: Option[JsObject])(implicit ctx: Context): Boolean =
!ctx.kid && // no public chats for kids
ctx.me.fold(true) { u => // anon can see public chats
tour.isPrivate || // private tournament pages can only be accessed by invited players (or can it?)
ctx.me.fold(!tour.isPrivate) { u => // anon can see public chats, except for private tournaments
(tour.isPrivate && json.fold(true)(jsonHasMe)) && // private tournament that I joined
Env.chat.panic.allowed(u, tighter = tour.variant == chess.variant.Antichess)
}
private def jsonHasMe(js: JsObject): Boolean = (js \ "me").toOption.isDefined
def show(id: String) = Open { implicit ctx =>
val page = getInt("page")
repo byId id flatMap { tourOption =>
@ -89,8 +91,8 @@ object Tournament extends LilaController {
(for {
verdicts <- env.api.verdicts(tour, ctx.me, getUserTeamIds)
version <- env.version(tour.id)
chat <- canHaveChat(tour) ?? Env.chat.api.userChat.cached.findMine(Chat.Id(tour.id), ctx.me).map(some)
json <- env.jsonView(tour, page, ctx.me, getUserTeamIds, none, version.some, partial = false, ctx.lang)
chat <- canHaveChat(tour, json.some) ?? Env.chat.api.userChat.cached.findMine(Chat.Id(tour.id), ctx.me).map(some)
_ <- chat ?? { c => Env.user.lightUserApi.preloadMany(c.chat.userIds) }
streamers <- streamerCache get tour.id
shieldOwner <- env.shieldApi currentOwner tour

View file

@ -35,6 +35,6 @@ export default function(ctrl: TournamentController) {
class: { 'tour__main-finished': ctrl.data.isFinished }
}, handler.main(ctrl))
),
h('div.chat__members.none', h('span.list'))
ctrl.opts.chat ? h('div.chat__members.none', h('span.list')) : null
]);
}