mirror of https://github.com/zulip/zulip.git
models: Extract zerver.models.muted_users.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
f960eafa59
commit
5d2146fb37
|
@ -32,7 +32,6 @@ from zerver.lib.cache import (
|
|||
cache_delete,
|
||||
cache_with_key,
|
||||
flush_message,
|
||||
flush_muting_users_cache,
|
||||
flush_submessage,
|
||||
flush_used_upload_space_cache,
|
||||
realm_alert_words_automaton_cache_key,
|
||||
|
@ -65,6 +64,7 @@ from zerver.models.groups import GroupGroupMembership as GroupGroupMembership
|
|||
from zerver.models.groups import UserGroup as UserGroup
|
||||
from zerver.models.groups import UserGroupMembership as UserGroupMembership
|
||||
from zerver.models.linkifiers import RealmFilter as RealmFilter
|
||||
from zerver.models.muted_users import MutedUser as MutedUser
|
||||
from zerver.models.prereg_users import EmailChangeStatus as EmailChangeStatus
|
||||
from zerver.models.prereg_users import MultiuseInvite as MultiuseInvite
|
||||
from zerver.models.prereg_users import PreregistrationRealm as PreregistrationRealm
|
||||
|
@ -143,23 +143,6 @@ def query_for_ids(
|
|||
return query
|
||||
|
||||
|
||||
class MutedUser(models.Model):
|
||||
user_profile = models.ForeignKey(UserProfile, related_name="muter", on_delete=CASCADE)
|
||||
muted_user = models.ForeignKey(UserProfile, related_name="muted", on_delete=CASCADE)
|
||||
date_muted = models.DateTimeField(default=timezone_now)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("user_profile", "muted_user")
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"{self.user_profile.email} -> {self.muted_user.email}"
|
||||
|
||||
|
||||
post_save.connect(flush_muting_users_cache, sender=MutedUser)
|
||||
post_delete.connect(flush_muting_users_cache, sender=MutedUser)
|
||||
|
||||
|
||||
class Client(models.Model):
|
||||
MAX_NAME_LENGTH = 30
|
||||
name = models.CharField(max_length=MAX_NAME_LENGTH, db_index=True, unique=True)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
from django.db import models
|
||||
from django.db.models import CASCADE
|
||||
from django.db.models.signals import post_delete, post_save
|
||||
from django.utils.timezone import now as timezone_now
|
||||
from typing_extensions import override
|
||||
|
||||
from zerver.lib.cache import flush_muting_users_cache
|
||||
from zerver.models.users import UserProfile
|
||||
|
||||
|
||||
class MutedUser(models.Model):
|
||||
user_profile = models.ForeignKey(UserProfile, related_name="muter", on_delete=CASCADE)
|
||||
muted_user = models.ForeignKey(UserProfile, related_name="muted", on_delete=CASCADE)
|
||||
date_muted = models.DateTimeField(default=timezone_now)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("user_profile", "muted_user")
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"{self.user_profile.email} -> {self.muted_user.email}"
|
||||
|
||||
|
||||
post_save.connect(flush_muting_users_cache, sender=MutedUser)
|
||||
post_delete.connect(flush_muting_users_cache, sender=MutedUser)
|
Loading…
Reference in New Issue