forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.scala
More file actions
103 lines (95 loc) · 3.08 KB
/
Copy pathchat.scala
File metadata and controls
103 lines (95 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package views.html
import play.api.libs.json.Json
import lila.app.templating.Environment.{ given, * }
import lila.app.ui.ScalatagsTemplate.*
import lila.i18n.I18nKeys
import lila.common.Json.given
object chat:
val frag = st.section(cls := "mchat")(
div(cls := "mchat__tabs")(
div(cls := "mchat__tab")(nbsp)
),
div(cls := "mchat__content")
)
def restrictedJson(
chat: lila.chat.Chat.Restricted,
name: String,
timeout: Boolean,
public: Boolean, // game players chat is not public
resourceId: lila.chat.Chat.ResourceId,
withNoteAge: Option[Int] = None,
writeable: Boolean = true,
localMod: Boolean = false,
palantir: Boolean = false
)(using Context) =
json(
chat.chat,
name = name,
timeout = timeout,
withNoteAge = withNoteAge,
writeable = writeable,
public = public,
resourceId = resourceId,
restricted = chat.restricted,
localMod = localMod,
palantir = palantir
)
def json(
chat: lila.chat.AnyChat,
name: String,
timeout: Boolean,
public: Boolean, // game players chat is not public
resourceId: lila.chat.Chat.ResourceId,
withNoteAge: Option[Int] = None,
writeable: Boolean = true,
restricted: Boolean = false,
localMod: Boolean = false,
broadcastMod: Boolean = false,
palantir: Boolean = false
)(using ctx: Context) =
Json
.obj(
"data" -> Json
.obj(
"id" -> chat.id,
"name" -> name,
"lines" -> lila.chat.JsonView(chat),
"userId" -> ctx.userId,
"resourceId" -> resourceId.value
)
.add("loginRequired" -> chat.loginRequired)
.add("restricted" -> restricted)
.add("palantir" -> (palantir && ctx.isAuth)),
"i18n" -> i18n(withNote = withNoteAge.isDefined),
"writeable" -> writeable,
"public" -> public,
"permissions" -> Json
.obj("local" -> (public && localMod))
.add("broadcast" -> (public && broadcastMod))
.add("timeout" -> (public && isGranted(_.ChatTimeout)))
.add("shadowban" -> (public && isGranted(_.Shadowban)))
)
.add("kobold" -> ctx.troll)
.add("blind" -> ctx.blind)
.add("timeout" -> timeout)
.add("noteId" -> (withNoteAge.isDefined && ctx.noBlind).option(chat.id.value take 8))
.add("noteAge" -> withNoteAge)
.add(
"timeoutReasons" -> (!localMod && (isGranted(_.ChatTimeout) || isGranted(_.BroadcastTimeout)))
.option(lila.chat.JsonView.timeoutReasons)
)
def i18n(withNote: Boolean)(using Context) =
i18nOptionJsObject(
I18nKeys.talkInChat.some,
I18nKeys.toggleTheChat.some,
I18nKeys.loginToChat.some,
I18nKeys.youHaveBeenTimedOut.some,
withNote option I18nKeys.notes,
withNote option I18nKeys.typePrivateNotesHere
)
val spectatorsFrag =
div(
cls := "chat__members none",
aria.live := "off",
aria.relevant := "additions removals text"
)