team chat ID prefix - WIP
parent
89b0f2af51
commit
6e1837e6d4
|
@ -56,7 +56,7 @@ final class Team(
|
|||
hasChat = canHaveChat(team, info)
|
||||
chat <-
|
||||
hasChat ?? env.chat.api.userChat.cached
|
||||
.findMine(lila.chat.Chat.Id(team.id), ctx.me)
|
||||
.findMine(lila.chat.Chat.Id(team.chatId), ctx.me)
|
||||
.map(some)
|
||||
_ <- env.user.lightUserApi preloadMany {
|
||||
info.userIds ::: chat.??(_.chat.userIds)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
db.team.find().forEach(t => {
|
||||
|
||||
let c = db.chat.findOne({_id:t._id});
|
||||
|
||||
if (c) {
|
||||
db.chat.remove({_id: c._id});
|
||||
c._id = `t:${c._id}`;
|
||||
db.chat.insert(c);
|
||||
print(`Moved ${c._id}`);
|
||||
}
|
||||
});
|
|
@ -49,7 +49,7 @@ final class BotPlayer(
|
|||
val source = d.room == "spectator" option {
|
||||
lila.hub.actorApi.shutup.PublicSource.Watcher(gameId)
|
||||
}
|
||||
chatApi.userChat.write(chatId, me.id, d.text, publicSource = source, _.Round)
|
||||
chatApi.userChat.write(chatId, me.id, d.text, publicSource = source, _.Round)(chatApi.defaultDbId)
|
||||
}
|
||||
|
||||
def rematchAccept(id: Game.ID, me: User): Fu[Boolean] = rematch(id, me, accept = true)
|
||||
|
|
|
@ -85,7 +85,7 @@ final class ChatApi(
|
|||
text: String,
|
||||
publicSource: Option[PublicSource],
|
||||
busChan: BusChan.Select
|
||||
): Funit =
|
||||
)(implicit dbId: Chat.Id => String): Funit =
|
||||
makeLine(chatId, userId, text) flatMap {
|
||||
_ ?? { line =>
|
||||
linkCheck(line, publicSource) flatMap {
|
||||
|
@ -94,7 +94,7 @@ final class ChatApi(
|
|||
funit
|
||||
case true =>
|
||||
pushLine(chatId, line) >>- {
|
||||
if (publicSource.isDefined) cached invalidate chatId
|
||||
if (publicSource.isDefined) cached invalidate Chat.Id(dbId(chatId))
|
||||
shutup ! {
|
||||
publicSource match {
|
||||
case Some(source) => RecordPublicChat(userId, text, source)
|
||||
|
@ -117,7 +117,7 @@ final class ChatApi(
|
|||
|
||||
def system(chatId: Chat.Id, text: String, busChan: BusChan.Select): Funit = {
|
||||
val line = UserLine(systemUserId, None, text, troll = false, deleted = false)
|
||||
pushLine(chatId, line) >>- {
|
||||
pushLine(chatId, line)(defaultDbId) >>- {
|
||||
cached.invalidate(chatId)
|
||||
publish(chatId, actorApi.ChatLine(chatId, line), busChan)
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ final class ChatApi(
|
|||
scope: ChatTimeout.Scope,
|
||||
text: String,
|
||||
busChan: BusChan.Select
|
||||
): Funit =
|
||||
)(implicit dbId: Chat.Id => String): Funit =
|
||||
coll.byId[UserChat](chatId.value) zip userRepo.byId(modId) zip userRepo.byId(userId) flatMap {
|
||||
case Some(chat) ~ Some(mod) ~ Some(user) if isMod(mod) || scope == ChatTimeout.Scope.Local =>
|
||||
doTimeout(chat, mod, user, reason, scope, text, busChan)
|
||||
|
@ -162,7 +162,7 @@ final class ChatApi(
|
|||
scope: ChatTimeout.Scope,
|
||||
text: String,
|
||||
busChan: BusChan.Select
|
||||
): Funit = {
|
||||
)(implicit dbId: Chat.Id => String): Funit = {
|
||||
val line = c.hasRecentLine(user) option UserLine(
|
||||
username = systemUserId,
|
||||
title = None,
|
||||
|
@ -172,7 +172,7 @@ final class ChatApi(
|
|||
)
|
||||
val c2 = c.markDeleted(user)
|
||||
val chat = line.fold(c2)(c2.add)
|
||||
coll.update.one($id(chat.id), chat).void >>
|
||||
coll.update.one($id(dbId(chat.id)), chat).void >>
|
||||
chatTimeout.add(c, mod, user, reason, scope) >>- {
|
||||
cached invalidate chat.id
|
||||
publish(chat.id, actorApi.OnTimeout(chat.id, user.id), busChan)
|
||||
|
@ -252,7 +252,7 @@ final class ChatApi(
|
|||
|
||||
def write(chatId: Chat.Id, color: Color, text: String, busChan: BusChan.Select): Funit =
|
||||
makeLine(chatId, color, text) ?? { line =>
|
||||
pushLine(chatId, line) >>- {
|
||||
pushLine(chatId, line)(defaultDbId) >>- {
|
||||
publish(chatId, actorApi.ChatLine(chatId, line), busChan)
|
||||
lila.mon.chat.message("anonPlayer", troll = false).increment()
|
||||
}
|
||||
|
@ -274,10 +274,12 @@ final class ChatApi(
|
|||
|
||||
def removeAll(chatIds: List[Chat.Id]) = coll.delete.one($inIds(chatIds)).void
|
||||
|
||||
private def pushLine(chatId: Chat.Id, line: Line): Funit =
|
||||
val defaultDbId = (id: Chat.Id) => id.value
|
||||
|
||||
private def pushLine(chatId: Chat.Id, line: Line)(implicit dbId: Chat.Id => String): Funit =
|
||||
coll.update
|
||||
.one(
|
||||
$id(chatId),
|
||||
$id(dbId(chatId)),
|
||||
$doc(
|
||||
"$push" -> $doc(
|
||||
Chat.BSONFields.lines -> $doc(
|
||||
|
|
|
@ -63,7 +63,8 @@ object RoomSocket {
|
|||
logger: Logger,
|
||||
publicSource: RoomId => PublicSource.type => Option[PublicSource],
|
||||
localTimeout: Option[(RoomId, User.ID, User.ID) => Fu[Boolean]] = None,
|
||||
chatBusChan: BusChan.Select
|
||||
chatBusChan: BusChan.Select,
|
||||
chatDbId: Chat.Id => String = _.value
|
||||
)(implicit ec: ExecutionContext): Handler =
|
||||
({
|
||||
case Protocol.In.ChatSay(roomId, userId, msg) =>
|
||||
|
@ -73,7 +74,7 @@ object RoomSocket {
|
|||
msg,
|
||||
publicSource(roomId)(PublicSource),
|
||||
chatBusChan
|
||||
)
|
||||
)(chatDbId)
|
||||
case Protocol.In.ChatTimeout(roomId, modId, suspect, reason, text) =>
|
||||
lila.chat.ChatTimeout.Reason(reason) foreach { r =>
|
||||
localTimeout.?? { _(roomId, modId, suspect) } foreach { local =>
|
||||
|
@ -86,7 +87,7 @@ object RoomSocket {
|
|||
text = text,
|
||||
scope = scope,
|
||||
busChan = chatBusChan
|
||||
)
|
||||
)(chatDbId)
|
||||
}
|
||||
}
|
||||
}: Handler) orElse minRoomHandler(rooms, logger)
|
||||
|
|
|
@ -7,6 +7,8 @@ import lila.user.User
|
|||
|
||||
final class Messenger(api: ChatApi) {
|
||||
|
||||
implicit private val chatDbId = api.defaultDbId
|
||||
|
||||
def system(game: Game, message: String): Unit =
|
||||
system(persistent = true)(game, message)
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ final private class ChapterMaker(
|
|||
text = s"I'm studying this game on ${net.domain}/study/${study.id}",
|
||||
publicSource = none,
|
||||
_.Study
|
||||
)
|
||||
)(chatApi.defaultDbId)
|
||||
}
|
||||
|
||||
private[study] def game2root(game: Game, initialFen: Option[FEN]): Fu[Node.Root] =
|
||||
|
@ -212,7 +212,7 @@ private[study] object ChapterMaker {
|
|||
orientation: String = "white",
|
||||
mode: String = ChapterMaker.Mode.Normal.key,
|
||||
initial: Boolean = false,
|
||||
isDefaultName: Boolean = true,
|
||||
isDefaultName: Boolean = true
|
||||
) extends ChapterData {
|
||||
|
||||
def manyGames =
|
||||
|
|
|
@ -180,7 +180,7 @@ final class StudyApi(
|
|||
text = text,
|
||||
publicSource = lila.hub.actorApi.shutup.PublicSource.Study(studyId.value).some,
|
||||
busChan = _.Study
|
||||
)
|
||||
)(chatApi.defaultDbId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ case class Team(
|
|||
|
||||
def isChatFor(f: Team.ChatFor.type => Team.ChatFor) =
|
||||
chat == f(Team.ChatFor)
|
||||
|
||||
def chatId = Team chatId id
|
||||
}
|
||||
|
||||
object Team {
|
||||
|
@ -35,6 +37,8 @@ object Team {
|
|||
|
||||
type ID = String
|
||||
|
||||
def chatId(id: ID) = s"t:$id"
|
||||
|
||||
type ChatFor = Int
|
||||
object ChatFor {
|
||||
val NONE = 0
|
||||
|
|
|
@ -25,7 +25,8 @@ final private class TeamSocket(
|
|||
localTimeout = Some { (roomId, modId, suspectId) =>
|
||||
cached.isLeader(roomId.value, modId) >>& !cached.isLeader(roomId.value, suspectId)
|
||||
},
|
||||
chatBusChan = _.Team
|
||||
chatBusChan = _.Team,
|
||||
chatDbId = id => Team chatId id.value
|
||||
)
|
||||
|
||||
private lazy val send: String => Unit = remoteSocketApi.makeSender("team-out").apply _
|
||||
|
|
Loading…
Reference in New Issue