2017-10-23 19:39:12 +02:00
|
|
|
from typing import (Dict, List, Text, Set)
|
2017-10-29 16:50:20 +01:00
|
|
|
from django.db.models.query import QuerySet
|
2017-10-23 19:39:12 +02:00
|
|
|
|
2017-10-29 16:50:20 +01:00
|
|
|
from zerver.lib.stream_subscription import (
|
|
|
|
get_active_subscriptions_for_stream_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
from zerver.models import (
|
|
|
|
MutedTopic,
|
|
|
|
)
|
2017-10-23 19:39:12 +02:00
|
|
|
|
2017-11-05 11:37:41 +01:00
|
|
|
class StreamTopicTarget:
|
2017-10-23 19:39:12 +02:00
|
|
|
'''
|
|
|
|
This class is designed to help us move to a
|
|
|
|
StreamTopic table or something similar. It isolates
|
|
|
|
places where we are are still using `subject` or
|
|
|
|
`topic_name` as a key into tables.
|
|
|
|
'''
|
2017-11-05 11:15:10 +01:00
|
|
|
def __init__(self, stream_id: int, topic_name: Text) -> None:
|
2017-10-23 19:39:12 +02:00
|
|
|
self.stream_id = stream_id
|
|
|
|
self.topic_name = topic_name
|
|
|
|
|
2017-11-05 11:15:10 +01:00
|
|
|
def user_ids_muting_topic(self) -> Set[int]:
|
2017-10-23 19:39:12 +02:00
|
|
|
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
|
|
|
|
}
|
2017-10-29 16:50:20 +01:00
|
|
|
|
2017-11-05 11:15:10 +01:00
|
|
|
def get_active_subscriptions(self) -> QuerySet:
|
2017-10-29 16:50:20 +01:00
|
|
|
return get_active_subscriptions_for_stream_id(self.stream_id)
|