Add lastread command
This commit is contained in:
parent
7be2620c28
commit
d2b634d87d
1 changed files with 25 additions and 1 deletions
26
mmcli.py
26
mmcli.py
|
@ -151,7 +151,10 @@ def resolve_team_channel(mm_api: mattermost.MMApi, query: str) -> Dict:
|
||||||
if not team:
|
if not team:
|
||||||
raise NotFound("team", query_parts[0])
|
raise NotFound("team", query_parts[0])
|
||||||
|
|
||||||
channel = resolve_channel(mm_api, team["id"], query_parts[1])
|
if query_parts[1].startswith("id:"):
|
||||||
|
channel = mm_api.get_channel(query_parts[1][3:])
|
||||||
|
else:
|
||||||
|
channel = resolve_channel(mm_api, team["id"], query_parts[1])
|
||||||
if not channel:
|
if not channel:
|
||||||
return NotFound("channel", query_parts[1])
|
return NotFound("channel", query_parts[1])
|
||||||
|
|
||||||
|
@ -443,6 +446,23 @@ def customstatus(mm_api: mattermost.MMApi, cmdline_args):
|
||||||
mm_api._delete(f"/v4/users/me/status/custom")
|
mm_api._delete(f"/v4/users/me/status/custom")
|
||||||
|
|
||||||
|
|
||||||
|
def lastread(mm_api: mattermost.MMApi, cmdline_args):
|
||||||
|
team, channel = resolve_team_channel(mm_api, cmdline_args.channel) if cmdline_args.channel is not None else (None, None)
|
||||||
|
assert channel is not None
|
||||||
|
response = mm_api._get(f"/v4/users/me/channels/{channel['id']}/posts/unread?limit_after=1&limit_before=0")
|
||||||
|
|
||||||
|
if response["order"]:
|
||||||
|
assert len(response["order"]) == 1
|
||||||
|
last_read_id = response["order"][0]
|
||||||
|
else:
|
||||||
|
last_read_id = None
|
||||||
|
|
||||||
|
if cmdline_args.format == "json":
|
||||||
|
print(json.dumps(last_read_id))
|
||||||
|
if cmdline_args.format == "tsv":
|
||||||
|
print(last_read_id or "null")
|
||||||
|
|
||||||
|
|
||||||
def tsv_escape(text):
|
def tsv_escape(text):
|
||||||
return text.replace("\\", "\\\\").replace("\t", r"\t").replace("\n", r"\n")
|
return text.replace("\\", "\\\\").replace("\t", r"\t").replace("\n", r"\n")
|
||||||
|
|
||||||
|
@ -488,6 +508,7 @@ ACTIONS = {
|
||||||
"edit": {"function": edit},
|
"edit": {"function": edit},
|
||||||
"status": {"function": status},
|
"status": {"function": status},
|
||||||
"customstatus": {"function": customstatus},
|
"customstatus": {"function": customstatus},
|
||||||
|
"lastread": {"function": lastread},
|
||||||
}
|
}
|
||||||
|
|
||||||
FORMATTERS = { "json", "tsv" }
|
FORMATTERS = { "json", "tsv" }
|
||||||
|
@ -597,6 +618,9 @@ The input format accepted on stdin is one JSON object per line. The possible fie
|
||||||
parser_customstatus.add_argument("--emoji", help="Name of emoji (without colons), e.g. coffee")
|
parser_customstatus.add_argument("--emoji", help="Name of emoji (without colons), e.g. coffee")
|
||||||
parser_customstatus.add_argument("text" , help="Text for the status", nargs="?")
|
parser_customstatus.add_argument("text" , help="Text for the status", nargs="?")
|
||||||
|
|
||||||
|
parser_lastread = subparsers.add_parser("lastread", help="last read message in channel; will be null if all messages are read")
|
||||||
|
parser_lastread.add_argument("channel", help="URL names of team and channel: '<team>/<channel>'")
|
||||||
|
|
||||||
parsed = argparser.parse_args()
|
parsed = argparser.parse_args()
|
||||||
|
|
||||||
if not parsed.server:
|
if not parsed.server:
|
||||||
|
|
Loading…
Reference in a new issue