mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	The first method we extract to this library is get_active_subscriptions_for_stream_id(). We also move num_subscribers_for_stream_id() to here, which is slightly annoying (having the method on Stream was nice) but avoids some circular dependency issues.
		
			
				
	
	
		
			20 lines
		
	
	
		
			533 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			20 lines
		
	
	
		
			533 B
		
	
	
	
		
			Python
		
	
	
	
	
	
from django.db.models.query import QuerySet
 | 
						|
from zerver.models import (
 | 
						|
    Recipient,
 | 
						|
    Subscription,
 | 
						|
)
 | 
						|
 | 
						|
def get_active_subscriptions_for_stream_id(stream_id):
 | 
						|
    # type: (int) -> QuerySet
 | 
						|
    return Subscription.objects.filter(
 | 
						|
        recipient__type=Recipient.STREAM,
 | 
						|
        recipient__type_id=stream_id,
 | 
						|
        active=True,
 | 
						|
    )
 | 
						|
 | 
						|
def num_subscribers_for_stream_id(stream_id):
 | 
						|
    # type: (int) -> int
 | 
						|
    return get_active_subscriptions_for_stream_id(stream_id).filter(
 | 
						|
        user_profile__is_active=True,
 | 
						|
    ).count()
 |