mirror of
https://github.com/ihabunek/toot.git
synced 2024-12-04 14:46:33 -05:00
Implement replies
This commit is contained in:
parent
9c74c1d9e6
commit
31462fe6f8
@ -164,6 +164,10 @@ class TUI(urwid.Frame):
|
|||||||
def _compose(*args):
|
def _compose(*args):
|
||||||
self.show_compose()
|
self.show_compose()
|
||||||
|
|
||||||
|
def _reply(timeline, status):
|
||||||
|
logger.info("reply")
|
||||||
|
self.show_compose(status)
|
||||||
|
|
||||||
def _source(timeline, status):
|
def _source(timeline, status):
|
||||||
self.show_status_source(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, "favourite", self.async_toggle_favourite)
|
||||||
urwid.connect_signal(timeline, "source", _source)
|
urwid.connect_signal(timeline, "source", _source)
|
||||||
urwid.connect_signal(timeline, "compose", _compose)
|
urwid.connect_signal(timeline, "compose", _compose)
|
||||||
|
urwid.connect_signal(timeline, "reply", _reply)
|
||||||
|
|
||||||
def build_timeline(self, statuses):
|
def build_timeline(self, statuses):
|
||||||
def _close(*args):
|
def _close(*args):
|
||||||
@ -264,21 +269,23 @@ class TUI(urwid.Frame):
|
|||||||
title="Unhandled Exception",
|
title="Unhandled Exception",
|
||||||
)
|
)
|
||||||
|
|
||||||
def show_compose(self):
|
def show_compose(self, in_reply_to=None):
|
||||||
def _close(*args):
|
def _close(*args):
|
||||||
self.close_overlay()
|
self.close_overlay()
|
||||||
|
|
||||||
def _post(timeline, content, warning, visibility):
|
def _post(timeline, *args):
|
||||||
self.post_status(content, warning, visibility)
|
self.post_status(*args)
|
||||||
|
|
||||||
composer = StatusComposer()
|
composer = StatusComposer(in_reply_to)
|
||||||
urwid.connect_signal(composer, "close", _close)
|
urwid.connect_signal(composer, "close", _close)
|
||||||
urwid.connect_signal(composer, "post", _post)
|
urwid.connect_signal(composer, "post", _post)
|
||||||
self.open_overlay(composer, title="Compose status")
|
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,
|
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)
|
status = Status(data, self.app.instance)
|
||||||
|
|
||||||
# TODO: instead of this, fetch new items from the timeline?
|
# TODO: instead of this, fetch new items from the timeline?
|
||||||
|
@ -29,11 +29,10 @@ class StatusComposer(urwid.Frame):
|
|||||||
"""
|
"""
|
||||||
signals = ["close", "post"]
|
signals = ["close", "post"]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, in_reply_to=None):
|
||||||
self.content_caption = urwid.Text("Status message")
|
self.in_reply_to = in_reply_to
|
||||||
self.content_edit = EditBox()
|
self.content_edit = EditBox()
|
||||||
|
|
||||||
self.cw_caption = urwid.Text("Content warning")
|
|
||||||
self.cw_edit = None
|
self.cw_edit = None
|
||||||
self.cw_add_button = Button("Add content warning",
|
self.cw_add_button = Button("Add content warning",
|
||||||
on_press=self.add_content_warning)
|
on_press=self.add_content_warning)
|
||||||
@ -53,12 +52,16 @@ class StatusComposer(urwid.Frame):
|
|||||||
return super().__init__(self.listbox)
|
return super().__init__(self.listbox)
|
||||||
|
|
||||||
def generate_list_items(self):
|
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 self.content_edit
|
||||||
yield urwid.Divider()
|
yield urwid.Divider()
|
||||||
|
|
||||||
if self.cw_edit:
|
if self.cw_edit:
|
||||||
yield self.cw_caption
|
yield urwid.Text("Content warning")
|
||||||
yield self.cw_edit
|
yield self.cw_edit
|
||||||
yield urwid.Divider()
|
yield urwid.Divider()
|
||||||
yield self.cw_remove_button
|
yield self.cw_remove_button
|
||||||
@ -125,7 +128,8 @@ class StatusComposer(urwid.Frame):
|
|||||||
self.set_error_message("Cannot post an empty message")
|
self.set_error_message("Cannot post an empty message")
|
||||||
return
|
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):
|
def close(self, button):
|
||||||
self._emit("close")
|
self._emit("close")
|
||||||
|
@ -21,6 +21,7 @@ class Timeline(urwid.Columns):
|
|||||||
"focus", # Focus changed
|
"focus", # Focus changed
|
||||||
"next", # Fetch more statuses
|
"next", # Fetch more statuses
|
||||||
"reblog", # Reblog status
|
"reblog", # Reblog status
|
||||||
|
"reply", # Compose a reply to a status
|
||||||
"source", # Show status source
|
"source", # Show status source
|
||||||
"thread", # Show thread for status
|
"thread", # Show thread for status
|
||||||
]
|
]
|
||||||
@ -85,6 +86,7 @@ class Timeline(urwid.Columns):
|
|||||||
self.contents[2] = self.status_details, ("weight", 60, False)
|
self.contents[2] = self.status_details, ("weight", 60, False)
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
|
status = self.get_focused_status()
|
||||||
command = self._command_map[key]
|
command = self._command_map[key]
|
||||||
|
|
||||||
# If down is pressed on last status in list emit a signal to load more.
|
# 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")
|
self._emit("next")
|
||||||
|
|
||||||
if key in ("b", "B"):
|
if key in ("b", "B"):
|
||||||
status = self.get_focused_status()
|
|
||||||
self._emit("reblog", status)
|
self._emit("reblog", status)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -105,7 +106,6 @@ class Timeline(urwid.Columns):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if key in ("f", "F"):
|
if key in ("f", "F"):
|
||||||
status = self.get_focused_status()
|
|
||||||
self._emit("favourite", status)
|
self._emit("favourite", status)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -113,19 +113,20 @@ class Timeline(urwid.Columns):
|
|||||||
self._emit("close")
|
self._emit("close")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if key in ("r", "R"):
|
||||||
|
self._emit("reply", status)
|
||||||
|
return
|
||||||
|
|
||||||
if key in ("t", "T"):
|
if key in ("t", "T"):
|
||||||
status = self.get_focused_status()
|
|
||||||
self._emit("thread", status)
|
self._emit("thread", status)
|
||||||
return
|
return
|
||||||
|
|
||||||
if key in ("v", "V"):
|
if key in ("v", "V"):
|
||||||
status = self.get_focused_status()
|
|
||||||
if status.data["url"]:
|
if status.data["url"]:
|
||||||
webbrowser.open(status.data["url"])
|
webbrowser.open(status.data["url"])
|
||||||
return
|
return
|
||||||
|
|
||||||
if key in ("u", "U"):
|
if key in ("u", "U"):
|
||||||
status = self.get_focused_status()
|
|
||||||
self._emit("source", status)
|
self._emit("source", status)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -220,7 +221,7 @@ class StatusDetails(urwid.Pile):
|
|||||||
# Push things to bottom
|
# Push things to bottom
|
||||||
yield ("weight", 1, urwid.SolidFill(" "))
|
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 "")
|
"[T]hread " if not self.in_thread else "")
|
||||||
options = highlight_keys(options, "cyan_bold", "cyan")
|
options = highlight_keys(options, "cyan_bold", "cyan")
|
||||||
yield ("pack", urwid.Text(options))
|
yield ("pack", urwid.Text(options))
|
||||||
|
Loading…
Reference in New Issue
Block a user