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

Moderate replies #1131

Merged
merged 9 commits into from
Sep 8, 2023
Merged
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
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