simplify HistoryIterator message ordering

rename reverse -> oldest_first, which is more obvious what it does.
Then, honor it entirely - if you specify no `after` endpoint, we default
to the beginning of message history, similar to how `before` defaults to
the end of message history.

This is a breaking change, and will change the behavior of any iterator
that previously would have been returning messages in a weird order for
limits over 100

`for msg in history(reversed=True, limit=300)` would return the newest
300 messages, in a messed up order (100..0, 200..100, 300..200).
`for msg in history(oldest_first=True, limit=300)` will now return the
oldest 300 messages in order. And so on.

`for msg in history(after=msg)` is unchanged, this previously would
return the oldest 100 messages after `msg`, oldest->newest order, and
still will.
This commit is contained in:
khazhyk
2019-04-07 21:47:59 -07:00
parent 7078b665a3
commit 366dc4855b
4 changed files with 29 additions and 32 deletions

View File

@ -863,7 +863,7 @@ class Messageable(metaclass=abc.ABCMeta):
data = await state.http.pins_from(channel.id)
return [state.create_message(channel=channel, data=m) for m in data]
def history(self, *, limit=100, before=None, after=None, around=None, reverse=None):
def history(self, *, limit=100, before=None, after=None, around=None, oldest_first=None):
"""Return an :class:`.AsyncIterator` that enables receiving the destination's message history.
You must have :attr:`~.Permissions.read_message_history` permissions to use this.
@ -902,11 +902,9 @@ class Messageable(metaclass=abc.ABCMeta):
If a date is provided it must be a timezone-naive datetime representing UTC time.
When using this argument, the maximum limit is 101. Note that if the limit is an
even number then this will return at most limit + 1 messages.
reverse: Optional[:class:`bool`]
If set to true, return messages in oldest->newest order. If unspecified,
this defaults to ``False`` for most cases. However if passing in a
``after`` parameter then this is set to ``True``. This avoids getting messages
out of order in the ``after`` case.
oldest_first: Optional[:class:`bool`]
If set to true, return messages in oldest->newest order. Defaults to True if
``after`` is specified, otherwise False.
Raises
------
@ -920,7 +918,7 @@ class Messageable(metaclass=abc.ABCMeta):
:class:`.Message`
The message with the message data parsed.
"""
return HistoryIterator(self, limit=limit, before=before, after=after, around=around, reverse=reverse)
return HistoryIterator(self, limit=limit, before=before, after=after, around=around, oldest_first=oldest_first)
class Connectable(metaclass=abc.ABCMeta):