From 7a25ee30911053d82fc81153e9e89b89a4639259 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Wed, 25 Dec 2024 16:19:39 -0800 Subject: [PATCH] Ban Modal + Reported Reason Update the Ban button shown to admins in the Profile Modal: * Now displays a modal for the admin to enter a reason and select the duration (1-96 hours). * Along with the ban, the reason is posted to your main website as an admin report so you can log which chat admin banned which user and the reason given. --- src/App.vue | 6 +++ src/components/ProfileModal.vue | 83 ++++++++++++++++++++++++++++++--- 2 files changed, 83 insertions(+), 6 deletions(-) diff --git a/src/App.vue b/src/App.vue index 7ff5dc0..baf4b73 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3838,6 +3838,11 @@ export default { // Set the "reported" flag. this.reportModal.origMessage.reported = true; }, + doCustomReport({ message, classification, comment }) { + // A fully custom report, e.g. for the Ban Modal. + this.reportModal.message = message; + this.doReport({ classification, comment }); + }, } }; @@ -4558,6 +4563,7 @@ export default { @mute-user="muteUser" @boot-user="bootUser" @send-command="sendCommand" + @report="doCustomReport" @cancel="profileModal.visible = false">
diff --git a/src/components/ProfileModal.vue b/src/components/ProfileModal.vue index 17cc654..211eee0 100644 --- a/src/components/ProfileModal.vue +++ b/src/components/ProfileModal.vue @@ -22,6 +22,11 @@ export default { // Profile data profileFields: [], + // Ban account data + banModalVisible: false, + banReason: "", + banDuration: 24, + // Error messaging from backend error: null, }; @@ -148,13 +153,37 @@ export default { this.$emit('send-command', `/kick ${this.user.username}`); }, banUser() { - let hours = window.prompt( - "Ban this user for how many hours? (Default 24)", - "24", - ); - if (!/^\d+$/.test(hours)) return; + this.banModalVisible = true; + this.banReason = ""; + this.banDuration = 24; + window.requestAnimationFrame(() => { + let reason = document.querySelector("#ban_reason"); + if (reason) { + reason.focus(); + } + }); + }, + confirmBan() { + // Send the ban command. + this.$emit('send-command', `/ban ${this.user.username} ${this.banDuration}`); - this.$emit('send-command', `/ban ${this.user.username} ${hours}`); + // Also send an admin report to the main website. + this.$emit('report', { + message: { + channel: `n/a`, + username: this.user.username, + at: new Date(), + message: 'Ban reason: ' + this.banReason, + }, + classification: 'User banned by admin', + comment: `A chat admin has banned ${this.user.username} from the chat room!\n\n` + + `* Chat admin: ${this.username}\n` + + `* Reason: ${this.banReason}\n` + + `* Duration: ${this.banDuration} hours`, + }); + + this.banModalVisible = false; + this.cancel(); }, urlFor(url) { @@ -338,6 +367,48 @@ export default {
+ + +