mirror of
https://github.com/zulip/zulip.git
synced 2025-10-27 18:13:58 +00:00
narrow: Add support for passing oldest/newest for anchor.
A wart that has long been present inin Zulip's get_messages API is how to request "the latest messages" in the API. Previously, the recommendation was basically to pass anchor=10000000000000000 (for an appropriately huge number). An accident of the server's implementation meant that specific number of 0s was actually important to avoid a buggy (or at least wasteful) value of found_newest=False if the query had specified num_after=0 (since we didn't check). This was the cause of the mobile issue https://github.com/zulip/zulip-mobile/issues/3654. The solution is to allow passing a special value of anchor='newest', basically a special string-type value that the server can interpret as meaning the user precisely just wants the most recent messages. We also add an analogous anchor='oldest' or similar to avoid folks needing to write a somewhat ugly anchor=0 for fetching the very first messages. We may want to also replace the use_first_unread_anchor argument to be a "first_unread" value for the anchor parameter. While it's not always ideal to make a value have a variable type like this, in this case it seems like a really clean way to express the idea of what the user is asking for in the API.
This commit is contained in:
@@ -489,7 +489,8 @@ class ZulipTestCase(TestCase):
|
||||
realm=recipient_realm,
|
||||
)
|
||||
|
||||
def get_messages_response(self, anchor: int=1, num_before: int=100, num_after: int=100,
|
||||
def get_messages_response(self, anchor: Union[int, str]=1,
|
||||
num_before: int=100, num_after: int=100,
|
||||
use_first_unread_anchor: bool=False) -> Dict[str, List[Dict[str, Any]]]:
|
||||
post_params = {"anchor": anchor, "num_before": num_before,
|
||||
"num_after": num_after,
|
||||
@@ -498,7 +499,7 @@ class ZulipTestCase(TestCase):
|
||||
data = result.json()
|
||||
return data
|
||||
|
||||
def get_messages(self, anchor: int=1, num_before: int=100, num_after: int=100,
|
||||
def get_messages(self, anchor: Union[str, int]=1, num_before: int=100, num_after: int=100,
|
||||
use_first_unread_anchor: bool=False) -> List[Dict[str, Any]]:
|
||||
data = self.get_messages_response(anchor, num_before, num_after, use_first_unread_anchor)
|
||||
return data['messages']
|
||||
|
||||
Reference in New Issue
Block a user