tournament messenger
This commit is contained in:
parent
36974b6a3f
commit
5ceef6c886
|
@ -54,7 +54,7 @@ final class Env(
|
|||
|
||||
lazy val history = new History(ttl = MessageTtl)
|
||||
|
||||
private lazy val messenger = new Messenger(netDomain = NetDomain)
|
||||
private lazy val messenger = new Messenger(NetDomain)
|
||||
|
||||
private lazy val hookMemo = new ExpireSetMemo(ttl = OrphanHookTtl)
|
||||
|
||||
|
|
|
@ -24,5 +24,5 @@ private[lobby] final class Messenger(val netDomain: String) extends Room {
|
|||
|
||||
def mute(username: String): Funit = MessageRepo censorUsername username
|
||||
|
||||
def remove = MessageRepo.removeRegex _
|
||||
def remove = MessageRepo removeRegex _
|
||||
}
|
||||
|
|
|
@ -20,9 +20,12 @@ final class Env(
|
|||
val MemoTtl = config duration "memo.ttl"
|
||||
val UidTimeout = config duration "uid.timeout"
|
||||
val HubTimeout = config duration "hub.timeout"
|
||||
val NetDomain = config getString "net.domain"
|
||||
}
|
||||
import settings._
|
||||
|
||||
private[tournament] lazy val messenger = new Messenger(NetDomain)
|
||||
|
||||
private[tournament] lazy val tournamentColl = db(CollectionTournament)
|
||||
private[tournament] lazy val roomColl = db(CollectionRoom)
|
||||
}
|
||||
|
|
33
modules/tournament/src/main/Messenger.scala
Normal file
33
modules/tournament/src/main/Messenger.scala
Normal file
|
@ -0,0 +1,33 @@
|
|||
package lila.tournament
|
||||
|
||||
import lila.db.api.$find
|
||||
import tube.tournamentTube
|
||||
import lila.user.{ User, UserRepo, Room ⇒ UserRoom }
|
||||
|
||||
private[tournament] final class Messenger(val netDomain: String) extends UserRoom {
|
||||
|
||||
import Room._
|
||||
|
||||
def init(tour: Created): Fu[List[Message]] = for {
|
||||
userOption ← UserRepo named tour.data.createdBy
|
||||
username = userOption.fold(tour.data.createdBy)(_.username)
|
||||
message ← systemMessage(tour, "%s creates the tournament" format username)
|
||||
} yield List(message)
|
||||
|
||||
def userMessage(tournamentId: String, username: String, text: String): Fu[Message] = for {
|
||||
userOption ← UserRepo named username
|
||||
tourOption ← $find byId tournamentId
|
||||
message ← (for {
|
||||
user ← userOption filter (_.canChat) toValid "This user cannot chat"
|
||||
_ ← tourOption toValid "No such tournament"
|
||||
msg ← createMessage(user, text)
|
||||
(author, text) = msg
|
||||
} yield Message(author.some, text)).future
|
||||
_ ← RoomRepo.addMessage(tournamentId, message)
|
||||
} yield message
|
||||
|
||||
def systemMessage(tour: Tournament, text: String): Fu[Message] =
|
||||
Message(none, text) |> { message ⇒
|
||||
RoomRepo.addMessage(tour.id, message) inject message
|
||||
}
|
||||
}
|
|
@ -1,16 +1,15 @@
|
|||
package lila.app
|
||||
package tournament
|
||||
package lila.tournament
|
||||
package actorApi
|
||||
|
||||
import socket.SocketMember
|
||||
import user.User
|
||||
import game.DbGame
|
||||
import lila.socket.SocketMember
|
||||
import lila.user.User
|
||||
import lila.game.Game
|
||||
|
||||
import akka.actor.ActorRef
|
||||
import scalaz.effects.IO
|
||||
|
||||
case class Member(
|
||||
channel: JsChannel,
|
||||
username: Option[String],
|
||||
userId: Option[String],
|
||||
muted: Boolean) extends SocketMember {
|
||||
|
||||
def canChat = !muted
|
||||
|
@ -19,8 +18,8 @@ case class Member(
|
|||
object Member {
|
||||
def apply(channel: JsChannel, user: Option[User]): Member = Member(
|
||||
channel = channel,
|
||||
username = user map (_.username),
|
||||
muted = ~user.map(_.muted))
|
||||
userId = user map (_.id),
|
||||
muted = user.zmap(_.muted))
|
||||
}
|
||||
|
||||
case class Join(
|
||||
|
@ -37,7 +36,7 @@ case object Start
|
|||
case object Reload
|
||||
case object ReloadPage
|
||||
case object HubTimeout
|
||||
case class StartGame(game: DbGame)
|
||||
case class StartGame(game: Game)
|
||||
case class Joining(userId: String)
|
||||
|
||||
// organizer
|
|
@ -1,8 +1,9 @@
|
|||
package lila
|
||||
|
||||
import lila.socket.WithSocket
|
||||
import lila.db.{ Tube, InColl }
|
||||
|
||||
package object tournament extends PackageObject with WithPlay {
|
||||
package object tournament extends PackageObject with WithPlay with WithSocket{
|
||||
|
||||
object tube {
|
||||
|
||||
|
@ -11,9 +12,9 @@ package object tournament extends PackageObject with WithPlay {
|
|||
private[tournament] implicit lazy val roomTube = Room.tube inColl Env.current.roomColl
|
||||
}
|
||||
|
||||
private[tournament]type Pairings = List[tournament.Pairing]
|
||||
private[tournament] type Pairings = List[tournament.Pairing]
|
||||
|
||||
private[tournament]type Players = List[tournament.Player]
|
||||
private[tournament] type Players = List[tournament.Player]
|
||||
|
||||
private[tournament] object RandomName {
|
||||
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package lila.app
|
||||
package tournament
|
||||
|
||||
import scalaz.effects._
|
||||
|
||||
import user.User
|
||||
|
||||
final class Messenger(
|
||||
roomRepo: RoomRepo,
|
||||
getTournament: String ⇒ IO[Option[Tournament]],
|
||||
getUser: String ⇒ IO[Option[User]],
|
||||
val netDomain: String) extends core.Room {
|
||||
|
||||
import Room._
|
||||
|
||||
def init(tour: Created): IO[List[Message]] = for {
|
||||
userOption ← getUser(tour.data.createdBy)
|
||||
username = userOption.fold(tour.data.createdBy)(_.username)
|
||||
message ← systemMessage(tour, "%s creates the tournament" format username)
|
||||
} yield List(message)
|
||||
|
||||
def userMessage(tournamentId: String, username: String, text: String): IO[Valid[Message]] = for {
|
||||
userOption ← getUser(username)
|
||||
tourOption ← getTournament(tournamentId)
|
||||
message = for {
|
||||
user ← userOption filter (_.canChat) toValid "This user cannot chat"
|
||||
_ ← tourOption toValid "No such tournament"
|
||||
msg ← createMessage(user, text)
|
||||
(author, text) = msg
|
||||
} yield Message(author.some, text)
|
||||
_ ← message.fold(_ ⇒ io(), msg ⇒ roomRepo.addMessage(tournamentId, msg))
|
||||
} yield message
|
||||
|
||||
def systemMessage(tour: Tournament, text: String): IO[Message] =
|
||||
Message(none, text) |> { message ⇒
|
||||
roomRepo.addMessage(tour.id, message) map (_ ⇒ message)
|
||||
}
|
||||
|
||||
def render(tour: Tournament): IO[String] = render(tour.id)
|
||||
|
||||
def render(roomId: String): IO[String] = roomRepo room roomId map (_.render)
|
||||
}
|
|
@ -104,7 +104,7 @@ object ApplicationBuild extends Build {
|
|||
libraryDependencies ++= provided(playApi, reactivemongo, playReactivemongo)
|
||||
)
|
||||
|
||||
lazy val tournament = project("tournament", Seq(common, chess, game, round, setup)).settings(
|
||||
lazy val tournament = project("tournament", Seq(common, hub, socket, chess, game, round, setup)).settings(
|
||||
libraryDependencies ++= provided(playApi, reactivemongo, playReactivemongo)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue