global chat timeouts for mods - local for study owners
parent
ecebf7d79c
commit
c713b07db0
|
@ -110,12 +110,12 @@ final class ChatApi(
|
|||
modId: User.ID,
|
||||
userId: User.ID,
|
||||
reason: ChatTimeout.Reason,
|
||||
text: String,
|
||||
local: Boolean
|
||||
scope: ChatTimeout.Scope,
|
||||
text: 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) || local =>
|
||||
doTimeout(chat, mod, user, reason, text)
|
||||
case Some(chat) ~ Some(mod) ~ Some(user) if isMod(mod) || scope == ChatTimeout.Scope.Local =>
|
||||
doTimeout(chat, mod, user, reason, scope, text)
|
||||
case _ => fuccess(none)
|
||||
}
|
||||
|
||||
|
@ -131,6 +131,7 @@ final class ChatApi(
|
|||
mod: User,
|
||||
user: User,
|
||||
reason: ChatTimeout.Reason,
|
||||
scope: ChatTimeout.Scope,
|
||||
text: String
|
||||
): Funit = {
|
||||
val line = c.hasRecentLine(user) option UserLine(
|
||||
|
@ -143,7 +144,7 @@ final class ChatApi(
|
|||
val c2 = c.markDeleted(user)
|
||||
val chat = line.fold(c2)(c2.add)
|
||||
coll.update.one($id(chat.id), chat).void >>
|
||||
chatTimeout.add(c, mod, user, reason) >>- {
|
||||
chatTimeout.add(c, mod, user, reason, scope) >>- {
|
||||
cached invalidate chat.id
|
||||
publish(chat.id, actorApi.OnTimeout(user.id))
|
||||
line foreach { l =>
|
||||
|
|
|
@ -14,10 +14,13 @@ final class ChatTimeout(
|
|||
|
||||
import ChatTimeout._
|
||||
|
||||
def add(chat: UserChat, mod: User, user: User, reason: Reason): Funit =
|
||||
private val global = new lila.memo.ExpireSetMemo(duration)
|
||||
|
||||
def add(chat: UserChat, mod: User, user: User, reason: Reason, scope: Scope): Funit =
|
||||
isActive(chat.id, user.id) flatMap {
|
||||
case true => funit
|
||||
case false =>
|
||||
if (scope == Scope.Global) global put user.id
|
||||
coll.insert
|
||||
.one(
|
||||
$doc(
|
||||
|
@ -34,7 +37,7 @@ final class ChatTimeout(
|
|||
}
|
||||
|
||||
def isActive(chatId: Chat.Id, userId: User.ID): Fu[Boolean] =
|
||||
coll.exists(
|
||||
fuccess(global.get(userId)) >>| coll.exists(
|
||||
$doc(
|
||||
"chat" -> chatId,
|
||||
"user" -> userId,
|
||||
|
@ -42,15 +45,6 @@ final class ChatTimeout(
|
|||
)
|
||||
)
|
||||
|
||||
def activeUserIds(chat: UserChat): Fu[List[User.ID]] =
|
||||
coll.primitive[User.ID](
|
||||
$doc(
|
||||
"chat" -> chat.id,
|
||||
"expiresAt" $exists true
|
||||
),
|
||||
"user"
|
||||
)
|
||||
|
||||
def history(user: User, nb: Int): Fu[List[UserEntry]] =
|
||||
coll.ext.find($doc("user" -> user.id)).sort($sort desc "createdAt").list[UserEntry](nb)
|
||||
|
||||
|
@ -92,4 +86,10 @@ object ChatTimeout {
|
|||
|
||||
case class UserEntry(mod: String, reason: Reason, createdAt: DateTime)
|
||||
implicit val UserEntryBSONReader: BSONDocumentReader[UserEntry] = Macros.reader[UserEntry]
|
||||
|
||||
sealed trait Scope
|
||||
object Scope {
|
||||
case object Local extends Scope
|
||||
case object Global extends Scope
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package lila.room
|
||||
|
||||
import lila.chat.{ Chat, ChatApi, UserLine, actorApi => chatApi }
|
||||
import lila.chat.{ Chat, ChatApi, UserLine, ChatTimeout, actorApi => chatApi }
|
||||
import lila.common.Bus
|
||||
import lila.hub.actorApi.shutup.PublicSource
|
||||
import lila.hub.{ Trouper, TrouperMap }
|
||||
|
@ -83,7 +83,8 @@ object RoomSocket {
|
|||
case Protocol.In.ChatTimeout(roomId, modId, suspect, reason, text) =>
|
||||
lila.chat.ChatTimeout.Reason(reason) foreach { r =>
|
||||
localTimeout.?? { _(roomId, modId, suspect) } foreach { local =>
|
||||
chat.userChat.timeout(Chat.Id(roomId.value), modId, suspect, r, text = text, local = local)
|
||||
val scope = if (local) ChatTimeout.Scope.Local else ChatTimeout.Scope.Global
|
||||
chat.userChat.timeout(Chat.Id(roomId.value), modId, suspect, r, text = text, scope = scope)
|
||||
}
|
||||
}
|
||||
}: Handler) orElse minRoomHandler(rooms, logger)
|
||||
|
|
|
@ -49,7 +49,7 @@ final class Messenger(api: ChatApi) {
|
|||
|
||||
def timeout(chatId: Chat.Id, modId: User.ID, suspect: User.ID, reason: String, text: String): Unit =
|
||||
ChatTimeout.Reason(reason) foreach { r =>
|
||||
api.userChat.timeout(chatId, modId, suspect, r, text, local = false)
|
||||
api.userChat.timeout(chatId, modId, suspect, r, ChatTimeout.Scope.Global, text)
|
||||
}
|
||||
|
||||
private def watcherId(chatId: Chat.Id) = Chat.Id(s"$chatId/w")
|
||||
|
|
Loading…
Reference in New Issue