Skip to content

Commit

Permalink
feat: [AXM-271] Add push notification event to discussions (#2548)
Browse files Browse the repository at this point in the history
* feat: [AXM-271] Add push notification event to discussions

* refactor: [AXM-252] add extra context to push notification
  • Loading branch information
NiedielnitsevIvan committed May 27, 2024
1 parent 97392f5 commit 874e9c4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 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
5 changes: 5 additions & 0 deletions lms/djangoapps/discussion/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +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,
'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
@@ -0,0 +1,3 @@
{% load i18n %}
{% blocktrans trimmed %}{{ comment_username }} replied to {{ thread_title }}:{% endblocktrans %}
{{ comment_body_text }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% load i18n %}

{% blocktrans %}Response to {{ thread_title }}{% endblocktrans %}
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 874e9c4

Please sign in to comment.