messages: Don't require "anchor" when "use_first_unread_anchor" is set.

The use_first_unread_anchor parameter allows automatically setting the
anchor to the first message that hasn't been read in this narrow.
Therefore it isn't necessary to specify an anchor when this parameter is
enabled.

Note from Tim: Arguably, we should think about making
`use_first_unread_anchor` the default behavior when anchor is
unspecified, but that's for later consideration.
This commit is contained in:
Yago González 2018-06-21 17:34:18 +02:00 committed by Tim Abbott
parent c7a97e34fb
commit 14bc5c7d5c
3 changed files with 11 additions and 2 deletions

View File

@ -956,6 +956,13 @@ class MessageDictTest(ZulipTestCase):
self.assertEqual(msg_dict['reactions'][0]['user']['full_name'],
sender.full_name)
def test_missing_anchor(self) -> None:
self.login(self.example_email("hamlet"))
result = self.client_get(
'/json/messages?use_first_unread_anchor=false&num_before=1&num_after=1')
self.assert_json_error(
result, "Missing 'anchor' argument (or set 'use_first_unread_anchor'=True).")
class SewMessageAndReactionTest(ZulipTestCase):
def test_sew_messages_and_reaction(self) -> None:

View File

@ -1697,7 +1697,7 @@ class GetOldMessagesTest(ZulipTestCase):
"""
self.login(self.example_email("hamlet"))
required_args = (("anchor", 1), ("num_before", 1), ("num_after", 1)) # type: Tuple[Tuple[str, int], ...]
required_args = (("num_before", 1), ("num_after", 1)) # type: Tuple[Tuple[str, int], ...]
for i in range(len(required_args)):
post_params = dict(required_args[:i] + required_args[i + 1:])

View File

@ -688,7 +688,7 @@ def zcommand_backend(request: HttpRequest, user_profile: UserProfile,
@has_request_variables
def get_messages_backend(request: HttpRequest, user_profile: UserProfile,
anchor: int=REQ(converter=int),
anchor: int=REQ(converter=int, default=None),
num_before: int=REQ(converter=to_non_negative_int),
num_after: int=REQ(converter=to_non_negative_int),
narrow: Optional[List[Dict[str, Any]]]=REQ('narrow', converter=narrow_parameter,
@ -696,6 +696,8 @@ def get_messages_backend(request: HttpRequest, user_profile: UserProfile,
use_first_unread_anchor: bool=REQ(validator=check_bool, default=False),
client_gravatar: bool=REQ(validator=check_bool, default=False),
apply_markdown: bool=REQ(validator=check_bool, default=True)) -> HttpResponse:
if anchor is None and not use_first_unread_anchor:
return json_error(_("Missing 'anchor' argument (or set 'use_first_unread_anchor'=True)."))
include_history = ok_to_include_history(narrow, user_profile)
if include_history: