kopia lustrzana https://github.com/ihabunek/toot
Merge branch 'master' of https://github.com/danschwarz/toot
commit
eb09e3d2ac
|
@ -14,13 +14,16 @@ from .overlays import ExceptionStackTrace, GotoMenu, Help, StatusSource, StatusL
|
|||
from .overlays import StatusDeleteConfirmation, Account
|
||||
from .poll import Poll
|
||||
from .timeline import Timeline
|
||||
from .utils import parse_content_links, show_media, copy_to_clipboard
|
||||
from .utils import get_max_toot_chars, parse_content_links, show_media, copy_to_clipboard
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
urwid.set_encoding('UTF-8')
|
||||
|
||||
|
||||
DEFAULT_MAX_TOOT_CHARS = 500
|
||||
|
||||
|
||||
class Header(urwid.WidgetWrap):
|
||||
def __init__(self, app, user):
|
||||
self.app = app
|
||||
|
@ -112,7 +115,7 @@ class TUI(urwid.Frame):
|
|||
self.footer.set_status("Loading...")
|
||||
|
||||
# Default max status length, updated on startup
|
||||
self.max_toot_chars = 500
|
||||
self.max_toot_chars = DEFAULT_MAX_TOOT_CHARS
|
||||
|
||||
self.timeline = None
|
||||
self.overlay = None
|
||||
|
@ -289,8 +292,8 @@ class TUI(urwid.Frame):
|
|||
return api.get_instance(self.app.base_url)
|
||||
|
||||
def _done(instance):
|
||||
if "max_toot_chars" in instance:
|
||||
self.max_toot_chars = instance["max_toot_chars"]
|
||||
self.max_toot_chars = get_max_toot_chars(instance, DEFAULT_MAX_TOOT_CHARS)
|
||||
logger.info(f"Max toot chars set to: {self.max_toot_chars}")
|
||||
|
||||
if "translation" in instance:
|
||||
# instance is advertising translation service
|
||||
|
@ -541,11 +544,9 @@ class TUI(urwid.Frame):
|
|||
|
||||
def async_toggle_favourite(self, timeline, status):
|
||||
def _favourite():
|
||||
logger.info("Favouriting {}".format(status))
|
||||
api.favourite(self.app, self.user, status.id)
|
||||
|
||||
def _unfavourite():
|
||||
logger.info("Unfavouriting {}".format(status))
|
||||
api.unfavourite(self.app, self.user, status.id)
|
||||
|
||||
def _done(loop):
|
||||
|
@ -562,11 +563,9 @@ class TUI(urwid.Frame):
|
|||
|
||||
def async_toggle_reblog(self, timeline, status):
|
||||
def _reblog():
|
||||
logger.info("Reblogging {}".format(status))
|
||||
api.reblog(self.app, self.user, status.original.id, visibility=get_default_visibility())
|
||||
|
||||
def _unreblog():
|
||||
logger.info("Unreblogging {}".format(status))
|
||||
api.unreblog(self.app, self.user, status.original.id)
|
||||
|
||||
def _done(loop):
|
||||
|
@ -590,7 +589,6 @@ class TUI(urwid.Frame):
|
|||
|
||||
def async_translate(self, timeline, status):
|
||||
def _translate():
|
||||
logger.info("Translating {}".format(status))
|
||||
self.footer.set_message("Translating status {}".format(status.original.id))
|
||||
|
||||
try:
|
||||
|
@ -623,11 +621,9 @@ class TUI(urwid.Frame):
|
|||
|
||||
def async_toggle_bookmark(self, timeline, status):
|
||||
def _bookmark():
|
||||
logger.info("Bookmarking {}".format(status))
|
||||
api.bookmark(self.app, self.user, status.id)
|
||||
|
||||
def _unbookmark():
|
||||
logger.info("Unbookmarking {}".format(status))
|
||||
api.unbookmark(self.app, self.user, status.id)
|
||||
|
||||
def _done(loop):
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import base64
|
||||
import urwid
|
||||
from html.parser import HTMLParser
|
||||
import math
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import urwid
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from functools import reduce
|
||||
from html.parser import HTMLParser
|
||||
|
||||
HASHTAG_PATTERN = re.compile(r'(?<!\w)(#\w+)\b')
|
||||
SECOND = 1
|
||||
|
@ -35,7 +36,7 @@ def parse_datetime(value):
|
|||
return dttm.astimezone()
|
||||
|
||||
|
||||
def time_ago(value: datetime) -> datetime:
|
||||
def time_ago(value: datetime) -> str:
|
||||
now = datetime.now().astimezone()
|
||||
delta = now.timestamp() - value.timestamp()
|
||||
|
||||
|
@ -163,3 +164,26 @@ def copy_to_clipboard(screen: urwid.raw_display.Screen, text: str):
|
|||
|
||||
screen.write(f"\033]52;c;{b64_text}\a")
|
||||
screen.flush()
|
||||
|
||||
|
||||
def get_max_toot_chars(instance, default=500):
|
||||
# Mastodon
|
||||
# https://docs.joinmastodon.org/entities/Instance/#max_characters
|
||||
max_toot_chars = deep_get(instance, ["configuration", "statuses", "max_characters"])
|
||||
if isinstance(max_toot_chars, int):
|
||||
return max_toot_chars
|
||||
|
||||
# Pleroma
|
||||
max_toot_chars = instance.get("max_toot_chars")
|
||||
if isinstance(max_toot_chars, int):
|
||||
return max_toot_chars
|
||||
|
||||
return default
|
||||
|
||||
|
||||
def deep_get(adict: dict, path: list[str], default=None):
|
||||
return reduce(
|
||||
lambda d, key: d.get(key, default) if isinstance(d, dict) else default,
|
||||
path,
|
||||
adict
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue