From bb654a998b18fb23904d0c23ae628725150b0a97 Mon Sep 17 00:00:00 2001 From: Arijan Date: Tue, 3 Jun 2025 00:12:42 +0800 Subject: [PATCH] fix group notification --- backend/api/utils/constants.py | 10 ++++++++++ backend/api/views/notifications.py | 6 ++++++ .../src/components/GroupMessageChatArea.js | 18 +++++++----------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/backend/api/utils/constants.py b/backend/api/utils/constants.py index c5ba0fab..b1945c1d 100644 --- a/backend/api/utils/constants.py +++ b/backend/api/utils/constants.py @@ -118,6 +118,8 @@ def __hash__(self): "training_complete": "Congratulations for completing the training", "app_rejected": "Thank you for your interest in MENTEE", "profile_complete": "MENTEE Profile Completed - Please login", + "new_group_message": "A new group chat message was added !", + "reply_group_message": "A new reply has been added to a group chat message !", }, "es-US": { "unread_message": "MENTEE: ¡Has recibido un nuevo mensaje!", @@ -136,6 +138,8 @@ def __hash__(self): "training_complete": "Felicitaciones por completar la capacitación", "app_rejected": "Gracias por tu interés en MENTEE", "profile_complete": "Perfil de MENTEE completado: por favor, inicia sesión", + "new_group_message": "Se agregó un nuevo mensaje de chat grupal.", + "reply_group_message": "Se agregó una nueva respuesta a un mensaje de chat grupal.", }, "pt-BR": { "unread_message": "MENTEE: Você recebeu uma nova mensagem!", @@ -154,6 +158,8 @@ def __hash__(self): "training_complete": "Parabéns por concluir o treinamento", "app_rejected": "Obrigado pelo seu interesse em MENTEE", "profile_complete": "Perfil de MENTEE completo - Faça login, por favor", + "new_group_message": "Uma nova mensagem de bate-papo em grupo foi adicionada", + "reply_group_message": "Uma nova resposta foi adicionada a uma mensagem de bate-papo em grupo", }, "ar": { "unread_message": "متدرب: لديك رسالة جديدة!", @@ -172,6 +178,8 @@ def __hash__(self): "training_complete": "تهانينا على إتمام التدريب", "app_rejected": "شكرًا لاهتمامك في MENTEE", "profile_complete": "الملف الشخصي لـ MENTEE مكتمل - يرجى تسجيل الدخول", + "new_group_message": "تمت إضافة رسالة دردشة جماعية جديدة.", + "reply_group_message": "تمت إضافة رد جديد على رسالة دردشة جماعية.", }, "fa-AF": { "unread_message": "منتی: شما یک پیام جدید دریافت کرده اید!", @@ -190,6 +198,8 @@ def __hash__(self): "training_complete": "تبریک بابت تکمیل آموزش", "app_rejected": "از علاقه‌مندی شما در منتی سپاسگزاریم", "profile_complete": "پروفایل منتی کامل شده است - لطفا وارد شوید", + "new_group_message": "یک پیام جدید به چت گروهی اضافه شد", + "reply_group_message": "پاسخ جدیدی به یک پیام چت گروهی اضافه شد", }, } diff --git a/backend/api/views/notifications.py b/backend/api/views/notifications.py index 6f99d1fc..c3bb7b6c 100644 --- a/backend/api/views/notifications.py +++ b/backend/api/views/notifications.py @@ -104,6 +104,9 @@ def send_unread_alert_group(id): data={ "link": front_url, "group_chat_title": title, + "subject": TRANSLATIONS[user_record.preferred_language][ + "new_group_message" + ], }, template_id=NEW_GROUPCHAT_TEMPLATE, ) @@ -116,6 +119,9 @@ def send_unread_alert_group(id): data={ "link": front_url, "title": title, + "subject": TRANSLATIONS[user_record.preferred_language][ + "reply_group_message" + ], }, template_id=REPLY_GROUPCHAT_TEMPLATE, ) diff --git a/frontend/src/components/GroupMessageChatArea.js b/frontend/src/components/GroupMessageChatArea.js index e72d731f..80c58976 100644 --- a/frontend/src/components/GroupMessageChatArea.js +++ b/frontend/src/components/GroupMessageChatArea.js @@ -223,7 +223,7 @@ function GroupMessageChatArea(props) { setEditInputFlags({}); }; - const sendReplyMessage = (block_id, block_title) => { + const sendReplyMessage = (block_id, block_title, sender_id) => { let currentMessage = replyMessageText; if (!currentMessage.trim().length > 0) { let temp = replyInputFlags; @@ -273,15 +273,7 @@ function GroupMessageChatArea(props) { return false; }); } else { - if (particiants?.length > 0) { - setTimeout(() => { - particiants.forEach((user) => { - if (user._id.$oid !== profileId) { - sendNotifyGroupMessage(user._id.$oid, block_title, false, false); - } - }); - }, 0); - } + sendNotifyGroupMessage(sender_id, block_title, false, false); } setTagUsers([]); }; @@ -795,7 +787,11 @@ function GroupMessageChatArea(props) { )}