From ea50250393033f7485a344d7eb39c684a62603f9 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sat, 1 Feb 2014 10:05:27 +0100 Subject: [PATCH] deal with tournament trolls --- app/controllers/Tournament.scala | 6 +++++- modules/chat/src/main/Chat.scala | 9 +++++++++ modules/socket/src/main/Historical.scala | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/Tournament.scala b/app/controllers/Tournament.scala index af1ef6389d..5f22b25383 100644 --- a/app/controllers/Tournament.scala +++ b/app/controllers/Tournament.scala @@ -190,5 +190,9 @@ object Tournament extends LilaController { } private def chatOf(tour: lila.tournament.Tournament)(implicit ctx: Context) = - ctx.isAuth ?? (Env.chat.api.userChat find tour.id map (_.some)) + ctx.isAuth ?? { + Env.chat.api.userChat find tour.id map { chat ⇒ + ctx.troll.fold(chat, chat.filterTroll).some + } + } } diff --git a/modules/chat/src/main/Chat.scala b/modules/chat/src/main/Chat.scala index d2f0262265..154362a51e 100644 --- a/modules/chat/src/main/Chat.scala +++ b/modules/chat/src/main/Chat.scala @@ -4,6 +4,8 @@ sealed trait AnyChat { def id: ChatId def lines: List[Line] + def filterTroll: AnyChat + def toJsonString = Line toJsonString lines } @@ -15,11 +17,18 @@ sealed trait Chat[L <: Line] extends AnyChat { case class UserChat( id: ChatId, lines: List[UserLine]) extends Chat[UserLine] { + + def filterTroll = 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 + }) } object Chat { diff --git a/modules/socket/src/main/Historical.scala b/modules/socket/src/main/Historical.scala index 7859ac180a..8b844f0f96 100644 --- a/modules/socket/src/main/Historical.scala +++ b/modules/socket/src/main/Historical.scala @@ -12,7 +12,7 @@ trait Historical[M <: SocketMember] { self: SocketActor[M] ⇒ } def sendMessage(message: History.Message)(member: M) { - if (!message.troll || member.troll) member.channel push message.msg.pp + if (!message.troll || member.troll) member.channel push message.msg } def sendMessage(member: M)(message: History.Message) { sendMessage(message)(member)