2019-02-02 23:53:55 +01:00
|
|
|
from typing import Set
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2021-07-23 15:26:02 +02:00
|
|
|
from zerver.models import UserTopic
|
2017-10-29 16:50:20 +01:00
|
|
|
|
2017-10-23 19:39:12 +02:00
|
|
|
|
2017-11-05 11:37:41 +01:00
|
|
|
class StreamTopicTarget:
|
2021-02-12 08:19:30 +01:00
|
|
|
"""
|
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
|
2022-02-08 00:13:33 +01:00
|
|
|
places where we are still using `topic_name` as
|
2018-12-23 18:45:18 +01:00
|
|
|
a key into tables.
|
2021-02-12 08:19:30 +01:00
|
|
|
"""
|
2020-04-22 01:45:30 +02:00
|
|
|
|
2018-05-11 01:40:23 +02:00
|
|
|
def __init__(self, stream_id: int, topic_name: str) -> 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]:
|
2021-07-23 15:26:02 +02:00
|
|
|
query = UserTopic.objects.filter(
|
2017-10-23 19:39:12 +02:00
|
|
|
stream_id=self.stream_id,
|
|
|
|
topic_name__iexact=self.topic_name,
|
2021-08-02 09:49:56 +02:00
|
|
|
visibility_policy=UserTopic.MUTED,
|
2017-10-23 19:39:12 +02:00
|
|
|
).values(
|
2021-02-12 08:20:45 +01:00
|
|
|
"user_profile_id",
|
2017-10-23 19:39:12 +02:00
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
return {row["user_profile_id"] for row in query}
|