Skip to content

👨🏽‍🍳 update group message notification #1297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions backend/api/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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!",
Expand All @@ -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!",
Expand All @@ -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": "متدرب: لديك رسالة جديدة!",
Expand All @@ -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": "منتی: شما یک پیام جدید دریافت کرده اید!",
Expand All @@ -187,6 +198,8 @@ def __hash__(self):
"training_complete": "تبریک بابت تکمیل آموزش",
"app_rejected": "از علاقه‌مندی شما در منتی سپاسگزاریم",
"profile_complete": "پروفایل منتی کامل شده است - لطفا وارد شوید",
"new_group_message": "یک پیام جدید به چت گروهی اضافه شد",
"reply_group_message": "پاسخ جدیدی به یک پیام چت گروهی اضافه شد",
},
}

Expand Down
66 changes: 52 additions & 14 deletions backend/api/views/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,6 +69,10 @@ def get_unread_dm_count(id):

@notifications.route("/unread_alert_group/<id>", 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()
Expand All @@ -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")
Expand Down
26 changes: 12 additions & 14 deletions frontend/src/components/GroupMessageChatArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ 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);
}
} else {
tagUsers.map((tag_id) => {
if (tag_id !== profileId) {
sendNotifyGroupMessage(tag_id, true);
sendNotifyGroupMessage(tag_id, messageTitle.trim(), true);
}
return false;
});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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([]);
};
Expand Down Expand Up @@ -794,7 +786,13 @@ function GroupMessageChatArea(props) {
</div>
)}
<Button
onClick={() => sendReplyMessage(block._id.$oid)}
onClick={() =>
sendReplyMessage(
block._id.$oid,
block.title,
block.sender_id.$oid
)
}
className="reply-message-send-button"
shape="circle"
type="primary"
Expand Down
16 changes: 14 additions & 2 deletions frontend/src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,9 +741,21 @@ export const fetchAvailability = (id) => {
);
};

export const sendNotifyGroupMessage = (recipient_id, tagged = false) => {
export const sendNotifyGroupMessage = (
recipient_id,
title,
tagged = true,
new_message_flag = true
) => {
const requestExtension = `/notifications/unread_alert_group/${recipient_id}`;
return authGet(requestExtension, { params: { tagged: tagged } }).then(
return authGet(requestExtension, {
params: {
title: title,
tagged: tagged,
new_message_flag: new_message_flag,
front_url: window.location.href,
},
}).then(
(response) => response.message,
(err) => {
console.error(err);
Expand Down