Skip to content

Commit

Permalink
feat: truncated number of notifications in email
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadadeeltajamul committed Oct 29, 2024
1 parent e8cdb06 commit f3f35ef
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
12 changes: 11 additions & 1 deletion openedx/core/djangoapps/notifications/email/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,29 @@
EMAIL_DIGEST_SENT = "edx.notifications.email_digest"


def send_user_email_digest_sent_event(user, cadence_type, notifications):
def send_user_email_digest_sent_event(user, cadence_type, notifications, message_context):
"""
Sends tracker and segment email for user email digest
"""
notification_breakdown = {key: 0 for key in COURSE_NOTIFICATION_APPS.keys()}
for notification in notifications:
notification_breakdown[notification.app_name] += 1

truncated_count = {}
email_content = message_context.get("email_content", [])
for app in email_content:
truncated_count[app.get("title", "")] = {
"total": app.get("total", -1),
"remaining_count": app.get("remaining_count", -1),
}

event_data = {
"username": user.username,
"email": user.email,
"cadence_type": cadence_type,
"total_notifications_count": len(notifications),
"count_breakdown": notification_breakdown,
"truncated_count": truncated_count,
"notification_ids": [notification.id for notification in notifications],
"send_at": str(datetime.datetime.now())
}
Expand Down
2 changes: 1 addition & 1 deletion openedx/core/djangoapps/notifications/email/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def send_digest_email_to_user(user, cadence_type, start_date, end_date, course_l
).personalize(recipient, course_language, message_context)
message = add_headers_to_email_message(message, message_context)
ace.send(message)
send_user_email_digest_sent_event(user, cadence_type, notifications)
send_user_email_digest_sent_event(user, cadence_type, notifications, message_context)
logger.info(f'<Email Cadence> Email sent to {user.username} ==Temp Log==')


Expand Down
23 changes: 18 additions & 5 deletions openedx/core/djangoapps/notifications/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,29 @@ def create_email_digest_context(app_notifications_dict, username, start_date, en
}
for key, value in app_notifications_dict.items()
])
email_content = [
{

email_content = []
notifications_in_app = 5
for key, value in app_notifications_dict.items():
total = value['count']
app_content = {
'title': value['title'],
'help_text': value.get('help_text', ''),
'help_text_url': value.get('help_text_url', ''),
'notifications': add_additional_attributes_to_notifications(
value.get('notifications', []), courses_data=courses_data
)
),
'total': total,
'show_remaining_count': False,
'remaining_count': 0,
'url': f'{settings.LEARNER_HOME_MICROFRONTEND_URL}/?showNotifications=true&app={key}'
}
for key, value in app_notifications_dict.items()
]
if total > notifications_in_app:
app_content['notifications'] = app_content['notifications'][:notifications_in_app]
app_content['show_remaining_count'] = True
app_content['remaining_count'] = total - notifications_in_app
email_content.append(app_content)

context.update({
"start_date": start_date_str,
"end_date": end_date_str,
Expand Down Expand Up @@ -295,6 +307,7 @@ def filter_notification_with_email_enabled_preferences(notifications, preference
for notification in notifications:
if notification.notification_type in enabled_course_prefs[notification.course_id]:
filtered_notifications.append(notification)
filtered_notifications.sort(key=lambda elem: elem.created, reverse=True)
return filtered_notifications


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,13 @@ <h3 style="font-size: 1.375rem; font-weight:700; line-height:28px; margin: 0.75r
</tbody>
</table>
</p>
<p style="height: 0.75rem; margin: 0;" />
<p style="height: 0.375rem; margin: 0;" />
{% if notification_app.show_remaining_count %}
<p style="margin: 0; height: 0.75rem; font-weight: 400; font-size: 14px; line-height: 24px;">
<a href="{{notification_app.url}}" style="color: #00688d; margin: 0; float:right; text-decoration: none;">
+ {{ notification_app.remaining_count }} more
</a>
</p>
{% endif %}
<p style="height: 0.375rem; margin: 0;" />
{% endfor %}

0 comments on commit f3f35ef

Please sign in to comment.