unread: Convert mark_stream_as_read to use stream IDs.

The logic is simpler and more robust.
This commit is contained in:
Tim Abbott 2017-08-15 10:34:15 -07:00
parent 89f9017686
commit f3a41ac796
4 changed files with 11 additions and 15 deletions

View File

@ -211,7 +211,7 @@ exports.register_stream_handlers = function () {
$('body').on('click', '.mark_stream_as_read', function (e) {
var sub = stream_popover_sub(e);
exports.hide_stream_popover();
unread_ops.mark_stream_as_read(sub.name);
unread_ops.mark_stream_as_read(sub.stream_id);
e.stopPropagation();
});

View File

@ -118,11 +118,11 @@ exports.mark_current_list_as_read = function mark_current_list_as_read(options)
exports.mark_messages_as_read(current_msg_list.all_messages(), options);
};
exports.mark_stream_as_read = function mark_stream_as_read(stream, cont) {
exports.mark_stream_as_read = function mark_stream_as_read(stream_id, cont) {
channel.post({
url: '/json/mark_stream_as_read',
idempotent: true,
data: {stream_name: stream},
data: {stream_id: stream_id},
success: cont});
};

View File

@ -213,7 +213,7 @@ class UnreadCountTests(ZulipTestCase):
# type: () -> None
self.login(self.example_email("hamlet"))
user_profile = self.example_user('hamlet')
self.subscribe_to_stream(user_profile.email, "test_stream", user_profile.realm)
stream = self.subscribe_to_stream(user_profile.email, "test_stream", user_profile.realm)
self.subscribe_to_stream(self.example_email("cordelia"), "test_stream", user_profile.realm)
message_id = self.send_message(self.example_email("hamlet"), "test_stream", Recipient.STREAM, "hello")
@ -222,7 +222,7 @@ class UnreadCountTests(ZulipTestCase):
events = [] # type: List[Mapping[str, Any]]
with tornado_redirected_to_list(events):
result = self.client_post("/json/mark_stream_as_read", {
"stream_name": "test_stream"
"stream_id": stream.id
})
self.assert_json_success(result)
@ -253,11 +253,11 @@ class UnreadCountTests(ZulipTestCase):
def test_mark_all_in_invalid_stream_read(self):
# type: () -> None
self.login(self.example_email("hamlet"))
invalid_stream_name = ""
invalid_stream_id = "12345678"
result = self.client_post("/json/mark_stream_as_read", {
"stream_name": invalid_stream_name
"stream_id": invalid_stream_id
})
self.assert_json_error(result, 'No such stream \'\'')
self.assert_json_error(result, 'Invalid stream id')
def test_mark_all_topics_unread_with_invalid_stream_name(self):
# type: () -> None

View File

@ -801,13 +801,9 @@ def mark_all_as_read(request, user_profile):
@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,))
stream_id=REQ(validator=check_int)):
# type: (HttpRequest, UserProfile, int) -> HttpResponse
stream, recipient, sub = access_stream_by_id(user_profile, stream_id)
count = do_mark_stream_messages_as_read(user_profile, stream)
log_data_str = "[%s updated]" % (count,)