Files
zulip/zerver/lib/stream_topic.py
Anders Kaseorg 365fe0b3d5 python: Sort imports with isort.
Fixes #2665.

Regenerated by tabbott with `lint --fix` after a rebase and change in
parameters.

Note from tabbott: In a few cases, this converts technical debt in the
form of unsorted imports into different technical debt in the form of
our largest files having very long, ugly import sequences at the
start.  I expect this change will increase pressure for us to split
those files, which isn't a bad thing.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-11 16:45:32 -07:00

35 lines
1005 B
Python

from typing import Set
from django.db.models.query import QuerySet
from zerver.lib.stream_subscription import get_active_subscriptions_for_stream_id
from zerver.models import MutedTopic
class StreamTopicTarget:
'''
This class is designed to help us move to a
StreamTopic table or something similar. It isolates
places where we are are still using `topic_name` as
a key into tables.
'''
def __init__(self, stream_id: int, topic_name: str) -> None:
self.stream_id = stream_id
self.topic_name = topic_name
def user_ids_muting_topic(self) -> Set[int]:
query = MutedTopic.objects.filter(
stream_id=self.stream_id,
topic_name__iexact=self.topic_name,
).values(
'user_profile_id',
)
return {
row['user_profile_id']
for row in query
}
def get_active_subscriptions(self) -> QuerySet:
return get_active_subscriptions_for_stream_id(self.stream_id)