mirror of
https://github.com/ihabunek/toot.git
synced 2024-11-03 04:17:21 -05:00
Fix crash on empty timeline
This commit is contained in:
parent
3829a57909
commit
bf168be87d
@ -314,8 +314,8 @@ class TUI(urwid.Frame):
|
|||||||
status, index, count = timeline.get_focused_status_with_counts()
|
status, index, count = timeline.get_focused_status_with_counts()
|
||||||
self.footer.set_status([
|
self.footer.set_status([
|
||||||
("footer_status_bold", "[{}] ".format(timeline.name)),
|
("footer_status_bold", "[{}] ".format(timeline.name)),
|
||||||
status.id, " - status ", str(index + 1), " of ", str(count),
|
] + ([status.id, " - status ", str(index + 1), " of ", str(count)]
|
||||||
])
|
if status else ["no focused status"]))
|
||||||
|
|
||||||
def show_status_source(self, status):
|
def show_status_source(self, status):
|
||||||
self.open_overlay(
|
self.open_overlay(
|
||||||
@ -324,7 +324,7 @@ class TUI(urwid.Frame):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def show_links(self, status):
|
def show_links(self, status):
|
||||||
links = parse_content_links(status.data["content"])
|
links = parse_content_links(status.data["content"]) if status else []
|
||||||
if links:
|
if links:
|
||||||
self.open_overlay(
|
self.open_overlay(
|
||||||
widget=StatusLinks(links),
|
widget=StatusLinks(links),
|
||||||
|
@ -36,7 +36,10 @@ class Timeline(urwid.Columns):
|
|||||||
self.is_thread = is_thread
|
self.is_thread = is_thread
|
||||||
self.statuses = statuses
|
self.statuses = statuses
|
||||||
self.status_list = self.build_status_list(statuses, focus=focus)
|
self.status_list = self.build_status_list(statuses, focus=focus)
|
||||||
self.status_details = StatusDetails(statuses[focus], is_thread)
|
try:
|
||||||
|
self.status_details = StatusDetails(statuses[focus], is_thread)
|
||||||
|
except IndexError:
|
||||||
|
self.status_details = StatusDetails(None, is_thread)
|
||||||
|
|
||||||
super().__init__([
|
super().__init__([
|
||||||
("weight", 40, self.status_list),
|
("weight", 40, self.status_list),
|
||||||
@ -64,7 +67,10 @@ class Timeline(urwid.Columns):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def get_focused_status(self):
|
def get_focused_status(self):
|
||||||
return self.statuses[self.status_list.body.focus]
|
try:
|
||||||
|
return self.statuses[self.status_list.body.focus]
|
||||||
|
except TypeError:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_focused_status_with_counts(self):
|
def get_focused_status_with_counts(self):
|
||||||
"""Returns a tuple of:
|
"""Returns a tuple of:
|
||||||
@ -97,9 +103,13 @@ class Timeline(urwid.Columns):
|
|||||||
status = self.get_focused_status()
|
status = self.get_focused_status()
|
||||||
command = self._command_map[key]
|
command = self._command_map[key]
|
||||||
|
|
||||||
|
if not status:
|
||||||
|
return super().keypress(size, 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.
|
||||||
# TODO: Consider pre-loading statuses earlier
|
# TODO: Consider pre-loading statuses earlier
|
||||||
if command in [urwid.CURSOR_DOWN, urwid.CURSOR_PAGE_DOWN]:
|
if command in [urwid.CURSOR_DOWN, urwid.CURSOR_PAGE_DOWN] \
|
||||||
|
and self.status_list.body.focus:
|
||||||
index = self.status_list.body.focus + 1
|
index = self.status_list.body.focus + 1
|
||||||
count = len(self.statuses)
|
count = len(self.statuses)
|
||||||
if index >= count:
|
if index >= count:
|
||||||
@ -224,8 +234,9 @@ class StatusDetails(urwid.Pile):
|
|||||||
Whether the status is rendered from a thread status list.
|
Whether the status is rendered from a thread status list.
|
||||||
"""
|
"""
|
||||||
self.in_thread = in_thread
|
self.in_thread = in_thread
|
||||||
reblogged_by = status.author if status.reblog else None
|
reblogged_by = status.author if status and status.reblog else None
|
||||||
widget_list = list(self.content_generator(status.original, reblogged_by))
|
widget_list = list(self.content_generator(status.original, reblogged_by)
|
||||||
|
if status else ())
|
||||||
return super().__init__(widget_list)
|
return super().__init__(widget_list)
|
||||||
|
|
||||||
def content_generator(self, status, reblogged_by):
|
def content_generator(self, status, reblogged_by):
|
||||||
|
Loading…
Reference in New Issue
Block a user