From 8f0b2ea9c36283370a22c03dc47de6d371ea752c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 10 Sep 2022 11:31:51 +0200 Subject: [PATCH] test on devrama --- files/assets/js/chat.js | 17 +++++++++++++++++ files/routes/chat.py | 15 ++++++++++++++- files/templates/chat.html | 8 +++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/files/assets/js/chat.js b/files/assets/js/chat.js index 4e636d176..ec773543d 100644 --- a/files/assets/js/chat.js +++ b/files/assets/js/chat.js @@ -187,6 +187,23 @@ socket.on('typing', function (users){ } }) + +function del(t) { + t.parentElement.parentElement.parentElement.parentElement.parentElement.remove() + const text = t.previousElementSibling.previousElementSibling.innerHTML + socket.emit('delete', text); +} + +socket.on('delete', function(text) { + const text_spans = document.getElementsByClassName('text') + for(const span of text_spans) { + if (span.innerHTML == text) + { + span.parentElement.parentElement.parentElement.parentElement.parentElement.remove() + } + } +}) + function scroll_chat() { setTimeout(function () { box.scrollTo(0, box.scrollHeight) diff --git a/files/routes/chat.py b/files/routes/chat.py index 307b33eb3..ffe513b4a 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -1,5 +1,5 @@ import time -from files.helpers.wrappers import auth_required +from files.helpers.wrappers import * from files.helpers.sanitize import sanitize from files.helpers.const import * from files.helpers.alerts import * @@ -133,6 +133,19 @@ def typing_indicator(data, v): return '', 204 +@socketio.on('delete') +@admin_level_required(2) +def delete(text, v): + + for message in messages: + if message['text'] == text: + messages.remove(message) + + emit('delete', text, broadcast=True) + + return '', 204 + + def close_running_threads(): cache.set(f'{SITE}_chat', messages) cache.set(f'{SITE}_total', total) diff --git a/files/templates/chat.html b/files/templates/chat.html index 6d5e456f2..1645e2859 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -149,6 +149,9 @@ + {% if v.admin_level > 1 %} + + {% endif %} @@ -182,8 +185,11 @@
{{text_html | safe}} - {{m['text']}} + {{m['text']}} + {% if v.admin_level > 1 %} + + {% endif %}