refactor: Extract get_stream_subscriptions_for_user().

This commit is contained in:
Steve Howell
2017-10-29 09:11:11 -07:00
committed by Tim Abbott
parent a2747517a3
commit b3192d17ab
4 changed files with 25 additions and 19 deletions

View File

@@ -4,6 +4,7 @@ from django.db.models.query import QuerySet
from zerver.models import (
Recipient,
Subscription,
UserProfile,
)
def get_active_subscriptions_for_stream_id(stream_id):
@@ -22,6 +23,13 @@ def get_active_subscriptions_for_stream_ids(stream_ids):
active=True
)
def get_stream_subscriptions_for_user(user_profile):
# type: (UserProfile) -> QuerySet
return Subscription.objects.filter(
user_profile=user_profile,
recipient__type=Recipient.STREAM,
)
def num_subscribers_for_stream_id(stream_id):
# type: (int) -> int
return get_active_subscriptions_for_stream_id(stream_id).filter(