Skip to content

🙆‍♂️ update group message notification #1296

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 4 commits into from
May 29, 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
3 changes: 3 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
60 changes: 46 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,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")
Expand Down
14 changes: 8 additions & 6 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) => {
let currentMessage = replyMessageText;
if (!currentMessage.trim().length > 0) {
let temp = replyInputFlags;
Expand Down Expand Up @@ -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;
});
Expand All @@ -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);
Expand Down Expand Up @@ -794,7 +794,9 @@ function GroupMessageChatArea(props) {
</div>
)}
<Button
onClick={() => sendReplyMessage(block._id.$oid)}
onClick={() =>
sendReplyMessage(block._id.$oid, block.title)
}
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