mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			30 lines
		
	
	
		
			803 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			803 B
		
	
	
	
		
			Python
		
	
	
	
	
	
from typing import List
 | 
						|
 | 
						|
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 get_active_subscriptions_for_stream_ids(stream_ids):
 | 
						|
    # type: (List[int]) -> QuerySet
 | 
						|
    return Subscription.objects.filter(
 | 
						|
        recipient__type=Recipient.STREAM,
 | 
						|
        recipient__type_id__in=stream_ids,
 | 
						|
        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()
 |