Skip to content

Commit

Permalink
refactor: [AXM-252] add extra context to push notification
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedielnitsevIvan committed Apr 29, 2024
1 parent 3d2f05d commit c26c26e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions lms/djangoapps/discussion/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def create_message_context(comment, site):
'course_id': str(thread.course_id),
'comment_id': comment.id,
'comment_body': comment.body,
'comment_body_text': comment.body_text,
'comment_author_id': comment.user_id,
'comment_created_at': comment.created_at, # comment_client models dates are already serialized
'thread_id': thread.id,
Expand Down
7 changes: 5 additions & 2 deletions lms/djangoapps/discussion/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ def _build_message_context(context): # lint-amnesty, pylint: disable=missing-fu
'thread_username': thread_author.username,
'comment_username': comment_author.username,
'post_link': post_link,
'click_action': post_link,
'send_push_notification': True,
'push_notification_extra_context': {
'notification_type': 'forum_comment',
'thread_id': context['thread_id'],
'comment_id': context['comment_id'],
},
'comment_created_at': date.deserialize(context['comment_created_at']),
'thread_created_at': date.deserialize(context['thread_created_at'])
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{% load i18n %}

{% block content %}
{% blocktrans trimmed %}
{{ comment_username }} replied to <b>{{ thread_title }}</b>:
{% endblocktrans %}
{{ comment_body }}
{% endblock %}
{% blocktrans trimmed %}{{ comment_username }} replied to {{ thread_title }}:{% endblocktrans %}
{{ comment_body_text }}
8 changes: 7 additions & 1 deletion lms/djangoapps/discussion/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def test_send_discussion_email_notification(self, user_subscribed):
expected_message_context.update({
'comment_author_id': self.comment_author.id,
'comment_body': comment['body'],
'comment_body_text': comment.body_text,
'comment_created_at': ONE_HOUR_AGO,
'comment_id': comment['id'],
'comment_username': self.comment_author.username,
Expand All @@ -283,7 +284,12 @@ def test_send_discussion_email_notification(self, user_subscribed):
'thread_commentable_id': thread['commentable_id'],
'post_link': f'https://{site.domain}{self.mock_permalink.return_value}',
'site': site,
'site_id': site.id
'site_id': site.id,
'push_notification_extra_context': {
'notification_type': 'forum_comment',
'thread_id': thread['id'],
'comment_id': comment['id'],
},
})
expected_recipient = Recipient(self.thread_author.id, self.thread_author.email)
actual_message = self.mock_ace_send.call_args_list[0][0][0]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pylint: disable=missing-docstring,protected-access

from bs4 import BeautifulSoup

from openedx.core.djangoapps.django_comment_common.comment_client import models, settings

Expand Down Expand Up @@ -99,6 +99,14 @@ def unFlagAbuse(self, user, voteable, removeAll):
)
voteable._update_from_response(response)

@property
def body_text(self):
"""
Return the text content of the comment html body.
"""
soup = BeautifulSoup(self.body, 'html.parser')
return soup.get_text()


def _url_for_thread_comments(thread_id):
return f"{settings.PREFIX}/threads/{thread_id}/comments"
Expand Down

0 comments on commit c26c26e

Please sign in to comment.