From 458598b1cb325630240cdd2d8a506031d7838d41 Mon Sep 17 00:00:00 2001 From: Phuoc Anh Kha Le <76896393+anhkha2003@users.noreply.github.com> Date: Sun, 28 Jan 2024 22:22:57 -0600 Subject: [PATCH] Fix bug comparing latest message in room chat (#106) --- 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]