fetch chat light user at render time - WIP - DOOMED
parent
f2b7fa38d4
commit
4e3240ebc2
|
@ -401,7 +401,7 @@ final class Mod(
|
|||
Secure(_.ChatTimeout) { _ => _ =>
|
||||
implicit val lightUser = env.user.lightUserSync
|
||||
JsonOptionOk {
|
||||
env.chat.api.userChat userModInfo username map2 lila.chat.JsonView.userModInfo
|
||||
env.chat.api.userChat userModInfo username map2 env.chat.json.userModInfo
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ final class Round(
|
|||
env.api.roundApi.player(pov, tour, apiVersion) zip
|
||||
getPlayerChat(pov.game, none) map { case ((_, data), chat) =>
|
||||
Ok {
|
||||
data.add("chat", chat.flatMap(_.game).map(c => lila.chat.JsonView(c.chat)))
|
||||
data.add("chat", chat.flatMap(_.game).map(c => env.chat.json(c.chat)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ final class Round(
|
|||
chat <- getWatcherChat(pov.game)
|
||||
} yield Ok {
|
||||
data
|
||||
.add("chat" -> chat.map(c => lila.chat.JsonView(c.chat)))
|
||||
.add("chat" -> chat.map(c => env.chat.json(c.chat)))
|
||||
.add("analysis" -> analysis.map(a => lila.analyse.JsonView.mobile(pov.game, a)))
|
||||
}
|
||||
) map { NoCache(_) }
|
||||
|
|
|
@ -181,7 +181,7 @@ final class Study(
|
|||
Ok(
|
||||
Json.obj(
|
||||
"study" -> data.study.add("chat" -> chatOpt.map { c =>
|
||||
lila.chat.JsonView.mobile(
|
||||
env.chat.json.mobile(
|
||||
chat = c.chat,
|
||||
writeable = ctx.userId.??(sc.study.canChat)
|
||||
)
|
||||
|
|
|
@ -140,7 +140,7 @@ final class Tournament(
|
|||
)
|
||||
chat <- loadChat(tour, json)
|
||||
} yield Ok(json.add("chat" -> chat.map { c =>
|
||||
lila.chat.JsonView.mobile(chat = c.chat)
|
||||
env.chat.json.mobile(chat = c.chat)
|
||||
}))
|
||||
}
|
||||
.monSuccess(_.tournament.apiShowPartial(getBool("partial"), HTTPRequest clientName ctx.req))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lila.app
|
||||
package templating
|
||||
|
||||
import play.api.libs.json.JsValue
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
@ -44,6 +45,8 @@ object Environment
|
|||
|
||||
def isChatPanicEnabled = env.chat.panic.enabled
|
||||
|
||||
def chatLinesToJson(chat: lila.chat.AnyChat): JsValue = env.chat.json(chat)
|
||||
|
||||
def blockingReportScores: (Int, Int, Int) = (
|
||||
env.report.api.maxScores.dmap(_.highest).awaitOrElse(50.millis, "nbReports", 0),
|
||||
env.report.scoreThresholdsSetting.get().mid,
|
||||
|
|
|
@ -16,7 +16,7 @@ object chat {
|
|||
div(cls := "mchat__content")
|
||||
)
|
||||
|
||||
import lila.chat.JsonView.writers.chatIdWrites
|
||||
import lila.chat.JsonView.chatIdWrites
|
||||
|
||||
def restrictedJson(
|
||||
chat: lila.chat.Chat.Restricted,
|
||||
|
@ -60,7 +60,7 @@ object chat {
|
|||
.obj(
|
||||
"id" -> chat.id,
|
||||
"name" -> name,
|
||||
"lines" -> lila.chat.JsonView(chat),
|
||||
"lines" -> chatLinesToJson(chat),
|
||||
"userId" -> ctx.userId,
|
||||
"resourceId" -> resourceId.value
|
||||
)
|
||||
|
|
|
@ -97,7 +97,7 @@ final class GameStateStream(
|
|||
|
||||
def receive = {
|
||||
case MoveGameEvent(g, _, _) if g.id == id && !g.finished => pushState(g).unit
|
||||
case lila.chat.actorApi.ChatLine(chatId, UserLine(username, _, text, false, false)) =>
|
||||
case lila.chat.actorApi.ChatLine(chatId, UserLine(username, text, false, false)) =>
|
||||
pushChatLine(username, text, chatId.value.lengthIs == Game.gameIdSize).unit
|
||||
case FinishGame(g, _, _) if g.id == id => onGameOver(g.some).unit
|
||||
case AbortedBy(pov) if pov.gameId == id => onGameOver(pov.game.some).unit
|
||||
|
|
|
@ -8,9 +8,7 @@ import lila.user.User
|
|||
|
||||
final class JsonView(lightUserSync: LightUser.GetterSync) {
|
||||
|
||||
import writers._
|
||||
|
||||
lazy val timeoutReasons = Json toJson ChatTimeout.Reason.all
|
||||
import JsonView._
|
||||
|
||||
def apply(chat: AnyChat): JsValue =
|
||||
chat match {
|
||||
|
@ -18,8 +16,6 @@ final class JsonView(lightUserSync: LightUser.GetterSync) {
|
|||
case c: UserChat => userChatWriter writes c
|
||||
}
|
||||
|
||||
def apply(line: Line): JsObject = lineWriter writes line
|
||||
|
||||
def userModInfo(u: UserModInfo)(implicit lightUser: LightUser.GetterSync) =
|
||||
lila.user.JsonView.modWrites.writes(u.user) ++ Json.obj(
|
||||
"history" -> u.history
|
||||
|
@ -31,55 +27,57 @@ final class JsonView(lightUserSync: LightUser.GetterSync) {
|
|||
"writeable" -> writeable
|
||||
)
|
||||
|
||||
object writers {
|
||||
implicit val mixedChatWriter: Writes[MixedChat] = Writes[MixedChat] { c =>
|
||||
JsArray(c.lines map lineWriter.writes)
|
||||
}
|
||||
|
||||
implicit val chatIdWrites: Writes[Chat.Id] = stringIsoWriter(Chat.chatIdIso)
|
||||
implicit val userChatWriter: Writes[UserChat] = Writes[UserChat] { c =>
|
||||
JsArray(c.lines map userLineWriter.writes)
|
||||
}
|
||||
|
||||
implicit val timeoutReasonWriter: Writes[ChatTimeout.Reason] = OWrites[ChatTimeout.Reason] { r =>
|
||||
Json.obj("key" -> r.key, "name" -> r.name)
|
||||
}
|
||||
implicit val lineWriter: OWrites[Line] = OWrites[Line] {
|
||||
case l: UserLine => userLineWriter writes l
|
||||
case l: PlayerLine => playerLineWriter writes l
|
||||
}
|
||||
|
||||
implicit def timeoutEntryWriter: OWrites[ChatTimeout.UserEntry] =
|
||||
OWrites[ChatTimeout.UserEntry] { e =>
|
||||
Json.obj(
|
||||
"reason" -> e.reason.key,
|
||||
"mod" -> lightUserSync(e.mod).fold("?")(_.name),
|
||||
"date" -> e.createdAt
|
||||
)
|
||||
}
|
||||
|
||||
implicit val mixedChatWriter: Writes[MixedChat] = Writes[MixedChat] { c =>
|
||||
JsArray(c.lines map lineWriter.writes)
|
||||
}
|
||||
|
||||
implicit val userChatWriter: Writes[UserChat] = Writes[UserChat] { c =>
|
||||
JsArray(c.lines map userLineWriter.writes)
|
||||
}
|
||||
|
||||
implicit private[chat] val lineWriter: OWrites[Line] = OWrites[Line] {
|
||||
case l: UserLine => userLineWriter writes l
|
||||
case l: PlayerLine => playerLineWriter writes l
|
||||
}
|
||||
|
||||
implicit private val userLineWriter = OWrites[UserLine] { l =>
|
||||
val userId = User normalize l.username
|
||||
val u = lightUserSync(userId) | LightUser.fallback(userId)
|
||||
Json
|
||||
.obj(
|
||||
"u" -> l.username,
|
||||
"t" -> l.text
|
||||
)
|
||||
.add("r" -> l.troll)
|
||||
.add("d" -> l.deleted)
|
||||
.add("title" -> u.title)
|
||||
.add("p" -> u.isPatron)
|
||||
}
|
||||
|
||||
implicit private val playerLineWriter = OWrites[PlayerLine] { l =>
|
||||
Json.obj(
|
||||
"c" -> l.color.name,
|
||||
implicit private val userLineWriter = OWrites[UserLine] { l =>
|
||||
val userId = User normalize l.username
|
||||
val u = lightUserSync(userId) | LightUser.fallback(userId)
|
||||
Json
|
||||
.obj(
|
||||
"u" -> l.username,
|
||||
"t" -> l.text
|
||||
)
|
||||
.add("r" -> l.troll)
|
||||
.add("d" -> l.deleted)
|
||||
.add("title" -> u.title)
|
||||
.add("p" -> u.isPatron)
|
||||
}
|
||||
|
||||
implicit def timeoutEntryWriter: OWrites[ChatTimeout.UserEntry] =
|
||||
OWrites[ChatTimeout.UserEntry] { e =>
|
||||
Json.obj(
|
||||
"reason" -> e.reason.key,
|
||||
"mod" -> lightUserSync(e.mod).fold("?")(_.name),
|
||||
"date" -> e.createdAt
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object JsonView {
|
||||
|
||||
lazy val timeoutReasons = Json toJson ChatTimeout.Reason.all
|
||||
|
||||
implicit val chatIdWrites: Writes[Chat.Id] = stringIsoWriter(Chat.chatIdIso)
|
||||
|
||||
implicit val timeoutReasonWriter: Writes[ChatTimeout.Reason] = OWrites[ChatTimeout.Reason] { r =>
|
||||
Json.obj("key" -> r.key, "name" -> r.name)
|
||||
}
|
||||
|
||||
implicit private val playerLineWriter = OWrites[PlayerLine] { l =>
|
||||
Json.obj(
|
||||
"c" -> l.color.name,
|
||||
"t" -> l.text
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -251,14 +251,14 @@ object Event {
|
|||
|
||||
case class PlayerMessage(line: PlayerLine) extends Event {
|
||||
def typ = "message"
|
||||
def data = lila.chat.JsonView(line)
|
||||
def data = JsNull
|
||||
override def owner = true
|
||||
override def troll = false
|
||||
}
|
||||
|
||||
case class UserMessage(line: UserLine, w: Boolean) extends Event {
|
||||
def typ = "message"
|
||||
def data = lila.chat.JsonView(line)
|
||||
def data = sys error "oh no what have I done"
|
||||
override def troll = line.troll
|
||||
override def watcher = w
|
||||
override def owner = !w
|
||||
|
|
|
@ -109,11 +109,15 @@ object RoomSocket {
|
|||
|
||||
private val chatMsgs = Set("message", "chat_timeout", "chat_reinstate")
|
||||
|
||||
def subscribeChat(rooms: TrouperMap[RoomState], busChan: BusChan.Select) = {
|
||||
def subscribeChat(
|
||||
rooms: TrouperMap[RoomState],
|
||||
busChan: BusChan.Select,
|
||||
chatLineWriter: OWrites[lila.chat.Line]
|
||||
) = {
|
||||
import lila.chat.actorApi._
|
||||
lila.common.Bus.subscribeFun(busChan(BusChan).chan, BusChan.Global.chan) {
|
||||
case ChatLine(id, line: UserLine) =>
|
||||
rooms.tellIfPresent(id.value, NotifyVersion("message", lila.chat.JsonView(line), line.troll))
|
||||
rooms.tellIfPresent(id.value, NotifyVersion("message", chatLineWriter writes line, line.troll))
|
||||
case OnTimeout(id, userId) =>
|
||||
rooms.tellIfPresent(id.value, NotifyVersion("chat_timeout", userId, troll = false))
|
||||
case OnReinstate(id, userId) =>
|
||||
|
|
|
@ -25,6 +25,7 @@ final class Env(
|
|||
renderer: lila.hub.actors.Renderer,
|
||||
timeline: lila.hub.actors.Timeline,
|
||||
chatApi: lila.chat.ChatApi,
|
||||
chatJson: lila.chat.JsonView,
|
||||
lightUser: lila.common.LightUser.Getter,
|
||||
onGameStart: lila.round.OnStart,
|
||||
cacheApi: lila.memo.CacheApi,
|
||||
|
|
|
@ -12,7 +12,8 @@ final private class SimulSocket(
|
|||
repo: SimulRepo,
|
||||
jsonView: JsonView,
|
||||
remoteSocketApi: lila.socket.RemoteSocket,
|
||||
chat: lila.chat.ChatApi
|
||||
chatApi: lila.chat.ChatApi,
|
||||
chatJson: lila.chat.JsonView
|
||||
)(implicit
|
||||
ec: scala.concurrent.ExecutionContext,
|
||||
mode: play.api.Mode
|
||||
|
@ -56,12 +57,12 @@ final private class SimulSocket(
|
|||
|
||||
lazy val rooms = makeRoomMap(send)
|
||||
|
||||
subscribeChat(rooms, _.Simul)
|
||||
subscribeChat(rooms, _.Simul, chatJson.lineWriter)
|
||||
|
||||
private lazy val handler: Handler =
|
||||
roomHandler(
|
||||
rooms,
|
||||
chat,
|
||||
chatApi,
|
||||
logger,
|
||||
roomId => _.Simul(roomId.value).some,
|
||||
chatBusChan = _.Simul,
|
||||
|
|
|
@ -25,6 +25,7 @@ final class Env(
|
|||
timeline: lila.hub.actors.Timeline,
|
||||
fishnet: lila.hub.actors.Fishnet,
|
||||
chatApi: lila.chat.ChatApi,
|
||||
chatJson: lila.chat.JsonView,
|
||||
mongo: lila.db.Env,
|
||||
net: lila.common.config.NetConfig,
|
||||
cacheApi: lila.memo.CacheApi
|
||||
|
|
|
@ -19,7 +19,8 @@ final private class StudySocket(
|
|||
api: StudyApi,
|
||||
jsonView: JsonView,
|
||||
remoteSocketApi: lila.socket.RemoteSocket,
|
||||
chatApi: lila.chat.ChatApi
|
||||
chatApi: lila.chat.ChatApi,
|
||||
chatJson: lila.chat.JsonView
|
||||
)(implicit
|
||||
ec: scala.concurrent.ExecutionContext,
|
||||
mode: play.api.Mode
|
||||
|
@ -32,7 +33,7 @@ final private class StudySocket(
|
|||
|
||||
lazy val rooms = makeRoomMap(send)
|
||||
|
||||
subscribeChat(rooms, _.Study)
|
||||
subscribeChat(rooms, _.Study, chatJson.lineWriter)
|
||||
|
||||
def isPresent(studyId: Study.Id, userId: User.ID): Fu[Boolean] =
|
||||
remoteSocketApi.request[Boolean](
|
||||
|
|
|
@ -17,6 +17,7 @@ final class Env(
|
|||
onStart: lila.round.OnStart,
|
||||
remoteSocketApi: lila.socket.RemoteSocket,
|
||||
chatApi: lila.chat.ChatApi,
|
||||
chatJson: lila.chat.JsonView,
|
||||
cacheApi: lila.memo.CacheApi,
|
||||
lightUserApi: lila.user.LightUserApi,
|
||||
historyApi: lila.history.HistoryApi,
|
||||
|
|
|
@ -11,7 +11,8 @@ import lila.socket.Socket.makeMessage
|
|||
|
||||
final private class SwissSocket(
|
||||
remoteSocketApi: lila.socket.RemoteSocket,
|
||||
chat: lila.chat.ChatApi,
|
||||
chatApi: lila.chat.ChatApi,
|
||||
chatJson: lila.chat.JsonView,
|
||||
teamOf: Swiss.Id => Fu[Option[TeamID]]
|
||||
)(implicit
|
||||
ec: scala.concurrent.ExecutionContext,
|
||||
|
@ -32,12 +33,12 @@ final private class SwissSocket(
|
|||
|
||||
lazy val rooms = makeRoomMap(send)
|
||||
|
||||
subscribeChat(rooms, _.Swiss)
|
||||
subscribeChat(rooms, _.Swiss, chatJson.lineWriter)
|
||||
|
||||
private lazy val handler: Handler =
|
||||
roomHandler(
|
||||
rooms,
|
||||
chat,
|
||||
chatApi,
|
||||
logger,
|
||||
roomId => _.Swiss(roomId.value).some,
|
||||
localTimeout = Some { (roomId, modId, _) =>
|
||||
|
|
|
@ -18,6 +18,7 @@ final class Env(
|
|||
notifyApi: NotifyApi,
|
||||
remoteSocketApi: lila.socket.RemoteSocket,
|
||||
chatApi: lila.chat.ChatApi,
|
||||
chatJson: lila.chat.JsonView,
|
||||
cacheApi: lila.memo.CacheApi,
|
||||
lightUserApi: lila.user.LightUserApi,
|
||||
db: lila.db.Db
|
||||
|
|
|
@ -5,7 +5,8 @@ import lila.socket.RemoteSocket.{ Protocol => P, _ }
|
|||
|
||||
final private class TeamSocket(
|
||||
remoteSocketApi: lila.socket.RemoteSocket,
|
||||
chat: lila.chat.ChatApi,
|
||||
chatApi: lila.chat.ChatApi,
|
||||
chatJson: lila.chat.JsonView,
|
||||
cached: Cached
|
||||
)(implicit
|
||||
ec: scala.concurrent.ExecutionContext,
|
||||
|
@ -14,12 +15,12 @@ final private class TeamSocket(
|
|||
|
||||
lazy val rooms = makeRoomMap(send)
|
||||
|
||||
subscribeChat(rooms, _.Team)
|
||||
subscribeChat(rooms, _.Team, chatJson.lineWriter)
|
||||
|
||||
private lazy val handler: Handler =
|
||||
roomHandler(
|
||||
rooms,
|
||||
chat,
|
||||
chatApi,
|
||||
logger,
|
||||
roomId => _.Team(roomId.value).some,
|
||||
localTimeout = Some { (roomId, modId, suspectId) =>
|
||||
|
|
|
@ -30,6 +30,7 @@ final class Env(
|
|||
proxyRepo: lila.round.GameProxyRepo,
|
||||
renderer: lila.hub.actors.Renderer,
|
||||
chatApi: lila.chat.ChatApi,
|
||||
chatJson: lila.chat.JsonView,
|
||||
tellRound: lila.round.TellRound,
|
||||
roundSocket: lila.round.RoundSocket,
|
||||
lightUserApi: lila.user.LightUserApi,
|
||||
|
|
|
@ -15,7 +15,8 @@ import lila.user.User
|
|||
final private class TournamentSocket(
|
||||
repo: TournamentRepo,
|
||||
remoteSocketApi: lila.socket.RemoteSocket,
|
||||
chat: lila.chat.ChatApi
|
||||
chatApi: lila.chat.ChatApi,
|
||||
chatJson: lila.chat.JsonView
|
||||
)(implicit
|
||||
ec: scala.concurrent.ExecutionContext,
|
||||
system: ActorSystem,
|
||||
|
@ -65,12 +66,12 @@ final private class TournamentSocket(
|
|||
|
||||
lazy val rooms = makeRoomMap(send)
|
||||
|
||||
subscribeChat(rooms, _.Tournament)
|
||||
subscribeChat(rooms, _.Tournament, chatJson.lineWriter)
|
||||
|
||||
private lazy val handler: Handler =
|
||||
roomHandler(
|
||||
rooms,
|
||||
chat,
|
||||
chatApi,
|
||||
logger,
|
||||
roomId => _.Tournament(roomId.value).some,
|
||||
chatBusChan = _.Tournament,
|
||||
|
|
Loading…
Reference in New Issue