"since" is now properly explained in the API docs

but we won't support it
This commit is contained in:
Midgard 2024-05-20 12:53:23 +02:00
parent 9a3482eabb
commit 80cd8cc4c4
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -44,7 +44,7 @@ def warn_if_tty(you_can_type="the message objects", write_message_to=sys.stderr)
print(f"Reading from tty. (You can type {you_can_type} below. Or maybe you meant to redirect something to stdin.)", file=write_message_to)
def get_posts_for_channel(self, channel_id: str, progress=lambda x: None, after=None, since=None, **kwargs) -> Iterable[Dict]:
def get_posts_for_channel(self, channel_id: str, progress=lambda x: None, after=None, **kwargs) -> Iterable[Dict]:
"""
@raises ApiException: Passed on from lower layers.
"""
@ -52,29 +52,7 @@ def get_posts_for_channel(self, channel_id: str, progress=lambda x: None, after=
page = 0
total = 0
# if after and since:
# raise ValueError("after and since cannot be used together")
if since:
raise Exception("'since' functionality is broken in the API and behaves non-deterministically. It cannot be meaningfully used.")
# Posts in channel updated after a given timestamp: pagination is broken in the API
# current_since = since
# while True:
# data_page = self._get(f"/v4/channels/{channel_id}/posts", params={"since": current_since, **kwargs})
# order = data_page["order"]
# yield from (
# data_page["posts"][post_id]
# for post_id in reversed(order)
# )
# total += len(order)
# progress(total)
# if len(order) < 1000: # For some reason the pages go up to 1000 posts if 'since' is given
# break
# current_since = data_page["posts"][order[0]]["create_at"]
# sleep(0.1)
elif after:
if after:
# Posts in channel after a given ID: API gives pages with OLDEST messages first, so we can
# yield each page when it is fetched
while True:
@ -221,7 +199,7 @@ def cat(mm_api: mattermost.MMApi, cmdline_args):
backlog_lock = threading.Lock()
def print_initial_messages():
posts = get_posts_for_channel(mm_api, channel["id"], after=cmdline_args.after, since=cmdline_args.since)
posts = get_posts_for_channel(mm_api, channel["id"], after=cmdline_args.after)
for post in posts:
print(str_for_post(attribute, post, cmdline_args))
@ -587,7 +565,6 @@ Security note: Other programs and users can typically read which arguments you g
parser_cat.add_argument("channel", help="URL names of team and channel: '<team>/<channel>'")
# ---
parser_cat.add_argument("--after", help="all after post with ID")
parser_cat.add_argument("--since", help="all after timestamp")
parser_cat.add_argument("-f", "--follow", action="store_true", help="keep running, printing new posts as they come in")
parser_tail = subparsers.add_parser("tail", help="list newest messages in channel")