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

Handle reblogs

This commit is contained in:
Ivan Habunek 2019-08-24 13:43:41 +02:00
parent f68f5d5716
commit 7da2e2dbbc
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
4 changed files with 26 additions and 3 deletions

View File

@ -114,6 +114,7 @@ class TUI(urwid.Frame):
finally:
self.footer.clear_message()
# # FIXME: REMOVE DEBUGGING
# with open("tmp/statuses2.json", "w") as f:
# import json
# json.dump(data, f, indent=4)

View File

@ -23,4 +23,5 @@ PALETTE = [
('italic', 'white', ''),
('yellow', 'yellow', ''),
('yellow_selected', 'yellow', 'dark blue'),
('gray', 'light gray', ''),
]

View File

@ -1,4 +1,16 @@
from datetime import datetime
from collections import namedtuple
Author = namedtuple("Author", ["account", "display_name"])
def get_author(data, instance):
# Show the author, not the persopn who reblogged
status = data["reblog"] or data
acct = status['account']['acct']
acct = acct if "@" in acct else "{}@{}".format(acct, instance)
return Author(acct, status['account']['display_name'])
def parse_datetime(value):
@ -20,6 +32,7 @@ class Status:
self.display_name = self.data["account"]["display_name"]
self.account = self.get_account()
self.created_at = parse_datetime(data["created_at"])
self.author = get_author(data, instance)
self.favourited = data.get("favourited", False)
self.reblogged = data.get("reblogged", False)

View File

@ -60,6 +60,7 @@ class Timeline(urwid.Columns):
def status_activated(self, *args):
"""Called when a status is clicked, or Enter is pressed."""
status = self.get_focused_status()
self._emit("status_activated", [status])
def status_focused(self):
@ -101,9 +102,16 @@ class StatusDetails(urwid.Pile):
return super().__init__(widget_list)
def content_generator(self, status):
if status.display_name:
yield urwid.Text(("green", status.display_name))
yield urwid.Text(("yellow", status.account))
if status.data["reblog"]:
yield urwid.Text([
("gray", "Reblogged by "),
("gray", status.data["account"]["display_name"])
])
yield urwid.Divider("-")
if status.author.display_name:
yield urwid.Text(("green", status.author.display_name))
yield urwid.Text(("yellow", status.author.account))
yield urwid.Divider()
for line in format_content(status.data["content"]):