Skip to content

🧁 req#5 #1221

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 19 commits into from
Feb 17, 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
35 changes: 34 additions & 1 deletion backend/api/views/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,39 @@ def get_unread_dm_count(id):
return create_response(data={"notifications": unread_message_number})


@notifications.route("/unread_alert_group/<id>", methods=["GET"])
def send_unread_alert_group(id):
try:
email = None
user_record = PartnerProfile.objects(Q(id=id)).first()
if user_record is not None:
email = user_record.email
else:
user_record = Hub.objects(Q(id=id)).first()
if user_record is not None:
email = user_record.email
if (user_record is not None) and user_record.email_notifications:
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)
except Exception as e:
logger.info(e)
return create_response(status=422, message="failed")

return create_response(status=200, message="Success")


@notifications.route("/unread_alert/<id>", methods=["GET"])
# @all_users
def send_unread_alert(id):
Expand Down Expand Up @@ -103,7 +136,7 @@ def send_unread_alert(id):
"unread_message"
],
},
template_id=GROUPCHAT_TAGGED_MESSAGE_TEMPLATE,
template_id=UNREAD_MESSAGE_TEMPLATE,
)
if not res:
msg = "Failed to send unread message alert email " + res_msg
Expand Down
19 changes: 5 additions & 14 deletions frontend/src/components/GroupMessageChatArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SendOutlined } from "@ant-design/icons";
import EmojiPicker from "emoji-picker-react";
import { useAuth } from "utils/hooks/useAuth";
import {
sendNotifyUnreadMessage,
sendNotifyGroupMessage,
downloadBlob,
getLibraryFile,
} from "utils/api";
Expand Down Expand Up @@ -173,15 +173,15 @@ function GroupMessageChatArea(props) {
setTimeout(() => {
particiants.forEach((user) => {
if (user._id.$oid !== profileId) {
sendNotifyUnreadMessage(user._id.$oid);
// sendNotifyGroupMessage(user._id.$oid, false);
}
});
}, 0);
}
} else {
tagUsers.map((tag_id) => {
if (tag_id !== profileId) {
sendNotifyUnreadMessage(tag_id);
sendNotifyGroupMessage(tag_id, true);
}
return false;
});
Expand All @@ -197,15 +197,6 @@ function GroupMessageChatArea(props) {
temp[block_id] = false;
setReplyInputFlags(temp);
setRefreshFlag(!refreshFlag);
setTagUsers([]);
if (tagUsers.length > 0) {
tagUsers.map((tag_id) => {
if (tag_id !== profileId) {
sendNotifyUnreadMessage(tag_id);
}
return false;
});
}
return;
}

Expand Down Expand Up @@ -247,7 +238,7 @@ function GroupMessageChatArea(props) {
if (tagUsers.length > 0) {
tagUsers.map((tag_id) => {
if (tag_id !== profileId) {
sendNotifyUnreadMessage(tag_id);
sendNotifyGroupMessage(tag_id, true);
}
return false;
});
Expand All @@ -256,7 +247,7 @@ function GroupMessageChatArea(props) {
setTimeout(() => {
particiants.forEach((user) => {
if (user._id.$oid !== profileId) {
sendNotifyUnreadMessage(user._id.$oid);
// sendNotifyGroupMessage(user._id.$oid, false);
}
});
}, 0);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/MessagesChatArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ function MessagesChatArea(props) {
{accountData && (
<>
<TextArea
style={{ width: "calc(100% - 220px" }}
className="message-input"
placeholder={t("messages.sendMessagePlaceholder")}
value={messageText}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/css/Messages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
}

.conversation-footer {
display: flex;
position: relative;
padding: 16px;
border-top: 1px solid #e8e8e8;
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,16 @@ export const fetchAvailability = (id) => {
);
};

export const sendNotifyGroupMessage = (recipient_id, tagged = false) => {
const requestExtension = `/notifications/unread_alert_group/${recipient_id}`;
return authGet(requestExtension, { params: { tagged: tagged } }).then(
(response) => response.message,
(err) => {
console.error(err);
}
);
};

export const sendNotifyUnreadMessage = (recipient_id) => {
const requestExtension = `/notifications/unread_alert/${recipient_id}`;
return authGet(requestExtension).then(
Expand Down