1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-09-22 04:25:55 -04:00

Support bookmarking a status by URL

Addresses issue #386 but not in every case.
This commit is contained in:
Federico Leva 2023-07-15 20:03:04 +03:00
parent 4f62f417f8
commit 0da15d9e68
3 changed files with 35 additions and 6 deletions

View File

@ -458,6 +458,16 @@ def search(app, user, query, resolve=False, type=None):
}).json()
def search_url(app, user, query):
"""
Perform a search for a URL as is, without encoding.
https://docs.joinmastodon.org/methods/search/#v2
"""
# The Request object performs form encoding if a dict is passed
return http.get(app, user, "/api/v2/search?q={}&resolve=true".format(query)
).json()
def follow(app, user, account):
return _account_action(app, user, account, 'follow')

View File

@ -242,8 +242,18 @@ def unpin(app, user, args):
def bookmark(app, user, args):
api.bookmark(app, user, args.status_id)
print_out("<green>✓ Status bookmarked</green>")
if "://" in args.status_id:
print_out("Not a status ID but an URL was provided. Attempting to fetch a status ID.")
result = api.search_url(app, user, args.status_id)
if result.get("statuses"):
status_id = result.get("statuses")[0].get("id")
else:
print_out(f"<red>Status not found for {args.status_id}</red>")
return
else:
status_id = args.status_id
api.bookmark(app, user, status_id)
print_out(f"<green>✓ Status {status_id} bookmarked</green>")
def unbookmark(app, user, args):
@ -366,6 +376,10 @@ def upload(app, user, args):
def search(app, user, args):
print_out(args.query)
if "://" in args.query:
response = api.search_url(app, user, args.query)
else:
response = api.search(app, user, args.query, args.resolve)
print_search_results(response)

View File

@ -260,8 +260,9 @@ def print_list_accounts(accounts):
def print_search_results(results):
accounts = results['accounts']
hashtags = results['hashtags']
accounts = results.get("accounts")
hashtags = results.get("hashtags")
statuses = results.get("results")
if accounts:
print_out("\nAccounts:")
@ -271,7 +272,11 @@ def print_search_results(results):
print_out("\nHashtags:")
print_out(", ".join([f"<green>#{t['name']}</green>" for t in hashtags]))
if not accounts and not hashtags:
if statuses:
print_out("\nStatuses:")
print_out(", ".join([f"<green>#{t['id']}</green>" for t in statuses]))
if not accounts and not hashtags and not statuses:
print_out("<yellow>Nothing found</yellow>")