Skip to content
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
16 changes: 14 additions & 2 deletions lms/djangoapps/discussion_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ class ThreadSerializer(_ContentSerializer):
pinned = serializers.SerializerMethodField(read_only=True)
closed = serializers.BooleanField(read_only=True)
following = serializers.SerializerMethodField()
comment_count = serializers.IntegerField(source="comments_count", read_only=True)
unread_comment_count = serializers.IntegerField(source="unread_comments_count", read_only=True)
comment_count = serializers.SerializerMethodField(read_only=True)
unread_comment_count = serializers.SerializerMethodField(read_only=True)
comment_list_url = serializers.SerializerMethodField()
endorsed_comment_list_url = serializers.SerializerMethodField()
non_endorsed_comment_list_url = serializers.SerializerMethodField()
Expand Down Expand Up @@ -252,6 +252,18 @@ def get_non_endorsed_comment_list_url(self, obj):
"""Returns the URL to retrieve the thread's non-endorsed comments."""
return self.get_comment_list_url(obj, endorsed=False)

def get_comment_count(self, obj):
"""Increments comment count to include post and returns total count of
contributions (i.e. post + responses + comments) for the thread"""
return obj["comments_count"] + 1

def get_unread_comment_count(self, obj):
"""Increments comment count to include post if thread is unread and returns
total count of unread contributions (i.e. post + responses + comments) for the thread"""
if not obj["read"]:
return obj["unread_comments_count"] + 1
return obj["unread_comments_count"]

def create(self, validated_data):
thread = Thread(user_id=self.context["cc_requester"]["id"], **validated_data)
thread.save()
Expand Down
20 changes: 10 additions & 10 deletions lms/djangoapps/discussion_api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def test_thread_content(self):
"abuse_flagged": False,
"voted": False,
"vote_count": 4,
"comment_count": 5,
"comment_count": 6,
"unread_comment_count": 3,
"comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_thread_id_0",
"endorsed_comment_list_url": None,
Expand Down Expand Up @@ -673,8 +673,8 @@ def test_thread_content(self):
"abuse_flagged": False,
"voted": False,
"vote_count": 9,
"comment_count": 18,
"unread_comment_count": 0,
"comment_count": 19,
"unread_comment_count": 1,
"comment_list_url": None,
"endorsed_comment_list_url": (
"http://testserver/api/discussion/v1/comments/?thread_id=test_thread_id_1&endorsed=True"
Expand Down Expand Up @@ -1397,8 +1397,8 @@ def test_basic(self, mock_emit):
"abuse_flagged": False,
"voted": False,
"vote_count": 0,
"comment_count": 0,
"unread_comment_count": 0,
"comment_count": 1,
"unread_comment_count": 1,
"comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_id",
"endorsed_comment_list_url": None,
"non_endorsed_comment_list_url": None,
Expand Down Expand Up @@ -1943,7 +1943,7 @@ def test_basic(self):
"abuse_flagged": False,
"voted": False,
"vote_count": 0,
"comment_count": 0,
"comment_count": 1,
"unread_comment_count": 0,
"comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_thread",
"endorsed_comment_list_url": None,
Expand Down Expand Up @@ -2999,8 +2999,8 @@ def test_basic(self):
"pinned": False,
"closed": False,
"following": False,
"comment_count": 0,
"unread_comment_count": 0,
"comment_count": 1,
"unread_comment_count": 1,
"comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_thread",
"endorsed_comment_list_url": None,
"non_endorsed_comment_list_url": None,
Expand Down Expand Up @@ -3039,8 +3039,8 @@ def test_nonauthor_enrolled_in_course(self):
"pinned": False,
"closed": False,
"following": False,
"comment_count": 0,
"unread_comment_count": 0,
"comment_count": 1,
"unread_comment_count": 1,
"comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_thread",
"endorsed_comment_list_url": None,
"non_endorsed_comment_list_url": None,
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/discussion_api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def test_basic(self):
"abuse_flagged": False,
"voted": False,
"vote_count": 4,
"comment_count": 5,
"unread_comment_count": 3,
"comment_count": 6,
"unread_comment_count": 4,
"comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_thread",
"endorsed_comment_list_url": None,
"non_endorsed_comment_list_url": None,
Expand Down
15 changes: 9 additions & 6 deletions lms/djangoapps/discussion_api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ def test_basic(self):
"abuse_flagged": False,
"voted": True,
"vote_count": 4,
"comment_count": 5,
"unread_comment_count": 3,
"comment_count": 6,
"unread_comment_count": 4,
"comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_thread",
"endorsed_comment_list_url": None,
"non_endorsed_comment_list_url": None,
Expand Down Expand Up @@ -519,8 +519,8 @@ def test_basic(self):
"abuse_flagged": False,
"voted": False,
"vote_count": 0,
"comment_count": 0,
"unread_comment_count": 0,
"comment_count": 1,
"unread_comment_count": 1,
"comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_thread",
"endorsed_comment_list_url": None,
"non_endorsed_comment_list_url": None,
Expand Down Expand Up @@ -634,6 +634,7 @@ def test_basic(self):
],
"created_at": "Test Created Date",
"updated_at": "Test Updated Date",
"comment_count": 1,
})
)
self.assertEqual(
Expand Down Expand Up @@ -684,6 +685,8 @@ def test_closed_thread(self, field, value):
"closed": True,
"abuse_flagged": value,
"editable_fields": ["abuse_flagged", "read"],
"comment_count": 1,
"unread_comment_count": 1,
})
)

Expand Down Expand Up @@ -1154,8 +1157,8 @@ def test_basic(self):
"pinned": False,
"closed": False,
"following": False,
"comment_count": 0,
"unread_comment_count": 0,
"comment_count": 1,
"unread_comment_count": 1,
"comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_thread",
"endorsed_comment_list_url": None,
"non_endorsed_comment_list_url": None,
Expand Down