deal with player/spectator/analyse trolls

This commit is contained in:
Thibault Duplessis 2014-02-01 10:19:47 +01:00
parent 9cd0660a5a
commit a9f3af138f
5 changed files with 15 additions and 12 deletions

View file

@ -39,7 +39,7 @@ object Analyse extends LilaController {
(env.analyser get pov.game.id) zip
(pov.game.tournamentId ?? TournamentRepo.byId) zip
(ctx.isAuth ?? {
Env.chat.api.userChat find s"${pov.gameId}/w" map (_.some)
Env.chat.api.userChat find s"${pov.gameId}/w" map (_.forUser(ctx.me).some)
}) map {
case (((((version, bookmarkers), pgn), analysis), tour), chat)
html.analyse.replay(

View file

@ -48,7 +48,7 @@ object Round extends LilaController with TheftPrevention {
pov.opponent.userId.??(UserRepo.isEngine) zip
(analyser has pov.gameId) zip
(pov.game.tournamentId ?? TournamentRepo.byId) zip
(Env.chat.api.playerChat find pov.gameId) map {
(Env.chat.api.playerChat find pov.gameId map (_ forUser ctx.me)) map {
case (((((v, bookmarkers), engine), analysed), tour), chat)
Ok(html.round.player(pov, v, engine, bookmarkers, analysed, chat = chat, tour = tour))
}
@ -70,7 +70,7 @@ object Round extends LilaController with TheftPrevention {
(analyser has pov.gameId) zip
(pov.game.tournamentId ?? TournamentRepo.byId) zip
(ctx.isAuth ?? {
Env.chat.api.userChat find s"${pov.gameId}/w" map (_.some)
Env.chat.api.userChat find s"${pov.gameId}/w" map (_.forUser(ctx.me).some)
}) map {
case ((((bookmarkers, v), analysed), tour), chat)
Ok(html.round.watcher(pov, v, bookmarkers, analysed, chat, tour))

View file

@ -191,8 +191,6 @@ object Tournament extends LilaController {
private def chatOf(tour: lila.tournament.Tournament)(implicit ctx: Context) =
ctx.isAuth ?? {
Env.chat.api.userChat find tour.id map { chat
ctx.troll.fold(chat, chat.filterTroll).some
}
Env.chat.api.userChat find tour.id map (_.forUser(ctx.me).some)
}
}

View file

@ -1,10 +1,12 @@
package lila.chat
import lila.user.User
sealed trait AnyChat {
def id: ChatId
def lines: List[Line]
def filterTroll: AnyChat
def forUser(u: Option[User]): AnyChat
def toJsonString = Line toJsonString lines
}
@ -18,17 +20,19 @@ case class UserChat(
id: ChatId,
lines: List[UserLine]) extends Chat[UserLine] {
def filterTroll = copy(lines = lines filterNot (_.troll))
def forUser(u: Option[User]) = u.??(_.troll).fold(this,
copy(lines = lines filterNot (_.troll)))
}
case class MixedChat(
id: ChatId,
lines: List[Line]) extends Chat[Line] {
def filterTroll = copy(lines = lines filter {
case l: UserLine !l.troll
case l: PlayerLine true
})
def forUser(u: Option[User]) = u.??(_.troll).fold(this,
copy(lines = lines filter {
case l: UserLine !l.troll
case l: PlayerLine true
}))
}
object Chat {

View file

@ -1614,6 +1614,7 @@ var storage = {
return '<li class="' + (sys ? 'system trans_me' : '') + (msg.r ? ' troll' : '') + '">' + user + urlToLink(msg.t) + '</li>';
},
_appendHtml: function(html) {
if (!html) return;
this.$msgs.append(html);
$('body').trigger('lichess.content_loaded');
this.$msgs.scrollTop(999999);