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:
Abhijeet Prasad Bodas
2021-03-27 16:53:32 +05:30
committed by Tim Abbott
parent 89f6139505
commit 3bfcaa3968
21 changed files with 522 additions and 12 deletions

View File

@@ -167,6 +167,7 @@ from zerver.lib.upload import (
upload_emoji_image,
)
from zerver.lib.user_groups import access_user_group_by_id, create_user_group
from zerver.lib.user_mutes import add_user_mute, get_user_mutes, remove_user_mute
from zerver.lib.user_status import update_user_status
from zerver.lib.users import (
check_bot_name_available,
@@ -6486,6 +6487,24 @@ def do_unmute_topic(user_profile: UserProfile, stream: Stream, topic: str) -> No
send_event(user_profile.realm, event, [user_profile.id])
def do_mute_user(
user_profile: UserProfile,
muted_user: UserProfile,
date_muted: Optional[datetime.datetime] = None,
) -> None:
if date_muted is None:
date_muted = timezone_now()
add_user_mute(user_profile, muted_user, date_muted)
event = dict(type="muted_users", muted_users=get_user_mutes(user_profile))
send_event(user_profile.realm, event, [user_profile.id])
def do_unmute_user(user_profile: UserProfile, muted_user: UserProfile) -> None:
remove_user_mute(user_profile, muted_user)
event = dict(type="muted_users", muted_users=get_user_mutes(user_profile))
send_event(user_profile.realm, event, [user_profile.id])
def do_mark_hotspot_as_read(user: UserProfile, hotspot: str) -> None:
UserHotspot.objects.get_or_create(user=user, hotspot=hotspot)
event = dict(type="hotspots", hotspots=get_next_hotspots(user))