Compare commits

..

2 commits

Author SHA1 Message Date
80cd8cc4c4
"since" is now properly explained in the API docs
but we won't support it
2024-05-20 12:54:32 +02:00
9a3482eabb
Correct type annotation 2024-05-20 12:53:02 +02:00

View file

@ -4,7 +4,7 @@ import sys
import argparse
import os
import json
from typing import Dict, Optional, List, Iterable
from typing import Dict, Optional, List, Iterable, Tuple
import re
from time import sleep
import threading
@ -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:
@ -158,7 +136,7 @@ def resolve_channel(mm_api: mattermost.MMApi, team_id: str, query: str) -> Optio
return joined_channel_result
def resolve_team_channel(mm_api: mattermost.MMApi, query: str) -> Dict:
def resolve_team_channel(mm_api: mattermost.MMApi, query: str) -> Tuple[Dict, Dict]:
query_parts = query.split("/")
del query
if len(query_parts) != 2:
@ -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")