Create new endpoints for marking streams/topics as read.

The new endpoints are:
    /json/mark_stream_as_read: takes stream name
    /json/mark_topic_as_read: takes stream name, topic name

The /json/flags endpoint no longer allows streams or topics
to be passed in as parameters.
This commit is contained in:
Steve Howell
2017-08-08 10:11:45 -04:00
committed by Tim Abbott
parent 60cc8fd58a
commit 89f9017686
4 changed files with 58 additions and 58 deletions

View File

@@ -120,28 +120,17 @@ exports.mark_current_list_as_read = function mark_current_list_as_read(options)
exports.mark_stream_as_read = function mark_stream_as_read(stream, cont) {
channel.post({
url: '/json/messages/flags',
url: '/json/mark_stream_as_read',
idempotent: true,
data: {messages: JSON.stringify([]),
all: false,
op: 'add',
flag: 'read',
stream_name: stream,
},
data: {stream_name: stream},
success: cont});
};
exports.mark_topic_as_read = function mark_topic_as_read(stream, topic, cont) {
channel.post({
url: '/json/messages/flags',
url: '/json/mark_topic_as_read',
idempotent: true,
data: {messages: JSON.stringify([]),
all: false,
op: 'add',
flag: 'read',
topic_name: topic,
stream_name: stream,
},
data: {stream_name: stream, topic_name: topic},
success: cont});
};

View File

@@ -221,10 +221,9 @@ class UnreadCountTests(ZulipTestCase):
events = [] # type: List[Mapping[str, Any]]
with tornado_redirected_to_list(events):
result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "add",
"flag": "read",
"stream_name": "test_stream"})
result = self.client_post("/json/mark_stream_as_read", {
"stream_name": "test_stream"
})
self.assert_json_success(result)
self.assertTrue(len(events) == 1)
@@ -255,12 +254,21 @@ class UnreadCountTests(ZulipTestCase):
# type: () -> None
self.login(self.example_email("hamlet"))
invalid_stream_name = ""
result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "add",
"flag": "read",
"stream_name": invalid_stream_name})
result = self.client_post("/json/mark_stream_as_read", {
"stream_name": invalid_stream_name
})
self.assert_json_error(result, 'No such stream \'\'')
def test_mark_all_topics_unread_with_invalid_stream_name(self):
# type: () -> None
self.login(self.example_email("hamlet"))
invalid_stream_name = "bogus"
result = self.client_post("/json/mark_topic_as_read", {
"stream_name": invalid_stream_name,
'topic_name': 'whatever',
})
self.assert_json_error(result, "No such stream 'bogus'")
def test_mark_all_in_stream_topic_read(self):
# type: () -> None
self.login(self.example_email("hamlet"))
@@ -271,11 +279,10 @@ class UnreadCountTests(ZulipTestCase):
unrelated_message_id = self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, "hello", "Denmark2")
events = [] # type: List[Mapping[str, Any]]
with tornado_redirected_to_list(events):
result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "add",
"flag": "read",
"topic_name": "test_topic",
"stream_name": "test_stream"})
result = self.client_post("/json/mark_topic_as_read", {
"stream_name": "test_stream",
"topic_name": "test_topic",
})
self.assert_json_success(result)
self.assertTrue(len(events) == 1)
@@ -304,9 +311,8 @@ class UnreadCountTests(ZulipTestCase):
# type: () -> None
self.login(self.example_email("hamlet"))
invalid_topic_name = "abc"
result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "add",
"flag": "read",
"topic_name": invalid_topic_name,
"stream_name": "Denmark"})
result = self.client_post("/json/mark_topic_as_read", {
"stream_name": "Denmark",
"topic_name": invalid_topic_name,
})
self.assert_json_error(result, 'No such topic \'abc\'')

View File

@@ -774,21 +774,8 @@ def get_messages_backend(request, user_profile,
@has_request_variables
def update_message_flags(request, user_profile,
messages=REQ(validator=check_list(check_int)),
operation=REQ('op'), flag=REQ(),
stream_name=REQ(default=None),
topic_name=REQ(default=None)):
# type: (HttpRequest, UserProfile, List[int], Text, Text, Optional[Text], Optional[Text]) -> HttpResponse
if stream_name is not None:
# TODO: We should just have different endpoints for
# the stream/topic options.
return update_stream_topic_message_flags(
request=request,
user_profile=user_profile,
operation=operation,
flag=flag,
stream_name=stream_name,
topic_name=topic_name)
operation=REQ('op'), flag=REQ()):
# type: (HttpRequest, UserProfile, List[int], Text, Text) -> HttpResponse
count = do_update_message_flags(user_profile, operation, flag, messages)
@@ -811,16 +798,30 @@ def mark_all_as_read(request, user_profile):
return json_success({'result': 'success',
'msg': ''})
def update_stream_topic_message_flags(request,
user_profile,
operation,
flag,
stream_name,
topic_name):
# type: (HttpRequest, UserProfile, Text, Text, Optional[Text], Optional[Text]) -> HttpResponse
assert(operation == 'add')
assert(flag == 'read')
@has_request_variables
def mark_stream_as_read(request,
user_profile,
stream_name=REQ()):
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
try:
stream = get_stream(stream_name, user_profile.realm)
except Stream.DoesNotExist:
raise JsonableError(_('No such stream \'%s\'') % (stream_name,))
count = do_mark_stream_messages_as_read(user_profile, stream)
log_data_str = "[%s updated]" % (count,)
request._log_data["extra"] = log_data_str
return json_success({'result': 'success',
'msg': ''})
@has_request_variables
def mark_topic_as_read(request,
user_profile,
stream_name=REQ(),
topic_name=REQ()):
# type: (HttpRequest, UserProfile, Text, Text) -> HttpResponse
try:
stream = get_stream(stream_name, user_profile.realm)
except Stream.DoesNotExist:
@@ -836,7 +837,7 @@ def update_stream_topic_message_flags(request,
count = do_mark_stream_messages_as_read(user_profile, stream, topic_name)
log_data_str = "[%s %s/%s updated]" % (operation, flag, count)
log_data_str = "[%s updated]" % (count,)
request._log_data["extra"] = log_data_str
return json_success({'result': 'success',

View File

@@ -253,6 +253,10 @@ v1_api_and_json_patterns = [
# mark messages as read (in bulk)
url(r'^mark_all_as_read$', rest_dispatch,
{'POST': 'zerver.views.messages.mark_all_as_read'}),
url(r'^mark_stream_as_read$', rest_dispatch,
{'POST': 'zerver.views.messages.mark_stream_as_read'}),
url(r'^mark_topic_as_read$', rest_dispatch,
{'POST': 'zerver.views.messages.mark_topic_as_read'}),
# messages -> zerver.views.messages
# GET returns messages, possibly filtered, POST sends a message