<commit_before>package lila.msg

import com.softwaremill.macwire._

import lila.common.Bus
import lila.common.config._
import lila.user.User
import lila.hub.actorApi.socket.remote.TellUserIn

@Module
final class Env(
    db: lila.db.Db,
    lightUserApi: lila.user.LightUserApi,
    isOnline: lila.socket.IsOnline,
    userRepo: lila.user.UserRepo,
    userCache: lila.user.Cached,
    relationApi: lila.relation.RelationApi,
    prefApi: lila.pref.PrefApi,
    notifyApi: lila.notify.NotifyApi,
    cacheApi: lila.memo.CacheApi,
    spam: lila.security.Spam,
    chatPanic: lila.chat.ChatPanic,
    shutup: lila.hub.actors.Shutup
)(implicit
    ec: scala.concurrent.ExecutionContext,
    system: akka.actor.ActorSystem,
    scheduler: akka.actor.Scheduler
) {

  private val colls = wire[MsgColls]

  lazy val json = wire[MsgJson]

  private lazy val notifier = wire[MsgNotify]

  private lazy val security = wire[MsgSecurity]

  lazy val api: MsgApi = wire[MsgApi]

  lazy val search = wire[MsgSearch]

  lazy val compat = wire[MsgCompat]

  def cli =
    new lila.common.Cli {
      def process = { case "msg" :: "multi" :: orig :: dests :: words =>
        api.cliMultiPost(orig, dests.split(',').toIndexedSeq, words mkString " ")
      }
    }

  Bus.subscribeFuns(
    "msgSystemSend" -> { case lila.hub.actorApi.msg.SystemMsg(userId, text) =>
      api.systemPost(userId, text).unit
    },
    "remoteSocketIn:msgRead" -> { case TellUserIn(userId, msg) =>
      msg str "d" map User.normalize foreach { api.setRead(userId, _) }
    },
    "remoteSocketIn:msgSend" -> { case TellUserIn(userId, msg) =>
      for {
        obj  <- msg obj "d"
        dest <- obj str "dest" map User.normalize
        text <- obj str "text"
      } api.post(userId, dest, text)
    }
  )
}

private class MsgColls(db: lila.db.Db) {
  val thread = db(CollName("msg_thread"))
  val msg    = db(CollName("msg_msg"))
}
<commit_msg>fix cli msg multi-send<commit_after>package lila.msg

import com.softwaremill.macwire._

import lila.common.Bus
import lila.common.config._
import lila.user.User
import lila.hub.actorApi.socket.remote.TellUserIn

@Module
final class Env(
    db: lila.db.Db,
    lightUserApi: lila.user.LightUserApi,
    isOnline: lila.socket.IsOnline,
    userRepo: lila.user.UserRepo,
    userCache: lila.user.Cached,
    relationApi: lila.relation.RelationApi,
    prefApi: lila.pref.PrefApi,
    notifyApi: lila.notify.NotifyApi,
    cacheApi: lila.memo.CacheApi,
    spam: lila.security.Spam,
    chatPanic: lila.chat.ChatPanic,
    shutup: lila.hub.actors.Shutup
)(implicit
    ec: scala.concurrent.ExecutionContext,
    system: akka.actor.ActorSystem,
    scheduler: akka.actor.Scheduler
) {

  private val colls = wire[MsgColls]

  lazy val json = wire[MsgJson]

  private lazy val notifier = wire[MsgNotify]

  private lazy val security = wire[MsgSecurity]

  lazy val api: MsgApi = wire[MsgApi]

  lazy val search = wire[MsgSearch]

  lazy val compat = wire[MsgCompat]

  def cli =
    new lila.common.Cli {
      def process = { case "msg" :: "multi" :: orig :: dests :: words =>
        api.cliMultiPost(orig, dests.map(_.toLower).split(',').toIndexedSeq, words mkString " ")
      }
    }

  Bus.subscribeFuns(
    "msgSystemSend" -> { case lila.hub.actorApi.msg.SystemMsg(userId, text) =>
      api.systemPost(userId, text).unit
    },
    "remoteSocketIn:msgRead" -> { case TellUserIn(userId, msg) =>
      msg str "d" map User.normalize foreach { api.setRead(userId, _) }
    },
    "remoteSocketIn:msgSend" -> { case TellUserIn(userId, msg) =>
      for {
        obj  <- msg obj "d"
        dest <- obj str "dest" map User.normalize
        text <- obj str "text"
      } api.post(userId, dest, text)
    }
  )
}

private class MsgColls(db: lila.db.Db) {
  val thread = db(CollName("msg_thread"))
  val msg    = db(CollName("msg_msg"))
}

{'fraction_non_alphanumeric': 0.12688116242864556, 'fraction_numerical': 0.0, 'mean_word_length': 3.122994652406417, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3603387', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1372, 'n_words': 291}