Skip to content

Commit

Permalink
Moderate replies (#1131)
Browse files Browse the repository at this point in the history
Add TS logic to handle reply moderation
  • Loading branch information
MatthiasReumann authored and SebiWrn committed May 7, 2024
1 parent 0a97c6a commit 09eee32
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dao/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (d chatDao) GetReactions(chatID uint) ([]model.ChatReaction, error) {
func (d chatDao) GetVisibleChats(userID uint, streamID uint) ([]model.Chat, error) {
var chats []model.Chat
query := DB.
Preload("Replies").
Preload("Replies", "(visible = 1) OR (user_id = ?)", userID).
Preload("Reactions").
Preload("AddressedToUsers").
Where("(visible = 1) OR (user_id = ?)", userID).
Expand Down
41 changes: 26 additions & 15 deletions web/template/components/chat.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@
<span x-show="m.admin"
class="fa-video text-white bg-red-400 p-1 rounded fas"></span>
<span class="text-2 font-semibold" x-text="m.name" :style="'color:'+m.color"></span>
<span x-show="!m.visible" class="text-5 font-light">
This message is currently only visible to you and admins.
</span>
<span x-show="!m.visible" class="text-5 font-light">This message is currently only visible to you and admins.</span>
</div>
<div class="relative group p-2 rounded hover:bg-gray-100 dark:hover:bg-gray-600">
<div class="flex justify-between">
Expand Down Expand Up @@ -190,26 +188,39 @@


<!-- replies -->
<div x-cloak x-show="m.ShowReplies.value"
class="grid gap-y-3 py-1 pl-2 mt-2 ml-4 border-l-2 dark:border-secondary-light">
<article x-cloak x-show="m.ShowReplies.value"
class="grid gap-y-3 py-1 pl-2 mt-2 ml-4 border-l-2 dark:border-secondary-light">
<template x-for="reply in m.replies">
<div class="grid gap-y-1">
<section class="grid gap-y-1">
<div>
<span x-show="reply.admin"
class="text-white bg-red-400 p-1 text-xs rounded fas fa-video"></span>
<span x-show="reply.admin"
class="text-white bg-red-400 p-1 text-xs rounded fas fa-video"></span>
<span class="text-2 font-semibold" x-text="reply.name"
:style="'color:'+reply.color"></span>
<span x-show="!reply.visible" class="text-xs text-5 font-light">This message is currently only visible to you and admins.</span>
</div>
<div class="group p-2 rounded hover:bg-gray-100 dark:hover:bg-gray-700">
<div class="flex justify-between">
<span class="w-5/6 overflow-wrap-anywhere my-auto" x-html="reply.message"></span>
<span class="hidden group-hover:inline text-xs text-5 font-light mt-auto"
x-text="reply.friendlyCreatedAt()"></span>
<div class="flex">
<div class="group p-2 rounded hover:bg-gray-100 dark:hover:bg-gray-700 flex-grow">
<div class="flex justify-between">
<span class="w-5/6 overflow-wrap-anywhere my-auto" x-html="reply.message"></span>
<span class="hidden group-hover:inline text-xs text-5 font-light mt-auto"
x-text="reply.friendlyCreatedAt()"></span>
</div>
</div>
{{if $course.ModeratedChatEnabled}}
<template x-if="isAdmin()">
<button x-cloak x-show="!reply.visible"
@click="approveMessage(reply.ID)"
title="Approve Message"
class="tum-live-icon-button shrink mx-2">
<i class="fa-solid fa-spell-check"></i>
</button>
</template>
{{end}}
</div>
</div>
</section>
</template>
</div>
</article>
</section>
</template>
</div>
Expand Down
7 changes: 7 additions & 0 deletions web/ts/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export class ChatMessageArray {
this.messages = filtered;
}

approveReply(m: ChatMessage) {
const base = this.messages.find((msg) => msg.ID === m.replyTo.Int64);
const filtered = base.replies.filter((msg) => msg.ID !== m.ID);
filtered.push(Object.assign(new ChatMessage(), m));
base.replies = filtered;
}

retract(msg: ChatMessage, isAdmin: boolean) {
if (isAdmin) {
this.messages.find((m) => m.ID === msg.ID).visible = false;
Expand Down
3 changes: 2 additions & 1 deletion web/ts/components/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ export function chatContext(streamId: number, user: User, isRecording: boolean):

handleApprove(msg: ChatMessage) {
this.preprocessors.forEach((f) => f(msg, this.user));
this.messages.approve(msg);
if (msg.replyTo.Valid) this.messages.approveReply(msg);
else this.messages.approve(msg);
},

handleRetract(msg: ChatMessage) {
Expand Down

0 comments on commit 09eee32

Please sign in to comment.