From f3c360933021211db32db462e6019cf1b90e6d96 Mon Sep 17 00:00:00 2001 From: Arijan Date: Wed, 28 May 2025 10:42:48 +0800 Subject: [PATCH 1/2] update group message notification --- backend/api/utils/constants.py | 3 + backend/api/views/notifications.py | 60 ++++++++++++++----- .../src/components/GroupMessageChatArea.js | 14 +++-- frontend/src/utils/api.js | 16 ++++- 4 files changed, 71 insertions(+), 22 deletions(-) diff --git a/backend/api/utils/constants.py b/backend/api/utils/constants.py index 0a89daa28..c5ba0fab7 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" diff --git a/backend/api/views/notifications.py b/backend/api/views/notifications.py index f46a16c5a..6f99d1fc0 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,46 @@ 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, + }, + 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, + }, + 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 581782312..e72d731f1 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) => { let currentMessage = replyMessageText; if (!currentMessage.trim().length > 0) { let temp = replyInputFlags; @@ -268,7 +268,7 @@ 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; }); @@ -277,7 +277,7 @@ function GroupMessageChatArea(props) { setTimeout(() => { particiants.forEach((user) => { if (user._id.$oid !== profileId) { - // sendNotifyGroupMessage(user._id.$oid, false); + sendNotifyGroupMessage(user._id.$oid, block_title, false, false); } }); }, 0); @@ -794,7 +794,9 @@ function GroupMessageChatArea(props) { )}