Allow negative anchor param to get_old_message

When narrowing, we use the selected id in the home view as the anchor,
and if the user is new and hasn't selected any messages yet (or moved
the pointer since first using humbug), their home view selected message
will be -1. Rather than failing to get_old_messages for any narrows starting
from that point, return all matching messages.

(imported from commit 72cfe392d9ac01ed41abc8eadf0f47240e374665)
This commit is contained in:
Leo Franchi 2013-03-11 15:11:24 -04:00
parent 436d3b2578
commit 9466addbe2
2 changed files with 4 additions and 4 deletions

View File

@ -1005,13 +1005,13 @@ class GetOldMessagesTest(AuthedTestCase):
def test_bad_int_params(self):
"""
anchor, num_before, num_after, and narrow must all be non-negative
num_before, num_after, and narrow must all be non-negative
integers or strings that can be converted to non-negative integers.
"""
self.login("hamlet@humbughq.com")
other_params = [("narrow", {})]
int_params = ["anchor", "num_before", "num_after"]
other_params = [("narrow", {}), ("anchor", 0)]
int_params = ["num_before", "num_after"]
bad_types = (False, "", "-1", -1)
for idx, param in enumerate(int_params):

View File

@ -585,7 +585,7 @@ def get_public_stream(request, stream, realm):
return stream
@has_request_variables
def get_old_messages_backend(request, anchor = POST(converter=to_non_negative_int),
def get_old_messages_backend(request, anchor = POST(converter=int),
num_before = POST(converter=to_non_negative_int),
num_after = POST(converter=to_non_negative_int),
narrow = POST('narrow', converter=narrow_parameter, default=None),