Skip to content

Commit

Permalink
feat: migrate fetch subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-Salman29 committed Oct 2, 2024
1 parent 1447495 commit 634af22
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def send_response_on_followed_post_notification(self):

while has_more_subscribers:

subscribers = Subscription.fetch(self.thread.id, query_params={'page': page})
subscribers = Subscription.fetch(self.thread.id, self.course.id, query_params={'page': page})
if page <= subscribers.num_pages:
for subscriber in subscribers.collection:
# Check if the subscriber is not the thread creator or response creator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"""
import logging

from opaque_keys.edx.keys import CourseKey

from . import models, settings, utils
from forum import api as forum_api
from lms.djangoapps.discussion.toggles import is_forum_v2_enabled

log = logging.getLogger(__name__)

Expand All @@ -21,7 +25,7 @@ class Subscription(models.Model):
base_url = f"{settings.PREFIX}/threads"

@classmethod
def fetch(cls, thread_id, query_params):
def fetch(cls, thread_id, course_id, query_params):
"""
Fetches the subscriptions for a given thread_id
"""
Expand All @@ -33,14 +37,20 @@ def fetch(cls, thread_id, query_params):
params.update(
utils.strip_blank(utils.strip_none(query_params))
)
response = utils.perform_request(
'get',
cls.url(action='get', params=params) + "/subscriptions",
params,
metric_tags=[],
metric_action='subscription.get',
paged_results=True
)

if course_id and not isinstance(course_id, CourseKey):
course_id = CourseKey.from_string(course_id)
if is_forum_v2_enabled(course_id):
response = forum_api.get_thread_subscriptions(thread_id, params['page'], params['per_page'])
else:
response = utils.perform_request(
'get',
cls.url(action='get', params=params) + "/subscriptions",
params,
metric_tags=[],
metric_action='subscription.get',
paged_results=True
)
return utils.SubscriptionsPaginatedResult(
collection=response.get('collection', []),
page=response.get('page', 1),
Expand Down

0 comments on commit 634af22

Please sign in to comment.