mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
committed by
Tim Abbott
parent
798defc046
commit
683c8507e4
@@ -40,7 +40,6 @@ from zerver.models import (
|
||||
DefaultStream,
|
||||
Huddle,
|
||||
Message,
|
||||
MutedTopic,
|
||||
Reaction,
|
||||
Realm,
|
||||
RealmAuditLog,
|
||||
@@ -60,6 +59,7 @@ from zerver.models import (
|
||||
UserMessage,
|
||||
UserPresence,
|
||||
UserProfile,
|
||||
UserTopic,
|
||||
get_display_recipient,
|
||||
get_realm,
|
||||
get_system_bot,
|
||||
@@ -751,7 +751,7 @@ def get_realm_config() -> Config:
|
||||
|
||||
Config(
|
||||
table="zerver_mutedtopic",
|
||||
model=MutedTopic,
|
||||
model=UserTopic,
|
||||
normal_parent=user_profile_config,
|
||||
parent_key="user_profile__in",
|
||||
)
|
||||
|
||||
@@ -45,7 +45,6 @@ from zerver.models import (
|
||||
DefaultStream,
|
||||
Huddle,
|
||||
Message,
|
||||
MutedTopic,
|
||||
MutedUser,
|
||||
Reaction,
|
||||
Realm,
|
||||
@@ -66,6 +65,7 @@ from zerver.models import (
|
||||
UserMessage,
|
||||
UserPresence,
|
||||
UserProfile,
|
||||
UserTopic,
|
||||
get_huddle_hash,
|
||||
get_realm,
|
||||
get_system_bot,
|
||||
@@ -1091,8 +1091,8 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Rea
|
||||
re_map_foreign_keys(data, "zerver_mutedtopic", "user_profile", related_table="user_profile")
|
||||
re_map_foreign_keys(data, "zerver_mutedtopic", "stream", related_table="stream")
|
||||
re_map_foreign_keys(data, "zerver_mutedtopic", "recipient", related_table="recipient")
|
||||
update_model_ids(MutedTopic, data, "mutedtopic")
|
||||
bulk_import_model(data, MutedTopic)
|
||||
update_model_ids(UserTopic, data, "mutedtopic")
|
||||
bulk_import_model(data, UserTopic)
|
||||
|
||||
if "zerver_muteduser" in data:
|
||||
fix_datetime_fields(data, "zerver_muteduser")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Set
|
||||
|
||||
from zerver.models import MutedTopic
|
||||
from zerver.models import UserTopic
|
||||
|
||||
|
||||
class StreamTopicTarget:
|
||||
@@ -16,7 +16,7 @@ class StreamTopicTarget:
|
||||
self.topic_name = topic_name
|
||||
|
||||
def user_ids_muting_topic(self) -> Set[int]:
|
||||
query = MutedTopic.objects.filter(
|
||||
query = UserTopic.objects.filter(
|
||||
stream_id=self.stream_id,
|
||||
topic_name__iexact=self.topic_name,
|
||||
).values(
|
||||
|
||||
@@ -459,7 +459,7 @@ def access_stream_for_unmute_topic_by_name(
|
||||
muted in the past (not here, but in the caller).
|
||||
|
||||
Long term, we'll probably have folks just pass us in the id of the
|
||||
MutedTopic row to unmute topics.
|
||||
UserTopic row to unmute topics.
|
||||
"""
|
||||
try:
|
||||
stream = get_stream(stream_name, user_profile.realm)
|
||||
|
||||
@@ -547,7 +547,7 @@ def use_db_models(
|
||||
Huddle = apps.get_model("zerver", "Huddle")
|
||||
Message = apps.get_model("zerver", "Message")
|
||||
MultiuseInvite = apps.get_model("zerver", "MultiuseInvite")
|
||||
MutedTopic = apps.get_model("zerver", "MutedTopic")
|
||||
UserTopic = apps.get_model("zerver", "UserTopic")
|
||||
PreregistrationUser = apps.get_model("zerver", "PreregistrationUser")
|
||||
PushDeviceToken = apps.get_model("zerver", "PushDeviceToken")
|
||||
Reaction = apps.get_model("zerver", "Reaction")
|
||||
@@ -591,7 +591,7 @@ def use_db_models(
|
||||
Huddle=Huddle,
|
||||
Message=Message,
|
||||
MultiuseInvite=MultiuseInvite,
|
||||
MutedTopic=MutedTopic,
|
||||
UserTopic=UserTopic,
|
||||
PreregistrationUser=PreregistrationUser,
|
||||
PushDeviceToken=PushDeviceToken,
|
||||
Reaction=Reaction,
|
||||
|
||||
@@ -6,13 +6,13 @@ from sqlalchemy.sql import ClauseElement, and_, column, not_, or_
|
||||
|
||||
from zerver.lib.timestamp import datetime_to_timestamp
|
||||
from zerver.lib.topic import topic_match_sa
|
||||
from zerver.models import MutedTopic, UserProfile, get_stream
|
||||
from zerver.models import UserProfile, UserTopic, get_stream
|
||||
|
||||
|
||||
def get_topic_mutes(
|
||||
user_profile: UserProfile, include_deactivated: bool = False
|
||||
) -> List[Tuple[str, str, float]]:
|
||||
query = MutedTopic.objects.filter(user_profile=user_profile)
|
||||
query = UserTopic.objects.filter(user_profile=user_profile)
|
||||
# Exclude muted topics that are part of deactivated streams unless
|
||||
# explicitly requested.
|
||||
if not include_deactivated:
|
||||
@@ -37,7 +37,7 @@ def set_topic_mutes(
|
||||
This is only used in tests.
|
||||
"""
|
||||
|
||||
MutedTopic.objects.filter(
|
||||
UserTopic.objects.filter(
|
||||
user_profile=user_profile,
|
||||
).delete()
|
||||
|
||||
@@ -65,7 +65,7 @@ def add_topic_mute(
|
||||
) -> None:
|
||||
if date_muted is None:
|
||||
date_muted = timezone_now()
|
||||
MutedTopic.objects.create(
|
||||
UserTopic.objects.create(
|
||||
user_profile=user_profile,
|
||||
stream_id=stream_id,
|
||||
recipient_id=recipient_id,
|
||||
@@ -75,7 +75,7 @@ def add_topic_mute(
|
||||
|
||||
|
||||
def remove_topic_mute(user_profile: UserProfile, stream_id: int, topic_name: str) -> None:
|
||||
row = MutedTopic.objects.get(
|
||||
row = UserTopic.objects.get(
|
||||
user_profile=user_profile,
|
||||
stream_id=stream_id,
|
||||
topic_name__iexact=topic_name,
|
||||
@@ -84,7 +84,7 @@ def remove_topic_mute(user_profile: UserProfile, stream_id: int, topic_name: str
|
||||
|
||||
|
||||
def topic_is_muted(user_profile: UserProfile, stream_id: int, topic_name: str) -> bool:
|
||||
is_muted = MutedTopic.objects.filter(
|
||||
is_muted = UserTopic.objects.filter(
|
||||
user_profile=user_profile,
|
||||
stream_id=stream_id,
|
||||
topic_name__iexact=topic_name,
|
||||
@@ -98,7 +98,7 @@ def exclude_topic_mutes(
|
||||
# Note: Unlike get_topic_mutes, here we always want to
|
||||
# consider topics in deactivated streams, so they are
|
||||
# never filtered from the query in this method.
|
||||
query = MutedTopic.objects.filter(
|
||||
query = UserTopic.objects.filter(
|
||||
user_profile=user_profile,
|
||||
)
|
||||
|
||||
@@ -128,7 +128,7 @@ def exclude_topic_mutes(
|
||||
|
||||
|
||||
def build_topic_mute_checker(user_profile: UserProfile) -> Callable[[int, str], bool]:
|
||||
rows = MutedTopic.objects.filter(user_profile=user_profile).values(
|
||||
rows = UserTopic.objects.filter(user_profile=user_profile).values(
|
||||
"recipient_id",
|
||||
"topic_name",
|
||||
)
|
||||
|
||||
@@ -2153,9 +2153,6 @@ class UserTopic(models.Model):
|
||||
return f"<UserTopic: ({self.user_profile.email}, {self.stream.name}, {self.topic_name}, {self.date_muted})>"
|
||||
|
||||
|
||||
MutedTopic = UserTopic
|
||||
|
||||
|
||||
class MutedUser(models.Model):
|
||||
user_profile = models.ForeignKey(UserProfile, related_name="+", on_delete=CASCADE)
|
||||
muted_user = models.ForeignKey(UserProfile, related_name="+", on_delete=CASCADE)
|
||||
|
||||
@@ -43,7 +43,6 @@ from zerver.models import (
|
||||
CustomProfileFieldValue,
|
||||
Huddle,
|
||||
Message,
|
||||
MutedTopic,
|
||||
MutedUser,
|
||||
Reaction,
|
||||
Realm,
|
||||
@@ -58,6 +57,7 @@ from zerver.models import (
|
||||
UserMessage,
|
||||
UserPresence,
|
||||
UserProfile,
|
||||
UserTopic,
|
||||
get_active_streams,
|
||||
get_client,
|
||||
get_huddle_hash,
|
||||
@@ -1002,7 +1002,7 @@ class ImportExportTest(ZulipTestCase):
|
||||
# test muted topics
|
||||
def get_muted_topics(r: Realm) -> Set[str]:
|
||||
user_profile_id = get_user_id(r, hamlet_full_name)
|
||||
muted_topics = MutedTopic.objects.filter(user_profile_id=user_profile_id)
|
||||
muted_topics = UserTopic.objects.filter(user_profile_id=user_profile_id)
|
||||
topic_names = {muted_topic.topic_name for muted_topic in muted_topics}
|
||||
return topic_names
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from zerver.lib.topic_mutes import (
|
||||
remove_topic_mute,
|
||||
topic_is_muted,
|
||||
)
|
||||
from zerver.models import MutedTopic, UserProfile, get_stream
|
||||
from zerver.models import UserProfile, UserTopic, get_stream
|
||||
|
||||
|
||||
class MutedTopicsTests(ZulipTestCase):
|
||||
@@ -69,13 +69,13 @@ class MutedTopicsTests(ZulipTestCase):
|
||||
mute_topic_for_user(hamlet)
|
||||
user_ids = stream_topic_target.user_ids_muting_topic()
|
||||
self.assertEqual(user_ids, {hamlet.id})
|
||||
hamlet_date_muted = MutedTopic.objects.filter(user_profile=hamlet)[0].date_muted
|
||||
hamlet_date_muted = UserTopic.objects.filter(user_profile=hamlet)[0].date_muted
|
||||
self.assertTrue(timezone_now() - hamlet_date_muted <= timedelta(seconds=100))
|
||||
|
||||
mute_topic_for_user(cordelia)
|
||||
user_ids = stream_topic_target.user_ids_muting_topic()
|
||||
self.assertEqual(user_ids, {hamlet.id, cordelia.id})
|
||||
cordelia_date_muted = MutedTopic.objects.filter(user_profile=cordelia)[0].date_muted
|
||||
cordelia_date_muted = UserTopic.objects.filter(user_profile=cordelia)[0].date_muted
|
||||
self.assertTrue(timezone_now() - cordelia_date_muted <= timedelta(seconds=100))
|
||||
|
||||
def test_add_muted_topic(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user