mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
Implemented API routes for muting/unmuting a topic
This commit is contained in:
@@ -3243,6 +3243,18 @@ def do_set_muted_topics(user_profile, muted_topics):
|
|||||||
event = dict(type="muted_topics", muted_topics=muted_topics)
|
event = dict(type="muted_topics", muted_topics=muted_topics)
|
||||||
send_event(event, [user_profile.id])
|
send_event(event, [user_profile.id])
|
||||||
|
|
||||||
|
def do_update_muted_topic(user_profile, stream, topic, op):
|
||||||
|
# type: (UserProfile, str, str, str) -> None
|
||||||
|
muted_topics = ujson.loads(user_profile.muted_topics)
|
||||||
|
if op == 'add':
|
||||||
|
muted_topics.append([stream, topic])
|
||||||
|
elif op == 'remove':
|
||||||
|
muted_topics.remove([stream, topic])
|
||||||
|
user_profile.muted_topics = ujson.dumps(muted_topics)
|
||||||
|
user_profile.save(update_fields=['muted_topics'])
|
||||||
|
event = dict(type="muted_topics", muted_topics=muted_topics)
|
||||||
|
send_event(event, [user_profile.id])
|
||||||
|
|
||||||
def notify_realm_filters(realm):
|
def notify_realm_filters(realm):
|
||||||
# type: (Realm) -> None
|
# type: (Realm) -> None
|
||||||
realm_filters = realm_filters_for_realm(realm.id)
|
realm_filters = realm_filters_for_realm(realm.id)
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ from __future__ import absolute_import
|
|||||||
from django.http import HttpResponse, HttpRequest
|
from django.http import HttpResponse, HttpRequest
|
||||||
from typing import List, Text
|
from typing import List, Text
|
||||||
|
|
||||||
|
import ujson
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
from zerver.decorator import authenticated_json_post_view
|
from zerver.decorator import authenticated_json_post_view
|
||||||
from zerver.lib.actions import do_set_muted_topics
|
from zerver.lib.actions import do_set_muted_topics, do_update_muted_topic
|
||||||
from zerver.lib.request import has_request_variables, REQ
|
from zerver.lib.request import has_request_variables, REQ
|
||||||
from zerver.lib.response import json_success
|
from zerver.lib.response import json_success, json_error
|
||||||
from zerver.lib.validator import check_string, check_list
|
from zerver.lib.validator import check_string, check_list
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
@@ -17,3 +20,20 @@ def set_muted_topics(request, user_profile,
|
|||||||
# type: (HttpRequest, UserProfile, List[List[Text]]) -> HttpResponse
|
# type: (HttpRequest, UserProfile, List[List[Text]]) -> HttpResponse
|
||||||
do_set_muted_topics(user_profile, muted_topics)
|
do_set_muted_topics(user_profile, muted_topics)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
|
@has_request_variables
|
||||||
|
def update_muted_topic(request, user_profile, stream=REQ(),
|
||||||
|
topic=REQ(), op=REQ()):
|
||||||
|
# type: (HttpRequest, UserProfile, str, str, str) -> HttpResponse
|
||||||
|
muted_topics = ujson.loads(user_profile.muted_topics)
|
||||||
|
if op == 'add':
|
||||||
|
if [stream, topic] in muted_topics:
|
||||||
|
return json_error(_("Topic already muted"))
|
||||||
|
muted_topics.append([stream, topic])
|
||||||
|
elif op == 'remove':
|
||||||
|
if [stream, topic] not in muted_topics:
|
||||||
|
return json_error(_("Topic is not there in the muted_topics list"))
|
||||||
|
muted_topics.remove([stream, topic])
|
||||||
|
|
||||||
|
do_update_muted_topic(user_profile, stream, topic, op)
|
||||||
|
return json_success()
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import zerver.views.users
|
|||||||
import zerver.views.unsubscribe
|
import zerver.views.unsubscribe
|
||||||
import zerver.views.integrations
|
import zerver.views.integrations
|
||||||
import zerver.views.user_settings
|
import zerver.views.user_settings
|
||||||
|
import zerver.views.muting
|
||||||
import confirmation.views
|
import confirmation.views
|
||||||
|
|
||||||
from zerver.lib.rest import rest_dispatch
|
from zerver.lib.rest import rest_dispatch
|
||||||
@@ -342,7 +343,8 @@ v1_api_and_json_patterns = [
|
|||||||
'DELETE': 'zerver.views.streams.remove_subscriptions_backend'}),
|
'DELETE': 'zerver.views.streams.remove_subscriptions_backend'}),
|
||||||
# muting -> zerver.views.muting
|
# muting -> zerver.views.muting
|
||||||
url(r'^users/me/subscriptions/muted_topics$', rest_dispatch,
|
url(r'^users/me/subscriptions/muted_topics$', rest_dispatch,
|
||||||
{'POST': 'zerver.views.muting.set_muted_topics'}),
|
{'POST': 'zerver.views.muting.set_muted_topics',
|
||||||
|
'PATCH': 'zerver.views.muting.update_muted_topic'}),
|
||||||
|
|
||||||
# used to register for an event queue in tornado
|
# used to register for an event queue in tornado
|
||||||
url(r'^register$', rest_dispatch,
|
url(r'^register$', rest_dispatch,
|
||||||
|
|||||||
Reference in New Issue
Block a user