mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
mute user: Add backend infrastructure code.
Adds backend code for the mute users feature. This is just infrastructure work (database interactions, helpers, tests, events, API docs etc) and does not involve any behavioral/semantic aspects of muted users. Adds POST and DELETE endpoints, to keep the URL scheme mostly consistent in terms of `users/me`. TODOs: 1. Add tests for exporting `zulip_muteduser` database table. 2. Add dedicated methods to python-zulip-api to be used in place of the current `client.call_endpoint` implementation.
This commit is contained in:
committed by
Tim Abbott
parent
89f6139505
commit
3bfcaa3968
43
zerver/lib/user_mutes.py
Normal file
43
zerver/lib/user_mutes.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import datetime
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
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(
|
||||
user_profile: UserProfile,
|
||||
muted_user: UserProfile,
|
||||
date_muted: Optional[datetime.datetime] = None,
|
||||
) -> None:
|
||||
if date_muted is None:
|
||||
date_muted = timezone_now()
|
||||
MutedUser.objects.create(
|
||||
user_profile=user_profile,
|
||||
muted_user=muted_user,
|
||||
date_muted=date_muted,
|
||||
)
|
||||
|
||||
|
||||
def remove_user_mute(user_profile: UserProfile, muted_user: UserProfile) -> None:
|
||||
MutedUser.objects.get(user_profile=user_profile, muted_user=muted_user).delete()
|
||||
|
||||
|
||||
def user_is_muted(user_profile: UserProfile, muted_user: UserProfile) -> bool:
|
||||
return MutedUser.objects.filter(user_profile=user_profile, muted_user=muted_user).exists()
|
||||
Reference in New Issue
Block a user