Allow author deletes chat

This commit is contained in:
cuom1999 2024-08-13 22:10:25 +07:00
parent 34e8ac6b8e
commit 1f91299d41
3 changed files with 38 additions and 29 deletions

View file

@ -37,6 +37,8 @@ from judge.models import Friend
from chat_box.models import Message, Profile, Room, UserRoom, Ignore, get_room_info
from chat_box.utils import encrypt_url, decrypt_url, encrypt_channel, get_unread_boxes
from reversion import revisions
class ChatView(ListView):
context_object_name = "message"
@ -137,15 +139,15 @@ def delete_message(request):
if request.method == "GET":
return HttpResponseBadRequest()
if not request.user.is_staff:
return HttpResponseBadRequest()
try:
messid = int(request.POST.get("message"))
mess = Message.objects.get(id=messid)
except:
return HttpResponseBadRequest()
if not request.user.is_staff and request.profile != mess.author:
return HttpResponseBadRequest()
mess.hidden = True
mess.save()
@ -167,8 +169,12 @@ def mute_message(request):
except:
return HttpResponseBadRequest()
with revisions.create_revision():
revisions.set_comment(_("Mute chat") + ": " + mess.body)
revisions.set_user(request.user)
mess.author.mute = True
mess.author.save()
Message.objects.filter(room=None, author=mess.author).update(hidden=True)
return JsonResponse(ret)

View file

@ -411,7 +411,6 @@
scrollContainer($('#chat-box'), $('#loader'))
{% if request.user.is_staff %}
$(document).on("click", ".chat_remove", function() {
var elt = $(this);
$.ajax({
@ -435,6 +434,8 @@
},
});
});
{% if request.user.is_staff %}
$(document).on("click", ".chat_mute", function() {
if (confirm("{{_('Mute this user and delete all messages?')}}")) {
var elt = $(this);

View file

@ -15,10 +15,12 @@
</div>
<span class="content-message">
<div class="body-block" id="body-block-{{ message.id }}" title="{{ message.time|date('g:i a') }}">
{% if request.user.is_staff %}
{% if request.user.is_staff or request.profile == message.author %}
<a class="red chatbtn_remove_mess chat_remove" value="{{message.id}}" style="cursor: pointer;">
{{_('Delete')}}
</a>
{% endif %}
{% if request.user.is_staff and request.profile != message.author %}
<a class="red chatbtn_remove_mess chat_mute" value="{{message.id}}" style="cursor: pointer;">
{{_('Mute')}}
</a>