From bb67d58eddb22937d4f358b6ef42ccc335a97327 Mon Sep 17 00:00:00 2001 From: anhkha2003 Date: Sun, 28 Jan 2024 21:16:21 -0600 Subject: [PATCH] Fix bug comparing latest message in room chat --- chat_box/views.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/chat_box/views.py b/chat_box/views.py index e472b56..34dcfe5 100644 --- a/chat_box/views.py +++ b/chat_box/views.py @@ -181,15 +181,13 @@ def check_valid_message(request, room): if not can_access_room(request, room) or request.profile.mute: return False - try: - last_msg = Message.objects.filter(room=room).first() - if ( - last_msg.author == request.profile - and last_msg.body == request.POST["body"].strip() - ): - return False - except Message.DoesNotExist: - pass + last_msg = Message.objects.filter(room=room).first() + if ( + last_msg + and last_msg.author == request.profile + and last_msg.body == request.POST["body"].strip() + ): + return False if not room: four_last_msg = Message.objects.filter(room=room).order_by("-id")[:4]