2021-03-27 12:23:32 +01:00
|
|
|
import datetime
|
2021-04-08 06:20:43 +02:00
|
|
|
from typing import Dict, List, Optional
|
2021-03-27 12:23:32 +01:00
|
|
|
|
|
|
|
from zerver.lib.timestamp import datetime_to_timestamp
|
|
|
|
from zerver.models import MutedUser, UserProfile
|
|
|
|
|
|
|
|
|
|
|
|
def get_user_mutes(user_profile: UserProfile) -> List[Dict[str, int]]:
|
|
|
|
rows = MutedUser.objects.filter(user_profile=user_profile).values(
|
|
|
|
"muted_user__id",
|
|
|
|
"date_muted",
|
|
|
|
)
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
"id": row["muted_user__id"],
|
|
|
|
"timestamp": datetime_to_timestamp(row["date_muted"]),
|
|
|
|
}
|
|
|
|
for row in rows
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def add_user_mute(
|
2021-04-07 19:33:10 +02:00
|
|
|
user_profile: UserProfile, muted_user: UserProfile, date_muted: datetime.datetime
|
2021-03-27 12:23:32 +01:00
|
|
|
) -> None:
|
|
|
|
MutedUser.objects.create(
|
|
|
|
user_profile=user_profile,
|
|
|
|
muted_user=muted_user,
|
|
|
|
date_muted=date_muted,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-04-08 06:20:43 +02:00
|
|
|
def get_mute_object(user_profile: UserProfile, muted_user: UserProfile) -> Optional[MutedUser]:
|
|
|
|
try:
|
|
|
|
return MutedUser.objects.get(user_profile=user_profile, muted_user=muted_user)
|
|
|
|
except MutedUser.DoesNotExist:
|
|
|
|
return None
|