Commit 02ab4a03 by Aamish Baloch Committed by GitHub

Merge pull request #16146 from edx/aamishbaloch/YONK-776

YONK-776: added thread_followed and thread_unfollowed signals
parents 4a1e8af7 7c3dab08
......@@ -7,6 +7,8 @@ thread_created = Signal(providing_args=['user', 'post'])
thread_edited = Signal(providing_args=['user', 'post'])
thread_voted = Signal(providing_args=['user', 'post'])
thread_deleted = Signal(providing_args=['user', 'post'])
thread_followed = Signal(providing_args=['user', 'post'])
thread_unfollowed = Signal(providing_args=['user', 'post'])
comment_created = Signal(providing_args=['user', 'post'])
comment_edited = Signal(providing_args=['user', 'post'])
comment_voted = Signal(providing_args=['user', 'post'])
......
......@@ -510,6 +510,23 @@ class ViewsTestCase(
# create_thread_helper verifies that extra data are passed through to the comments service
self.create_thread_helper(mock_request, extra_response_data={'context': ThreadContext.STANDALONE})
@ddt.data(
('follow_thread', 'thread_followed'),
('unfollow_thread', 'thread_unfollowed'),
)
@ddt.unpack
def test_follow_unfollow_thread_signals(self, view_name, signal, mock_request):
self.create_thread_helper(mock_request)
with self.assert_discussion_signals(signal):
response = self.client.post(
reverse(
view_name,
kwargs={"course_id": unicode(self.course_id), "thread_id": 'i4x-MITx-999-course-Robot_Super_Course'}
)
)
self.assertEqual(response.status_code, 200)
def test_delete_thread(self, mock_request):
self._set_mock_request_data(mock_request, {
"user_id": str(self.student.id),
......
......@@ -42,7 +42,9 @@ from django_comment_common.signals import (
thread_created,
thread_deleted,
thread_edited,
thread_voted
thread_voted,
thread_followed,
thread_unfollowed,
)
from django_comment_common.utils import ThreadContext
import eventtracking
......@@ -291,6 +293,7 @@ def create_thread(request, course_id, commentable_id):
if follow:
cc_user = cc.User.from_django_user(user)
cc_user.follow(thread)
thread_followed.send(sender=None, user=user, post=thread)
data = thread.to_dict()
......@@ -525,6 +528,7 @@ def _vote_or_unvote(request, course_id, obj, value='up', undo_vote=False):
# (People could theoretically downvote by handcrafting AJAX requests.)
else:
user.vote(obj, value)
thread_voted.send(sender=None, user=request.user, post=obj)
track_voted_event(request, course, obj, value, undo_vote)
return JsonResponse(prepare_content(obj.to_dict(), course_key))
......@@ -563,7 +567,6 @@ def vote_for_thread(request, course_id, thread_id, value):
"""
thread = cc.Thread.find(thread_id)
result = _vote_or_unvote(request, course_id, thread, value)
thread_voted.send(sender=None, user=request.user, post=thread)
return result
......@@ -689,6 +692,7 @@ def follow_thread(request, course_id, thread_id):
user = cc.User.from_django_user(request.user)
thread = cc.Thread.find(thread_id)
user.follow(thread)
thread_followed.send(sender=None, user=request.user, post=thread)
return JsonResponse({})
......@@ -717,6 +721,7 @@ def unfollow_thread(request, course_id, thread_id):
user = cc.User.from_django_user(request.user)
thread = cc.Thread.find(thread_id)
user.unfollow(thread)
thread_unfollowed.send(sender=None, user=request.user, post=thread)
return JsonResponse({})
......
......@@ -21,7 +21,9 @@ from django_comment_common.signals import (
thread_created,
thread_deleted,
thread_edited,
thread_voted
thread_voted,
thread_followed,
thread_unfollowed,
)
from lms.djangoapps.teams import TEAM_DISCUSSION_CONTEXT
from lms.djangoapps.teams.utils import emit_team_event
......@@ -42,6 +44,14 @@ def post_create_vote_handler(sender, **kwargs): # pylint: disable=unused-argume
handle_activity(kwargs['user'], kwargs['post'])
@receiver(thread_followed)
@receiver(thread_unfollowed)
def post_followed_unfollowed_handler(sender, **kwargs): # pylint: disable=unused-argument
"""Update the user's last activity date upon followed or unfollowed of a
post."""
handle_activity(kwargs['user'], kwargs['post'])
@receiver(thread_edited)
@receiver(thread_deleted)
@receiver(comment_edited)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment