Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow taking private notes in kid mode #16761

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 34 additions & 35 deletions app/controllers/Round.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ final class Round(
private[controllers] def getWatcherChat(
game: GameModel
)(using ctx: Context): Fu[Option[lila.chat.UserChat.Mine]] = {
ctx.kid.no && (ctx.noBot || ctx.userId.exists(game.userIds.has)) && ctx.me.fold(
(ctx.noBot || ctx.userId.exists(game.userIds.has)) && ctx.me.fold(
HTTPRequest.isHuman(ctx.req)
)(env.chat.panic.allowed(_)) && {
game.finishedOrAborted || !ctx.userId.exists(game.userIds.has)
Expand All @@ -212,41 +212,40 @@ final class Round(
private[controllers] def getPlayerChat(game: GameModel, tour: Option[Tour])(using
ctx: Context
): Fu[Option[Chat.GameOrEvent]] =
ctx.kid.no.so:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this causes the game chat to always be loaded and sent to all clients, including the mobile apps, where kids will get to see the other player messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feared my approach would be too simple.
Let me think of something else.

def toEventChat(resource: String)(c: lila.chat.UserChat.Mine) =
Chat
.GameOrEvent:
Right:
(c.truncate(100), lila.chat.Chat.ResourceId(resource))
.some
(game.tournamentId, game.simulId, game.swissId) match
case (Some(tid), _, _) =>
val hasChat = ctx.isAuth && tour.forall(tournamentC.canHaveChat(_, none))
hasChat.so(
def toEventChat(resource: String)(c: lila.chat.UserChat.Mine) =
Chat
.GameOrEvent:
Right:
(c.truncate(100), lila.chat.Chat.ResourceId(resource))
.some
(game.tournamentId, game.simulId, game.swissId) match
case (Some(tid), _, _) =>
val hasChat = ctx.isAuth && tour.forall(tournamentC.canHaveChat(_, none))
hasChat.so(
env.chat.api.userChat.cached
.findMine(tid.into(ChatId))
.dmap(toEventChat(s"tournament/$tid"))
)
case (_, Some(sid), _) =>
env.chat.api.userChat.cached.findMine(sid.into(ChatId)).dmap(toEventChat(s"simul/$sid"))
case (_, _, Some(sid)) =>
env.swiss.api
.roundInfo(sid)
.flatMapz(swissC.canHaveChat)
.flatMapz:
env.chat.api.userChat.cached
.findMine(tid.into(ChatId))
.dmap(toEventChat(s"tournament/$tid"))
)
case (_, Some(sid), _) =>
env.chat.api.userChat.cached.findMine(sid.into(ChatId)).dmap(toEventChat(s"simul/$sid"))
case (_, _, Some(sid)) =>
env.swiss.api
.roundInfo(sid)
.flatMapz(swissC.canHaveChat)
.flatMapz:
env.chat.api.userChat.cached
.findMine(sid.into(ChatId))
.dmap(toEventChat(s"swiss/$sid"))
case _ =>
game.hasChat.so:
for
chat <- env.chat.api.playerChat.findIf(game.id.into(ChatId), !game.justCreated)
lines <- lila.chat.JsonView.asyncLines(chat)
yield Chat
.GameOrEvent:
Left:
Chat.Restricted(chat, lines, restricted = game.sourceIs(_.Lobby) && ctx.isAnon)
.some
.findMine(sid.into(ChatId))
.dmap(toEventChat(s"swiss/$sid"))
case _ =>
game.hasChat.so:
for
chat <- env.chat.api.playerChat.findIf(game.id.into(ChatId), !game.justCreated)
lines <- lila.chat.JsonView.asyncLines(chat)
yield Chat
.GameOrEvent:
Left:
Chat.Restricted(chat, lines, restricted = game.sourceIs(_.Lobby) && ctx.isAnon)
.some

def sides(gameId: GameId, color: Color) = Open:
FoundSnip(env.round.proxyRepo.pov(gameId, color)): pov =>
Expand Down
1 change: 1 addition & 0 deletions modules/chat/src/main/ChatUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ final class ChatUi(helpers: Helpers):
"lines" -> lines,
"resourceId" -> resourceId.value
)
.add("kidMode" -> ctx.kid)
.add("hostIds" -> hostIds.some.filter(_.nonEmpty))
.add("userId" -> ctx.userId)
.add("loginRequired" -> chat.loginRequired)
Expand Down
1 change: 1 addition & 0 deletions ui/chat/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface ChatData {
restricted: boolean;
palantir: boolean;
hostIds?: string[];
kidMode: boolean;
}

export interface Line {
Expand Down
13 changes: 11 additions & 2 deletions ui/chat/src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function (ctrl: ChatCtrl): VNode {
return h(
'section.mchat' + (ctrl.opts.alwaysEnabled ? '' : '.mchat-optional'),
{ class: { 'mchat-mod': !!ctrl.moderation }, hook: { destroy: ctrl.destroy } },
moderationView(ctrl.moderation) || normalView(ctrl),
moderationView(ctrl.moderation) || normalView(ctrl) || kidView(ctrl),
);
}

Expand All @@ -40,7 +40,16 @@ function renderPalantir(ctrl: ChatCtrl) {
});
}

function normalView(ctrl: ChatCtrl) {
function kidView(ctrl: ChatCtrl) {
const active = 'note';
return [
h('div.mchat__tabs.nb_1', { attrs: { role: 'tablist' } }, [renderTab(ctrl, 'note', active)]),
h('div.mchat__content.note', ctrl.note ? [noteView(ctrl.note, ctrl.vm.autofocus)] : []),
];
}

function normalView(ctrl: ChatCtrl): VNode[] | undefined {
if (ctrl.data.kidMode) return;
const active = ctrl.vm.tab;
return [
h('div.mchat__tabs.nb_' + ctrl.allTabs.length, { attrs: { role: 'tablist' } }, [
Expand Down
Loading