diff --git a/backend/api/utils/constants.py b/backend/api/utils/constants.py index 0a89daa2..b1945c1d 100644 --- a/backend/api/utils/constants.py +++ b/backend/api/utils/constants.py @@ -22,6 +22,9 @@ ALERT_TO_ADMINS = "d-1808cac1e196446ca8be2ef3ecf93bdb" EVENT_TEMPLATE = "d-5be889d30c0b40aebfa3b569aa5b40f0" NEW_ANNOUNCE_TEMPLATE = "d-a3c4f9ee95544df48d771b8336357ed6" +NEW_GROUPCHAT_TEMPLATE = "d-6edceb23368244a2951b99624920a0bf" +REPLY_GROUPCHAT_TEMPLATE = "d-4027a86a55384ed696a3b812e11f7316" + # This lacks timezone so you'll need to add that according to whatever code you're working with APPT_TIME_FORMAT = "%m-%d-%Y at %I:%M%p" @@ -115,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!", @@ -133,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!", @@ -151,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": "متدرب: لديك رسالة جديدة!", @@ -169,6 +178,8 @@ def __hash__(self): "training_complete": "تهانينا على إتمام التدريب", "app_rejected": "شكرًا لاهتمامك في MENTEE", "profile_complete": "الملف الشخصي لـ MENTEE مكتمل - يرجى تسجيل الدخول", + "new_group_message": "تمت إضافة رسالة دردشة جماعية جديدة.", + "reply_group_message": "تمت إضافة رد جديد على رسالة دردشة جماعية.", }, "fa-AF": { "unread_message": "منتی: شما یک پیام جدید دریافت کرده اید!", @@ -187,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 f46a16c5..c3bb7b6c 100644 --- a/backend/api/views/notifications.py +++ b/backend/api/views/notifications.py @@ -9,6 +9,8 @@ WEEKLY_NOTIF_REMINDER, UNREAD_MESSAGE_TEMPLATE, GROUPCHAT_TAGGED_MESSAGE_TEMPLATE, + NEW_GROUPCHAT_TEMPLATE, + REPLY_GROUPCHAT_TEMPLATE, TRANSLATIONS, ) from api.utils.require_auth import all_users @@ -67,6 +69,10 @@ def get_unread_dm_count(id): @notifications.route("/unread_alert_group/", methods=["GET"]) def send_unread_alert_group(id): + tagged = request.args.get("tagged") + new_message_flag = request.args.get("new_message_flag") + front_url = request.args.get("front_url", "") + title = request.args.get("title", "") try: email = None user_record = PartnerProfile.objects(Q(id=id)).first() @@ -77,20 +83,52 @@ def send_unread_alert_group(id): if user_record is not None: email = user_record.email if user_record is not None: - res, res_msg = send_email( - recipient=email, - data={ - "number_unread": "1", - user_record.preferred_language: True, - "subject": TRANSLATIONS[user_record.preferred_language][ - "unread_message" - ], - }, - template_id=GROUPCHAT_TAGGED_MESSAGE_TEMPLATE, - ) - if not res: - msg = "Failed to send unread message alert email " + res_msg - logger.info(msg) + if tagged == "true": + res, res_msg = send_email( + recipient=email, + data={ + "number_unread": "1", + user_record.preferred_language: True, + "subject": TRANSLATIONS[user_record.preferred_language][ + "unread_message" + ], + }, + template_id=GROUPCHAT_TAGGED_MESSAGE_TEMPLATE, + ) + if not res: + msg = "Failed to send unread message alert email " + res_msg + logger.info(msg) + if new_message_flag == "true": + res, res_msg = send_email( + recipient=email, + data={ + "link": front_url, + "group_chat_title": title, + "subject": TRANSLATIONS[user_record.preferred_language][ + "new_group_message" + ], + }, + template_id=NEW_GROUPCHAT_TEMPLATE, + ) + if not res: + msg = "Failed to send new group message alert email " + res_msg + logger.info(msg) + else: + res, res_msg = send_email( + recipient=email, + data={ + "link": front_url, + "title": title, + "subject": TRANSLATIONS[user_record.preferred_language][ + "reply_group_message" + ], + }, + template_id=REPLY_GROUPCHAT_TEMPLATE, + ) + if not res: + msg = "Failed to send reply group message alert email " + res_msg + logger.info(msg) + except Exception as e: logger.info(e) return create_response(status=422, message="failed") diff --git a/frontend/src/components/GroupMessageChatArea.js b/frontend/src/components/GroupMessageChatArea.js index 58178231..80c58976 100644 --- a/frontend/src/components/GroupMessageChatArea.js +++ b/frontend/src/components/GroupMessageChatArea.js @@ -177,7 +177,7 @@ function GroupMessageChatArea(props) { setTimeout(() => { particiants.forEach((user) => { if (user._id.$oid !== profileId) { - // sendNotifyGroupMessage(user._id.$oid, false); + sendNotifyGroupMessage(user._id.$oid, messageTitle.trim(), false); } }); }, 0); @@ -185,7 +185,7 @@ function GroupMessageChatArea(props) { } else { tagUsers.map((tag_id) => { if (tag_id !== profileId) { - sendNotifyGroupMessage(tag_id, true); + sendNotifyGroupMessage(tag_id, messageTitle.trim(), true); } return false; }); @@ -223,7 +223,7 @@ function GroupMessageChatArea(props) { setEditInputFlags({}); }; - const sendReplyMessage = (block_id) => { + const sendReplyMessage = (block_id, block_title, sender_id) => { let currentMessage = replyMessageText; if (!currentMessage.trim().length > 0) { let temp = replyInputFlags; @@ -268,20 +268,12 @@ function GroupMessageChatArea(props) { if (tagUsers.length > 0) { tagUsers.map((tag_id) => { if (tag_id !== profileId) { - sendNotifyGroupMessage(tag_id, true); + sendNotifyGroupMessage(tag_id, block_title, true, false); } return false; }); } else { - if (particiants?.length > 0) { - setTimeout(() => { - particiants.forEach((user) => { - if (user._id.$oid !== profileId) { - // sendNotifyGroupMessage(user._id.$oid, false); - } - }); - }, 0); - } + sendNotifyGroupMessage(sender_id, block_title, false, false); } setTagUsers([]); }; @@ -794,7 +786,13 @@ function GroupMessageChatArea(props) { )}