Implement replies

This commit is contained in:
Ivan Habunek 2019-08-29 11:01:49 +02:00
parent 9c74c1d9e6
commit 31462fe6f8
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
3 changed files with 30 additions and 18 deletions

View File

@ -164,6 +164,10 @@ class TUI(urwid.Frame):
def _compose(*args):
self.show_compose()
def _reply(timeline, status):
logger.info("reply")
self.show_compose(status)
def _source(timeline, status):
self.show_status_source(status)
@ -172,6 +176,7 @@ class TUI(urwid.Frame):
urwid.connect_signal(timeline, "favourite", self.async_toggle_favourite)
urwid.connect_signal(timeline, "source", _source)
urwid.connect_signal(timeline, "compose", _compose)
urwid.connect_signal(timeline, "reply", _reply)
def build_timeline(self, statuses):
def _close(*args):
@ -264,21 +269,23 @@ class TUI(urwid.Frame):
title="Unhandled Exception",
)
def show_compose(self):
def show_compose(self, in_reply_to=None):
def _close(*args):
self.close_overlay()
def _post(timeline, content, warning, visibility):
self.post_status(content, warning, visibility)
def _post(timeline, *args):
self.post_status(*args)
composer = StatusComposer()
composer = StatusComposer(in_reply_to)
urwid.connect_signal(composer, "close", _close)
urwid.connect_signal(composer, "post", _post)
self.open_overlay(composer, title="Compose status")
def post_status(self, content, warning, visibility):
def post_status(self, content, warning, visibility, in_reply_to_id):
data = api.post_status(self.app, self.user, content,
spoiler_text=warning, visibility=visibility)
spoiler_text=warning,
visibility=visibility,
in_reply_to_id=in_reply_to_id)
status = Status(data, self.app.instance)
# TODO: instead of this, fetch new items from the timeline?

View File

@ -29,11 +29,10 @@ class StatusComposer(urwid.Frame):
"""
signals = ["close", "post"]
def __init__(self):
self.content_caption = urwid.Text("Status message")
def __init__(self, in_reply_to=None):
self.in_reply_to = in_reply_to
self.content_edit = EditBox()
self.cw_caption = urwid.Text("Content warning")
self.cw_edit = None
self.cw_add_button = Button("Add content warning",
on_press=self.add_content_warning)
@ -53,12 +52,16 @@ class StatusComposer(urwid.Frame):
return super().__init__(self.listbox)
def generate_list_items(self):
yield self.content_caption
if self.in_reply_to:
yield urwid.Text(("gray", "Replying to {}".format(self.in_reply_to.account)))
yield urwid.AttrWrap(urwid.Divider("-"), "gray")
yield urwid.Text("Status message")
yield self.content_edit
yield urwid.Divider()
if self.cw_edit:
yield self.cw_caption
yield urwid.Text("Content warning")
yield self.cw_edit
yield urwid.Divider()
yield self.cw_remove_button
@ -125,7 +128,8 @@ class StatusComposer(urwid.Frame):
self.set_error_message("Cannot post an empty message")
return
self._emit("post", content, warning, self.visibility)
in_reply_to_id = self.in_reply_to.id if self.in_reply_to else None
self._emit("post", content, warning, self.visibility, in_reply_to_id)
def close(self, button):
self._emit("close")

View File

@ -21,6 +21,7 @@ class Timeline(urwid.Columns):
"focus", # Focus changed
"next", # Fetch more statuses
"reblog", # Reblog status
"reply", # Compose a reply to a status
"source", # Show status source
"thread", # Show thread for status
]
@ -85,6 +86,7 @@ class Timeline(urwid.Columns):
self.contents[2] = self.status_details, ("weight", 60, False)
def keypress(self, size, key):
status = self.get_focused_status()
command = self._command_map[key]
# If down is pressed on last status in list emit a signal to load more.
@ -96,7 +98,6 @@ class Timeline(urwid.Columns):
self._emit("next")
if key in ("b", "B"):
status = self.get_focused_status()
self._emit("reblog", status)
return
@ -105,7 +106,6 @@ class Timeline(urwid.Columns):
return
if key in ("f", "F"):
status = self.get_focused_status()
self._emit("favourite", status)
return
@ -113,19 +113,20 @@ class Timeline(urwid.Columns):
self._emit("close")
return
if key in ("r", "R"):
self._emit("reply", status)
return
if key in ("t", "T"):
status = self.get_focused_status()
self._emit("thread", status)
return
if key in ("v", "V"):
status = self.get_focused_status()
if status.data["url"]:
webbrowser.open(status.data["url"])
return
if key in ("u", "U"):
status = self.get_focused_status()
self._emit("source", status)
return
@ -220,7 +221,7 @@ class StatusDetails(urwid.Pile):
# Push things to bottom
yield ("weight", 1, urwid.SolidFill(" "))
options = "[B]oost [F]avourite [V]iew {}So[u]rce [H]elp".format(
options = "[B]oost [F]avourite [V]iew {}[R]eply So[u]rce [H]elp".format(
"[T]hread " if not self.in_thread else "")
options = highlight_keys(options, "cyan_bold", "cyan")
yield ("pack", urwid.Text(options))