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 @@